1 |
gezelter |
2 |
#ifdef IS_MPI |
2 |
|
|
#include <stdlib.h> |
3 |
|
|
#include <stdio.h> |
4 |
|
|
#include <string.h> |
5 |
|
|
|
6 |
|
|
#define __mpiBASSEVENT |
7 |
|
|
#include "mpiBASS.h" |
8 |
|
|
#include "simError.h" |
9 |
|
|
|
10 |
|
|
|
11 |
|
|
void mpiCatchEvent(void); |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
void mpiEventInit(void) |
17 |
|
|
{ |
18 |
|
|
int blockCounts[5] = {1,3,1,120,80}; |
19 |
|
|
MPI_Aint dspls[5]; |
20 |
|
|
MPI_Datatype types[5]; |
21 |
|
|
mBEvent protoEvent; |
22 |
|
|
|
23 |
|
|
int i; |
24 |
|
|
|
25 |
|
|
MPI_Address(&protoEvent.type, &dspls[0]); |
26 |
|
|
MPI_Address(&protoEvent.d1, &dspls[1]); |
27 |
|
|
MPI_Address(&protoEvent.i1, &dspls[2]); |
28 |
|
|
MPI_Address(&protoEvent.cArray, &dspls[3]); |
29 |
|
|
MPI_Address(&protoEvent.lhs , &dspls[4]); |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
types[0] = MPI_INT; |
33 |
|
|
types[1] = MPI_DOUBLE; |
34 |
|
|
types[2] = MPI_INT; |
35 |
|
|
types[3] = MPI_CHAR; |
36 |
|
|
types[4] = MPI_CHAR; |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
for (i =4; i >= 0; i--) dspls[i] -= dspls[0]; |
40 |
|
|
|
41 |
|
|
MPI_Type_struct(5,blockCounts,dspls,types,&mpiBASSEventType); |
42 |
|
|
MPI_Type_commit(&mpiBASSEventType); |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
void throwMPIEvent(event* the_event) |
47 |
|
|
{ |
48 |
|
|
mBEvent mpiEventContainer; |
49 |
|
|
int mpiStatus; |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
if (the_event == NULL) mpiStatus = MPI_INTERFACE_DONE; |
53 |
|
|
else mpiStatus = MPI_INTERFACE_CONTINUE; |
54 |
|
|
|
55 |
|
|
MPI_Bcast(&mpiStatus,1,MPI_INT,0,MPI_COMM_WORLD); |
56 |
|
|
|
57 |
|
|
if (!mpiStatus){ |
58 |
|
|
switch (the_event->event_type){ |
59 |
|
|
case MOLECULE: |
60 |
|
|
mpiEventContainer.type = mpiMOLECULE; |
61 |
|
|
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
62 |
|
|
break; |
63 |
|
|
|
64 |
|
|
case RIGIDBODY: |
65 |
|
|
mpiEventContainer.type = mpiRIGIDBODY; |
66 |
|
|
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
67 |
|
|
break; |
68 |
|
|
|
69 |
|
|
case CUTOFFGROUP: |
70 |
|
|
mpiEventContainer.type = mpiCUTOFFGROUP; |
71 |
|
|
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
72 |
|
|
break; |
73 |
|
|
|
74 |
|
|
case ATOM: |
75 |
|
|
mpiEventContainer.type = mpiATOM; |
76 |
|
|
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
77 |
|
|
break; |
78 |
|
|
|
79 |
|
|
case BOND: |
80 |
|
|
mpiEventContainer.type = mpiBOND; |
81 |
|
|
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
82 |
|
|
break; |
83 |
|
|
|
84 |
|
|
case BEND: |
85 |
|
|
mpiEventContainer.type = mpiBEND; |
86 |
|
|
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
87 |
|
|
break; |
88 |
|
|
|
89 |
|
|
case TORSION: |
90 |
|
|
mpiEventContainer.type = mpiTORSION; |
91 |
|
|
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
92 |
|
|
break; |
93 |
|
|
|
94 |
|
|
case ZCONSTRAINT: |
95 |
|
|
mpiEventContainer.type = mpiZCONSTRAINT; |
96 |
|
|
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
97 |
|
|
break; |
98 |
|
|
|
99 |
|
|
case COMPONENT: |
100 |
|
|
mpiEventContainer.type = mpiCOMPONENT; |
101 |
|
|
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
102 |
|
|
break; |
103 |
|
|
|
104 |
|
|
case POSITION: |
105 |
|
|
mpiEventContainer.type = mpiPOSITION; |
106 |
|
|
mpiEventContainer.d1 = the_event->evt.pos.x; // pack pos coord into d |
107 |
|
|
mpiEventContainer.d2 = the_event->evt.pos.y; |
108 |
|
|
mpiEventContainer.d3 = the_event->evt.pos.z; |
109 |
|
|
break; |
110 |
|
|
|
111 |
|
|
case ORIENTATION: |
112 |
|
|
mpiEventContainer.type = mpiORIENTATION; |
113 |
|
|
mpiEventContainer.d1 = the_event->evt.ornt.phi; // pack orientation coord into d |
114 |
|
|
mpiEventContainer.d2 = the_event->evt.ornt.theta; |
115 |
|
|
mpiEventContainer.d3 = the_event->evt.ornt.psi; |
116 |
|
|
break; |
117 |
|
|
|
118 |
|
|
case CONSTRAINT: |
119 |
|
|
mpiEventContainer.type = mpiCONSTRAINT; |
120 |
|
|
mpiEventContainer.d1 = the_event->evt.cnstr; // pack constraint coord into d |
121 |
|
|
break; |
122 |
|
|
|
123 |
|
|
case MEMBERS: |
124 |
|
|
mpiEventContainer.type = mpiMEMBERS; |
125 |
|
|
mpiEventContainer.i1 = the_event->evt.mbrs.nMembers ; // pack member ints into i |
126 |
|
|
break; |
127 |
|
|
|
128 |
|
|
case ASSIGNMENT: |
129 |
|
|
|
130 |
|
|
strcpy(mpiEventContainer.lhs,the_event->evt.asmt.lhs); |
131 |
|
|
|
132 |
|
|
#ifdef MPIBASS_VERBOSE |
133 |
|
|
|
134 |
|
|
fprintf(stderr, |
135 |
|
|
"mpiDiag at node %d: evt Assignment: \"%s\" = ?\n" |
136 |
|
|
" mpi Assignment: \"%s\" = ?\n", |
137 |
|
|
worldRank, |
138 |
|
|
the_event->evt.asmt.lhs, |
139 |
|
|
mpiEventContainer.lhs); |
140 |
|
|
#endif |
141 |
|
|
|
142 |
|
|
switch (the_event->evt.asmt.asmt_type){ |
143 |
|
|
case STRING: |
144 |
|
|
mpiEventContainer.type = mpiASSIGNMENT_s; |
145 |
|
|
strcpy(mpiEventContainer.cArray,the_event->evt.asmt.rhs.sval); |
146 |
|
|
break; |
147 |
|
|
|
148 |
|
|
case INT: |
149 |
|
|
mpiEventContainer.type = mpiASSIGNMENT_i; |
150 |
|
|
mpiEventContainer.i1 = the_event->evt.asmt.rhs.ival; |
151 |
|
|
break; |
152 |
|
|
|
153 |
|
|
case DOUBLE: |
154 |
|
|
mpiEventContainer.type = mpiASSIGNMENT_d; |
155 |
|
|
mpiEventContainer.d1 = the_event->evt.asmt.rhs.dval; |
156 |
|
|
break; |
157 |
|
|
} |
158 |
|
|
break; |
159 |
|
|
|
160 |
|
|
case BLOCK_END: |
161 |
|
|
mpiEventContainer.type = mpiBLOCK_END; |
162 |
|
|
break; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
|
166 |
|
|
MPI_Bcast(&mpiEventContainer,1,mpiBASSEventType,0,MPI_COMM_WORLD); |
167 |
|
|
|
168 |
|
|
if (the_event->event_type == MEMBERS) { |
169 |
|
|
|
170 |
|
|
// For member lists, we need a separate broadcast to spew out the |
171 |
|
|
// membership array: |
172 |
|
|
MPI_Bcast(the_event->evt.mbrs.memberList, the_event->evt.mbrs.nMembers, |
173 |
|
|
MPI_INT, 0, MPI_COMM_WORLD); |
174 |
|
|
|
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
sprintf( checkPointMsg, |
178 |
|
|
"BASS Event broadcast successful" ); |
179 |
|
|
|
180 |
|
|
MPIcheckPoint(); |
181 |
|
|
} |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
|
185 |
|
|
// Everybody but node 0 runs this |
186 |
|
|
void mpiEventLoop(void) |
187 |
|
|
{ |
188 |
|
|
int mpiContinue; |
189 |
|
|
|
190 |
|
|
#ifdef MPIBASS_VERBOSE |
191 |
|
|
fprintf(stderr, |
192 |
|
|
"event key List at node %d:\n" |
193 |
|
|
" MOLECULE %d\n" |
194 |
|
|
" ATOM %d\n" |
195 |
|
|
" BOND %d\n" |
196 |
|
|
" BEND %d\n" |
197 |
|
|
" TORSION %d\n" |
198 |
|
|
" COMPONENT %d\n" |
199 |
|
|
" POSITION %d\n" |
200 |
|
|
" ASSIGNMENT %d\n" |
201 |
|
|
" MEMBERS %d\n" |
202 |
|
|
" CONSTRAINT %d\n" |
203 |
|
|
" ORIENTATION %d\n" |
204 |
|
|
" ZCONSTRAINT %d\n" |
205 |
|
|
" RIGIDBODY %d\n" |
206 |
|
|
" CUTOFFGROUP %d\n" |
207 |
|
|
" BLOCK_END %d\n" |
208 |
|
|
"\n", |
209 |
|
|
worldRank, |
210 |
|
|
MOLECULE, ATOM, BOND, BEND, TORSION, COMPONENT, |
211 |
|
|
POSITION, ASSIGNMENT, MEMBERS, CONSTRAINT, ORIENTATION, |
212 |
|
|
ZCONSTRAINT, RIGIDBODY, CUTOFFGROUP, BLOCK_END ); |
213 |
|
|
#endif |
214 |
|
|
|
215 |
|
|
MPI_Bcast(&mpiContinue,1,MPI_INT,0,MPI_COMM_WORLD); |
216 |
|
|
|
217 |
|
|
while(!mpiContinue){ |
218 |
|
|
|
219 |
|
|
mpiCatchEvent(); |
220 |
|
|
|
221 |
|
|
MPI_Bcast(&mpiContinue,1,MPI_INT,0,MPI_COMM_WORLD); |
222 |
|
|
} |
223 |
|
|
|
224 |
|
|
if (mpiContinue == MPI_INTERFACE_ABORT){ |
225 |
|
|
MPI_Finalize(); |
226 |
|
|
exit (0); |
227 |
|
|
} |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
void mpiCatchEvent(void) |
231 |
|
|
{ |
232 |
|
|
event the_event; |
233 |
|
|
mBEvent mpiEventContainer; |
234 |
|
|
|
235 |
|
|
|
236 |
|
|
MPI_Bcast(&mpiEventContainer,1,mpiBASSEventType,0,MPI_COMM_WORLD); |
237 |
|
|
|
238 |
|
|
switch (mpiEventContainer.type){ |
239 |
|
|
case mpiMOLECULE: |
240 |
|
|
the_event.event_type = MOLECULE; |
241 |
|
|
the_event.evt.blk_index = mpiEventContainer.i1; |
242 |
|
|
break; |
243 |
|
|
|
244 |
|
|
case mpiRIGIDBODY: |
245 |
|
|
the_event.event_type = RIGIDBODY; |
246 |
|
|
the_event.evt.blk_index = mpiEventContainer.i1; |
247 |
|
|
break; |
248 |
|
|
|
249 |
|
|
case mpiCUTOFFGROUP: |
250 |
|
|
the_event.event_type = CUTOFFGROUP; |
251 |
|
|
the_event.evt.blk_index = mpiEventContainer.i1; |
252 |
|
|
break; |
253 |
|
|
|
254 |
|
|
case mpiATOM: |
255 |
|
|
the_event.event_type = ATOM; |
256 |
|
|
the_event.evt.blk_index = mpiEventContainer.i1; |
257 |
|
|
break; |
258 |
|
|
|
259 |
|
|
case mpiBOND: |
260 |
|
|
the_event.event_type = BOND; |
261 |
|
|
the_event.evt.blk_index = mpiEventContainer.i1; |
262 |
|
|
break; |
263 |
|
|
|
264 |
|
|
case mpiBEND: |
265 |
|
|
the_event.event_type = BEND; |
266 |
|
|
the_event.evt.blk_index = mpiEventContainer.i1; |
267 |
|
|
break; |
268 |
|
|
|
269 |
|
|
case mpiTORSION: |
270 |
|
|
the_event.event_type = TORSION; |
271 |
|
|
the_event.evt.blk_index = mpiEventContainer.i1; |
272 |
|
|
break; |
273 |
|
|
|
274 |
|
|
case mpiZCONSTRAINT: |
275 |
|
|
the_event.event_type = ZCONSTRAINT; |
276 |
|
|
the_event.evt.blk_index = mpiEventContainer.i1; |
277 |
|
|
break; |
278 |
|
|
|
279 |
|
|
case mpiCOMPONENT: |
280 |
|
|
the_event.event_type = COMPONENT; |
281 |
|
|
the_event.evt.blk_index = mpiEventContainer.i1; |
282 |
|
|
break; |
283 |
|
|
|
284 |
|
|
|
285 |
|
|
case mpiPOSITION: |
286 |
|
|
the_event.event_type = POSITION; |
287 |
|
|
the_event.evt.pos.x = mpiEventContainer.d1; |
288 |
|
|
the_event.evt.pos.y = mpiEventContainer.d2; |
289 |
|
|
the_event.evt.pos.z = mpiEventContainer.d3; |
290 |
|
|
break; |
291 |
|
|
|
292 |
|
|
case mpiORIENTATION: |
293 |
|
|
the_event.event_type = ORIENTATION; |
294 |
|
|
the_event.evt.ornt.phi = mpiEventContainer.d1; |
295 |
|
|
the_event.evt.ornt.theta = mpiEventContainer.d2; |
296 |
|
|
the_event.evt.ornt.psi = mpiEventContainer.d3; |
297 |
|
|
break; |
298 |
|
|
|
299 |
|
|
case mpiCONSTRAINT: |
300 |
|
|
the_event.event_type = CONSTRAINT; |
301 |
|
|
the_event.evt.cnstr = mpiEventContainer.d1; |
302 |
|
|
break; |
303 |
|
|
|
304 |
|
|
case mpiMEMBERS: |
305 |
|
|
the_event.event_type = MEMBERS; |
306 |
|
|
the_event.evt.mbrs.nMembers = mpiEventContainer.i1; |
307 |
|
|
|
308 |
|
|
the_event.evt.mbrs.memberList = (int *) calloc(the_event.evt.mbrs.nMembers, |
309 |
|
|
sizeof(int)); |
310 |
|
|
|
311 |
|
|
// Grab the member list since we have a number of members: |
312 |
|
|
MPI_Bcast(the_event.evt.mbrs.memberList, the_event.evt.mbrs.nMembers, |
313 |
|
|
MPI_INT, 0, MPI_COMM_WORLD); |
314 |
|
|
|
315 |
|
|
break; |
316 |
|
|
|
317 |
|
|
case mpiASSIGNMENT_s: |
318 |
|
|
the_event.event_type = ASSIGNMENT; |
319 |
|
|
the_event.evt.asmt.asmt_type = STRING; |
320 |
|
|
strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs); |
321 |
|
|
strcpy(the_event.evt.asmt.rhs.sval,mpiEventContainer.cArray); |
322 |
|
|
|
323 |
|
|
#ifdef MPIBASS_VERBOSE |
324 |
|
|
|
325 |
|
|
fprintf(stderr, "mpiDiag at node %d: Assignment: %s = %s\n", worldRank, |
326 |
|
|
the_event.evt.asmt.lhs, |
327 |
|
|
the_event.evt.asmt.rhs.sval ); |
328 |
|
|
#endif |
329 |
|
|
|
330 |
|
|
break; |
331 |
|
|
|
332 |
|
|
case mpiASSIGNMENT_i: |
333 |
|
|
the_event.event_type = ASSIGNMENT; |
334 |
|
|
the_event.evt.asmt.asmt_type = INT; |
335 |
|
|
strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs); |
336 |
|
|
the_event.evt.asmt.rhs.ival = mpiEventContainer.i1; |
337 |
|
|
|
338 |
|
|
#ifdef MPIBASS_VERBOSE |
339 |
|
|
|
340 |
|
|
fprintf(stderr, "mpiDiag at node %d: Assignment: %s = %d\n", worldRank, |
341 |
|
|
the_event.evt.asmt.lhs, |
342 |
|
|
the_event.evt.asmt.rhs.ival ); |
343 |
|
|
#endif |
344 |
|
|
|
345 |
|
|
break; |
346 |
|
|
|
347 |
|
|
case mpiASSIGNMENT_d: |
348 |
|
|
the_event.event_type = ASSIGNMENT; |
349 |
|
|
the_event.evt.asmt.asmt_type = DOUBLE; |
350 |
|
|
strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs); |
351 |
|
|
the_event.evt.asmt.rhs.dval = mpiEventContainer.d1; |
352 |
|
|
|
353 |
|
|
#ifdef MPIBASS_VERBOSE |
354 |
|
|
|
355 |
|
|
fprintf(stderr, "mpiDiag at node %d: Assignment: %s = %lf\n", worldRank, |
356 |
|
|
the_event.evt.asmt.lhs, |
357 |
|
|
the_event.evt.asmt.rhs.dval ); |
358 |
|
|
#endif |
359 |
|
|
|
360 |
|
|
break; |
361 |
|
|
|
362 |
|
|
case mpiBLOCK_END: |
363 |
|
|
the_event.event_type = BLOCK_END; |
364 |
|
|
break; |
365 |
|
|
} |
366 |
|
|
|
367 |
|
|
#ifdef MPIBASS_VERBOSE |
368 |
|
|
|
369 |
|
|
fprintf(stderr, "mpiDiag at node %d: event type is %d\n", worldRank, |
370 |
|
|
the_event.event_type); |
371 |
|
|
#endif |
372 |
|
|
|
373 |
|
|
if (!event_handler(&the_event)){ |
374 |
|
|
|
375 |
|
|
sprintf(painCave.errMsg, |
376 |
|
|
"MPI event handling error at node %d => %s\n", |
377 |
|
|
worldRank, |
378 |
|
|
the_event.err_msg); |
379 |
|
|
painCave.isFatal = 1; |
380 |
|
|
simError(); |
381 |
|
|
} |
382 |
|
|
MPIcheckPoint(); |
383 |
|
|
} |
384 |
|
|
|
385 |
|
|
|
386 |
|
|
void mpiInterfaceExit(void){ |
387 |
|
|
int mpiStatus = MPI_INTERFACE_ABORT; |
388 |
|
|
|
389 |
|
|
MPI_Bcast(&mpiStatus,1,MPI_INT,0,MPI_COMM_WORLD); |
390 |
|
|
MPI_Finalize(); |
391 |
|
|
exit (0); |
392 |
|
|
|
393 |
|
|
} |
394 |
|
|
#endif |