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