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

File Contents

# User Rev Content
1 chuckv 123
2     #include <stdlib.h>
3     #include <stdio.h>
4     #include <string.h>
5 chuckv 135 #define __mpiBASSEVENT
6 chuckv 123 #include "mpiInterface.h"
7    
8    
9     void mpiCatchEvent(void);
10    
11    
12    
13    
14 chuckv 134 void mpiEventInit(void)
15 chuckv 123 {
16 chuckv 137 int blockCounts[5] = {1,3,4,120,80};
17     MPI_Aint dspls[5];
18     MPI_Datatype types[5];
19 chuckv 123 mBEvent protoEvent;
20    
21     int i;
22    
23 chuckv 134 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 chuckv 137 MPI_Address(&protoEvent.lhs , &dspls[4]);
28 chuckv 123
29    
30     types[0] = MPI_INT;
31     types[1] = MPI_DOUBLE;
32     types[2] = MPI_INT;
33     types[3] = MPI_CHAR;
34 chuckv 137 types[4] = MPI_CHAR;
35 chuckv 123
36    
37 chuckv 137 for (i =4; i >= 0; i--) dspls[i] -= dspls[0];
38 chuckv 123
39 chuckv 137 MPI_Type_struct(5,blockCounts,dspls,types,&mpiBASSEventType);
40 chuckv 123 MPI_Type_commit(&mpiBASSEventType);
41     }
42    
43    
44 chuckv 134 void throwMPIEvent(event* the_event)
45 chuckv 123 {
46 chuckv 134 mBEvent mpiEventContainer;
47 chuckv 123 int mpiStatus;
48     int mpiError;
49 chuckv 137 int mynode;
50 chuckv 123
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 chuckv 134 if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort(MPI_COMM_WORLD,0);
58 chuckv 123 exit (0);
59     }
60    
61     if (!mpiStatus){
62     switch (the_event->event_type){
63     case MOLECULE:
64     mpiEventContainer.type = mpiMOLECULE;
65 chuckv 134 mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int
66 chuckv 123 break;
67    
68     case ATOM:
69     mpiEventContainer.type = mpiATOM;
70 chuckv 134 mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int
71 chuckv 123 break;
72    
73     case BOND:
74     mpiEventContainer.type = mpiBOND;
75 chuckv 134 mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int
76 chuckv 123 break;
77    
78     case BEND:
79     mpiEventContainer.type = mpiBEND;
80 chuckv 134 mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int
81 chuckv 123 break;
82    
83     case TORSION:
84     mpiEventContainer.type = mpiTORSION;
85 chuckv 134 mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int
86 chuckv 123 break;
87    
88     case COMPONENT:
89     mpiEventContainer.type = mpiCOMPONENT;
90 chuckv 134 mpiEventContainer.i1 = the_event->evt.blk_index; // pack block index into first int
91 chuckv 123 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 chuckv 137
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 chuckv 123 switch (the_event->evt.asmt.asmt_type){
135     case STRING:
136     mpiEventContainer.type = mpiASSIGNMENT_s;
137 chuckv 134 strcpy(mpiEventContainer.cArray,the_event->evt.asmt.rhs.sval);
138 chuckv 123 break;
139    
140     case INT:
141     mpiEventContainer.type = mpiASSIGNMENT_i;
142 chuckv 134 mpiEventContainer.i1 = the_event->evt.asmt.rhs.ival;
143 chuckv 123 break;
144    
145     case DOUBLE:
146     mpiEventContainer.type = mpiASSIGNMENT_d;
147 chuckv 134 mpiEventContainer.d1 = the_event->evt.asmt.rhs.dval;
148 chuckv 123 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 chuckv 134 if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort(MPI_COMM_WORLD,0);
163 chuckv 123 exit (0);
164     }
165     }
166     }
167    
168    
169     // Everybody but node 0 runs this
170 chuckv 134 void mpiEventLoop(void)
171 chuckv 123 {
172     int mpiError;
173     int mpiContinue;
174 chuckv 137 int mynode;
175 chuckv 123
176 chuckv 137 #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 chuckv 123 mpiError = MPI_Bcast(&mpiContinue,1,MPI_INT,0,MPI_COMM_WORLD);
201     if (mpiError != MPI_SUCCESS){
202     mpiError = MPI_Finalize();
203 chuckv 134 if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort(MPI_COMM_WORLD,0);
204 chuckv 123 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 chuckv 134 if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort(MPI_COMM_WORLD,0);
216 chuckv 123 exit (0);
217     }
218     }
219    
220     if (mpiContinue == MPI_INTERFACE_ABORT){
221     mpiError = MPI_Finalize();
222 chuckv 134 if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort(MPI_COMM_WORLD,0);
223 chuckv 123 exit (0);
224     }
225     }
226    
227 chuckv 134 void mpiCatchEvent(void)
228 chuckv 123 {
229     event the_event;
230 chuckv 134 mBEvent mpiEventContainer;
231 chuckv 123 int mpiError;
232 chuckv 137 int mynode;
233 chuckv 123
234    
235     mpiError = MPI_Bcast(&mpiEventContainer,1,mpiBASSEventType,0,MPI_COMM_WORLD);
236    
237     if (mpiError != MPI_SUCCESS){
238     mpiError = MPI_Finalize();
239 chuckv 134 if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort(MPI_COMM_WORLD,0);
240 chuckv 123 exit (0);
241     }
242    
243    
244     switch (mpiEventContainer.type){
245     case mpiMOLECULE:
246     the_event.event_type = MOLECULE;
247 chuckv 134 the_event.evt.blk_index = mpiEventContainer.i1;
248 chuckv 123 break;
249    
250     case mpiATOM:
251     the_event.event_type = ATOM;
252 chuckv 134 the_event.evt.blk_index = mpiEventContainer.i1;
253 chuckv 123 break;
254    
255     case mpiBOND:
256     the_event.event_type = BOND;
257 chuckv 134 the_event.evt.blk_index = mpiEventContainer.i1;
258 chuckv 123 break;
259    
260     case mpiBEND:
261     the_event.event_type = BEND;
262 chuckv 134 the_event.evt.blk_index = mpiEventContainer.i1;
263 chuckv 123 break;
264    
265     case mpiTORSION:
266     the_event.event_type = TORSION;
267 chuckv 134 the_event.evt.blk_index = mpiEventContainer.i1;
268 chuckv 123 break;
269    
270     case mpiCOMPONENT:
271     the_event.event_type = COMPONENT;
272 chuckv 134 the_event.evt.blk_index = mpiEventContainer.i1;
273 chuckv 123 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 chuckv 137 strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs);
307 chuckv 134 strcpy(the_event.evt.asmt.rhs.sval,mpiEventContainer.cArray);
308 chuckv 137
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 chuckv 123 break;
317    
318     case mpiASSIGNMENT_i:
319     the_event.event_type = ASSIGNMENT;
320     the_event.evt.asmt.asmt_type = INT;
321 chuckv 137 strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs);
322 chuckv 134 the_event.evt.asmt.rhs.ival = mpiEventContainer.i1;
323 chuckv 137
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 chuckv 123 break;
332    
333     case mpiASSIGNMENT_d:
334     the_event.event_type = ASSIGNMENT;
335     the_event.evt.asmt.asmt_type = DOUBLE;
336 chuckv 137 strcpy(the_event.evt.asmt.lhs,mpiEventContainer.lhs);
337 chuckv 134 the_event.evt.asmt.rhs.dval = mpiEventContainer.d1;
338 chuckv 137
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 chuckv 123 break;
347    
348     case mpiBLOCK_END:
349     the_event.event_type = BLOCK_END;
350     break;
351     }
352    
353 chuckv 137 #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 chuckv 123 exit (0);
366     }
367     }
368 chuckv 134
369    
370     void mpiInterfaceExit(void){
371     int mpiError;
372     int mpiStatus = MPI_INTERFACE_ABORT;
373 chuckv 137
374 chuckv 134 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     }