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