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