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