1 |
#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,4,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 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 |
case ZCONSTRAINT: |
90 |
mpiEventContainer.type = mpiZCONSTRAINT; |
91 |
mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int |
92 |
break; |
93 |
|
94 |
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 |
mpiEventContainer.d1 = the_event->evt.ornt.x; // pack orientation coord into d |
109 |
mpiEventContainer.d2 = the_event->evt.ornt.y; |
110 |
mpiEventContainer.d3 = the_event->evt.ornt.z; |
111 |
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 |
case MEMBER: |
119 |
mpiEventContainer.type = mpiMEMBER; |
120 |
mpiEventContainer.i1 = the_event->evt.mbr.a ; // pack member ints into i |
121 |
mpiEventContainer.i2 = the_event->evt.mbr.b; |
122 |
mpiEventContainer.i3 = the_event->evt.mbr.c; |
123 |
mpiEventContainer.i4 = the_event->evt.mbr.d; |
124 |
break; |
125 |
|
126 |
case ASSIGNMENT: |
127 |
|
128 |
strcpy(mpiEventContainer.lhs,the_event->evt.asmt.lhs); |
129 |
|
130 |
#ifdef MPIBASS_VERBOSE |
131 |
|
132 |
fprintf(stderr, |
133 |
"mpiDiag at node %d: evt Assignment: \"%s\" = ?\n" |
134 |
" mpi Assignment: \"%s\" = ?\n", |
135 |
worldRank, |
136 |
the_event->evt.asmt.lhs, |
137 |
mpiEventContainer.lhs); |
138 |
#endif |
139 |
|
140 |
switch (the_event->evt.asmt.asmt_type){ |
141 |
case STRING: |
142 |
mpiEventContainer.type = mpiASSIGNMENT_s; |
143 |
strcpy(mpiEventContainer.cArray,the_event->evt.asmt.rhs.sval); |
144 |
break; |
145 |
|
146 |
case INT: |
147 |
mpiEventContainer.type = mpiASSIGNMENT_i; |
148 |
mpiEventContainer.i1 = the_event->evt.asmt.rhs.ival; |
149 |
break; |
150 |
|
151 |
case DOUBLE: |
152 |
mpiEventContainer.type = mpiASSIGNMENT_d; |
153 |
mpiEventContainer.d1 = the_event->evt.asmt.rhs.dval; |
154 |
break; |
155 |
} |
156 |
break; |
157 |
|
158 |
case BLOCK_END: |
159 |
mpiEventContainer.type = mpiBLOCK_END; |
160 |
break; |
161 |
} |
162 |
|
163 |
|
164 |
MPI_Bcast(&mpiEventContainer,1,mpiBASSEventType,0,MPI_COMM_WORLD); |
165 |
|
166 |
sprintf( checkPointMsg, |
167 |
"BASS Event broadcast successful" ); |
168 |
MPIcheckPoint(); |
169 |
} |
170 |
} |
171 |
|
172 |
|
173 |
// Everybody but node 0 runs this |
174 |
void mpiEventLoop(void) |
175 |
{ |
176 |
int mpiContinue; |
177 |
|
178 |
#ifdef MPIBASS_VERBOSE |
179 |
fprintf(stderr, |
180 |
"event key List at node %d:\n" |
181 |
" MOLECULE %d\n" |
182 |
" ATOM %d\n" |
183 |
" BOND %d\n" |
184 |
" BEND %d\n" |
185 |
" TORSION %d\n" |
186 |
" COMPONENT %d\n" |
187 |
" POSITION %d\n" |
188 |
" ASSIGNMENT %d\n" |
189 |
" MEMBER %d\n" |
190 |
" CONSTRAINT %d\n" |
191 |
" ORIENTATION %d\n" |
192 |
" ZCONSTRAINT %d\n" |
193 |
" RIGIDBODY %d\n" |
194 |
" BLOCK_END %d\n" |
195 |
"\n", |
196 |
worldRank, |
197 |
MOLECULE, ATOM, BOND, BEND, TORSION, COMPONENT, |
198 |
POSITION, ASSIGNMENT, MEMBER, CONSTRAINT, ORIENTATION, |
199 |
ZCONSTRAINT, RIGIDBODY, BLOCK_END ); |
200 |
#endif |
201 |
|
202 |
MPI_Bcast(&mpiContinue,1,MPI_INT,0,MPI_COMM_WORLD); |
203 |
|
204 |
while(!mpiContinue){ |
205 |
|
206 |
mpiCatchEvent(); |
207 |
|
208 |
MPI_Bcast(&mpiContinue,1,MPI_INT,0,MPI_COMM_WORLD); |
209 |
} |
210 |
|
211 |
if (mpiContinue == MPI_INTERFACE_ABORT){ |
212 |
MPI_Finalize(); |
213 |
exit (0); |
214 |
} |
215 |
} |
216 |
|
217 |
void mpiCatchEvent(void) |
218 |
{ |
219 |
event the_event; |
220 |
mBEvent mpiEventContainer; |
221 |
|
222 |
|
223 |
MPI_Bcast(&mpiEventContainer,1,mpiBASSEventType,0,MPI_COMM_WORLD); |
224 |
|
225 |
switch (mpiEventContainer.type){ |
226 |
case mpiMOLECULE: |
227 |
the_event.event_type = MOLECULE; |
228 |
the_event.evt.blk_index = mpiEventContainer.i1; |
229 |
break; |
230 |
|
231 |
case mpiRIGIDBODY: |
232 |
the_event.event_type = RIGIDBODY; |
233 |
the_event.evt.blk_index = mpiEventContainer.i1; |
234 |
break; |
235 |
|
236 |
case mpiATOM: |
237 |
the_event.event_type = ATOM; |
238 |
the_event.evt.blk_index = mpiEventContainer.i1; |
239 |
break; |
240 |
|
241 |
case mpiBOND: |
242 |
the_event.event_type = BOND; |
243 |
the_event.evt.blk_index = mpiEventContainer.i1; |
244 |
break; |
245 |
|
246 |
case mpiBEND: |
247 |
the_event.event_type = BEND; |
248 |
the_event.evt.blk_index = mpiEventContainer.i1; |
249 |
break; |
250 |
|
251 |
case mpiTORSION: |
252 |
the_event.event_type = TORSION; |
253 |
the_event.evt.blk_index = mpiEventContainer.i1; |
254 |
break; |
255 |
|
256 |
case mpiZCONSTRAINT: |
257 |
the_event.event_type = ZCONSTRAINT; |
258 |
the_event.evt.blk_index = mpiEventContainer.i1; |
259 |
break; |
260 |
|
261 |
case mpiCOMPONENT: |
262 |
the_event.event_type = COMPONENT; |
263 |
the_event.evt.blk_index = mpiEventContainer.i1; |
264 |
break; |
265 |
|
266 |
|
267 |
case mpiPOSITION: |
268 |
the_event.event_type = POSITION; |
269 |
the_event.evt.pos.x = mpiEventContainer.d1; |
270 |
the_event.evt.pos.y = mpiEventContainer.d2; |
271 |
the_event.evt.pos.z = mpiEventContainer.d3; |
272 |
break; |
273 |
|
274 |
case mpiORIENTATION: |
275 |
the_event.event_type = ORIENTATION; |
276 |
the_event.evt.ornt.x = mpiEventContainer.d1; |
277 |
the_event.evt.ornt.y = mpiEventContainer.d2; |
278 |
the_event.evt.ornt.z = mpiEventContainer.d3; |
279 |
break; |
280 |
|
281 |
case mpiCONSTRAINT: |
282 |
the_event.event_type = CONSTRAINT; |
283 |
the_event.evt.cnstr = mpiEventContainer.d1; |
284 |
break; |
285 |
|
286 |
case mpiMEMBER: |
287 |
the_event.event_type = MEMBER; |
288 |
the_event.evt.mbr.a = mpiEventContainer.i1; |
289 |
the_event.evt.mbr.b = mpiEventContainer.i2; |
290 |
the_event.evt.mbr.c = mpiEventContainer.i3; |
291 |
the_event.evt.mbr.d = mpiEventContainer.i4; |
292 |
break; |
293 |
|
294 |
case mpiASSIGNMENT_s: |
295 |
the_event.event_type = ASSIGNMENT; |
296 |
the_event.evt.asmt.asmt_type = STRING; |
297 |
strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs); |
298 |
strcpy(the_event.evt.asmt.rhs.sval,mpiEventContainer.cArray); |
299 |
|
300 |
#ifdef MPIBASS_VERBOSE |
301 |
|
302 |
fprintf(stderr, "mpiDiag at node %d: Assignment: %s = %s\n", worldRank, |
303 |
the_event.evt.asmt.lhs, |
304 |
the_event.evt.asmt.rhs.sval ); |
305 |
#endif |
306 |
|
307 |
break; |
308 |
|
309 |
case mpiASSIGNMENT_i: |
310 |
the_event.event_type = ASSIGNMENT; |
311 |
the_event.evt.asmt.asmt_type = INT; |
312 |
strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs); |
313 |
the_event.evt.asmt.rhs.ival = mpiEventContainer.i1; |
314 |
|
315 |
#ifdef MPIBASS_VERBOSE |
316 |
|
317 |
fprintf(stderr, "mpiDiag at node %d: Assignment: %s = %d\n", worldRank, |
318 |
the_event.evt.asmt.lhs, |
319 |
the_event.evt.asmt.rhs.ival ); |
320 |
#endif |
321 |
|
322 |
break; |
323 |
|
324 |
case mpiASSIGNMENT_d: |
325 |
the_event.event_type = ASSIGNMENT; |
326 |
the_event.evt.asmt.asmt_type = DOUBLE; |
327 |
strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs); |
328 |
the_event.evt.asmt.rhs.dval = mpiEventContainer.d1; |
329 |
|
330 |
#ifdef MPIBASS_VERBOSE |
331 |
|
332 |
fprintf(stderr, "mpiDiag at node %d: Assignment: %s = %lf\n", worldRank, |
333 |
the_event.evt.asmt.lhs, |
334 |
the_event.evt.asmt.rhs.dval ); |
335 |
#endif |
336 |
|
337 |
break; |
338 |
|
339 |
case mpiBLOCK_END: |
340 |
the_event.event_type = BLOCK_END; |
341 |
break; |
342 |
} |
343 |
|
344 |
#ifdef MPIBASS_VERBOSE |
345 |
|
346 |
fprintf(stderr, "mpiDiag at node %d: event type is %d\n", worldRank, |
347 |
the_event.event_type); |
348 |
#endif |
349 |
|
350 |
if (!event_handler(&the_event)){ |
351 |
|
352 |
sprintf(painCave.errMsg, |
353 |
"MPI event handling error at node %d => %s\n", |
354 |
worldRank, |
355 |
the_event.err_msg); |
356 |
painCave.isFatal = 1; |
357 |
simError(); |
358 |
} |
359 |
MPIcheckPoint(); |
360 |
} |
361 |
|
362 |
|
363 |
void mpiInterfaceExit(void){ |
364 |
int mpiStatus = MPI_INTERFACE_ABORT; |
365 |
|
366 |
MPI_Bcast(&mpiStatus,1,MPI_INT,0,MPI_COMM_WORLD); |
367 |
MPI_Finalize(); |
368 |
exit (0); |
369 |
|
370 |
} |
371 |
#endif |