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