ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/mpiBASS.c
Revision: 675
Committed: Mon Aug 11 19:38:44 2003 UTC (20 years, 11 months ago) by mmeineke
Content type: text/plain
File size: 8974 byte(s)
Log Message:
Added zConstraint into the BASS language syntax.

File Contents

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