ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/mpiBASS.c
Revision: 988
Committed: Tue Jan 27 19:37:48 2004 UTC (20 years, 5 months ago) by gezelter
Content type: text/plain
File size: 9626 byte(s)
Log Message:
More BASS changes to do new rigidBody scheme

File Contents

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