ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/mpi_implementation/mpiBASS.c
Revision: 139
Committed: Wed Oct 16 21:07:16 2002 UTC (22 years, 6 months ago) by chuckv
Content type: text/plain
File size: 10198 byte(s)
Log Message:
*** empty log message ***

File Contents

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