1 | #include "ep_lib.hpp" |
---|
2 | #include <mpi.h> |
---|
3 | #include "ep_declaration.hpp" |
---|
4 | #include <iostream> |
---|
5 | #include <fstream> |
---|
6 | #include "ep_mpi.hpp" |
---|
7 | |
---|
8 | using namespace std; |
---|
9 | |
---|
10 | std::list< ep_lib::MPI_Request* > * EP_PendingRequests = 0; |
---|
11 | #pragma omp threadprivate(EP_PendingRequests) |
---|
12 | |
---|
13 | |
---|
14 | std::map<std::pair<int, int>, MPI_Group* > * tag_group_map = 0; |
---|
15 | |
---|
16 | std::map<int, std::pair<ep_lib::MPI_Comm*, std::pair<int, int> > > * tag_comm_map = 0; |
---|
17 | |
---|
18 | |
---|
19 | MPI_Group MPI_GROUP_WORLD; |
---|
20 | |
---|
21 | namespace ep_lib |
---|
22 | { |
---|
23 | |
---|
24 | int tag_combine(int real_tag, int src, int dest) |
---|
25 | { |
---|
26 | int a = real_tag << 16; |
---|
27 | int b = src << 8; |
---|
28 | int c = dest; |
---|
29 | |
---|
30 | return a+b+c; |
---|
31 | } |
---|
32 | |
---|
33 | int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank) |
---|
34 | { |
---|
35 | for(std::map<int, std::pair<int, int> >::iterator it = comm->ep_rank_map->begin(); it != comm->ep_rank_map->end(); it++) |
---|
36 | { |
---|
37 | if( ( it->second.first == ep_rank_loc ) |
---|
38 | && ( it->second.second == mpi_rank ) ) |
---|
39 | { |
---|
40 | return it->first; |
---|
41 | } |
---|
42 | } |
---|
43 | printf("rank not find for EP_intracomm\n"); |
---|
44 | return MPI_Abort(comm, 0); |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count) |
---|
49 | { |
---|
50 | return ::MPI_Get_count(to_mpi_status_ptr(*status), to_mpi_type(datatype), count); |
---|
51 | } |
---|
52 | |
---|
53 | double MPI_Wtime() |
---|
54 | { |
---|
55 | return ::MPI_Wtime(); |
---|
56 | } |
---|
57 | |
---|
58 | int MPI_Comm_test_inter(MPI_Comm comm, int *flag) |
---|
59 | { |
---|
60 | if(comm->is_ep) return *flag = comm->is_intercomm; |
---|
61 | else return ::MPI_Comm_test_inter(to_mpi_comm(comm->mpi_comm), flag); |
---|
62 | } |
---|
63 | |
---|
64 | void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type) |
---|
65 | { |
---|
66 | |
---|
67 | int src_rank; |
---|
68 | int int_count; |
---|
69 | ::MPI_Aint datasize, intsize, charsize, lb; |
---|
70 | |
---|
71 | ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(datatype)), &lb, &datasize); |
---|
72 | ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(MPI_CHAR)), &lb, &intsize); |
---|
73 | |
---|
74 | int_count = count * datasize / intsize ; |
---|
75 | |
---|
76 | char *buffer = static_cast< char* >(const_cast< void*> (buf)); |
---|
77 | |
---|
78 | unsigned long sum = 0; |
---|
79 | for(int i = 0; i<int_count; i++) |
---|
80 | sum += *(buffer+i); |
---|
81 | |
---|
82 | |
---|
83 | MPI_Comm_rank(comm, &src_rank); |
---|
84 | |
---|
85 | ofstream myfile; |
---|
86 | myfile.open ("send_log.txt", ios::app); |
---|
87 | if (myfile.is_open()) |
---|
88 | { |
---|
89 | myfile << "type = " << type << " src = "<< src_rank<< " dest = "<< dest <<" tag = "<< tag << " count = "<< count << " sum = "<< sum << "\n"; |
---|
90 | myfile.close(); |
---|
91 | } |
---|
92 | else printf("Unable to open file\n"); |
---|
93 | |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | void check_sum_recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, int type) |
---|
98 | { |
---|
99 | |
---|
100 | int dest_rank; |
---|
101 | int int_count; |
---|
102 | ::MPI_Aint datasize, intsize, charsize, lb; |
---|
103 | |
---|
104 | ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(datatype)), &lb, &datasize); |
---|
105 | ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(MPI_CHAR)), &lb, &intsize); |
---|
106 | |
---|
107 | int_count = count * datasize / intsize ; |
---|
108 | |
---|
109 | char *buffer = static_cast< char* >(buf); |
---|
110 | |
---|
111 | unsigned long sum = 0; |
---|
112 | for(int i = 0; i<int_count; i++) |
---|
113 | sum += *(buffer+i); |
---|
114 | |
---|
115 | |
---|
116 | MPI_Comm_rank(comm, &dest_rank); |
---|
117 | |
---|
118 | ofstream myfile; |
---|
119 | myfile.open ("recv_log.txt", ios::app); |
---|
120 | if (myfile.is_open()) |
---|
121 | { |
---|
122 | myfile << "type = " << type << " src = "<< src << " dest = "<< dest_rank <<" tag = "<< tag << " count = "<< count << " sum = "<< sum << "\n"; |
---|
123 | myfile.close(); |
---|
124 | } |
---|
125 | else printf("Unable to open file\n"); |
---|
126 | |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | bool valid_type(MPI_Datatype datatype) |
---|
132 | { |
---|
133 | if( datatype == MPI_INT |
---|
134 | || datatype == MPI_FLOAT |
---|
135 | || datatype == MPI_DOUBLE |
---|
136 | || datatype == MPI_CHAR |
---|
137 | || datatype == MPI_LONG |
---|
138 | || datatype == MPI_UNSIGNED_LONG |
---|
139 | || datatype == MPI_LONG_LONG) |
---|
140 | { |
---|
141 | return true; |
---|
142 | } |
---|
143 | |
---|
144 | return false; |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | bool valid_op(MPI_Op op) |
---|
149 | { |
---|
150 | if( op == MPI_MAX |
---|
151 | || op == MPI_MIN |
---|
152 | || op == MPI_SUM |
---|
153 | || op == MPI_LOR) |
---|
154 | { |
---|
155 | return true; |
---|
156 | } |
---|
157 | |
---|
158 | return false; |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | MPI_Datatype to_mpi_type(ep_lib::MPI_Datatype type) |
---|
166 | { |
---|
167 | return *static_cast< MPI_Datatype* >(type); |
---|
168 | } |
---|
169 | |
---|
170 | MPI_Op to_mpi_op(ep_lib::MPI_Op op) |
---|
171 | { |
---|
172 | return *static_cast< MPI_Op* >(op); |
---|
173 | } |
---|
174 | |
---|
175 | MPI_Comm to_mpi_comm(void* comm) |
---|
176 | { |
---|
177 | return *(static_cast< MPI_Comm* >(comm)); |
---|
178 | } |
---|
179 | |
---|
180 | MPI_Comm* to_mpi_comm_ptr(void* comm) |
---|
181 | { |
---|
182 | return static_cast< MPI_Comm* >(comm); |
---|
183 | } |
---|
184 | |
---|
185 | MPI_Message to_mpi_message(void* message) |
---|
186 | { |
---|
187 | return *(static_cast< MPI_Message* >(message)); |
---|
188 | } |
---|
189 | |
---|
190 | MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message) |
---|
191 | { |
---|
192 | return static_cast< MPI_Message* >(message->mpi_message); |
---|
193 | } |
---|
194 | |
---|
195 | MPI_Info to_mpi_info(ep_lib::MPI_Info info) |
---|
196 | { |
---|
197 | return *(static_cast< MPI_Info* >(info->mpi_info)); |
---|
198 | } |
---|
199 | |
---|
200 | MPI_Win to_mpi_win(void* win) |
---|
201 | { |
---|
202 | return *(static_cast< MPI_Win* >(win)); |
---|
203 | } |
---|
204 | |
---|
205 | MPI_Aint to_mpi_aint(ep_lib::MPI_Aint aint) |
---|
206 | { |
---|
207 | return *(static_cast< MPI_Aint* >(aint.mpi_aint)); |
---|
208 | } |
---|
209 | |
---|
210 | MPI_Status* to_mpi_status_ptr(ep_lib::MPI_Status status) |
---|
211 | { |
---|
212 | return static_cast< MPI_Status* >(status.mpi_status); |
---|
213 | } |
---|
214 | |
---|
215 | MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request) |
---|
216 | { |
---|
217 | return static_cast< MPI_Request* >(request->mpi_request); |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | |
---|