ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/mpi_implementation/mpiInterface.c
Revision: 135
Committed: Fri Oct 11 17:29:40 2002 UTC (22 years, 6 months ago) by chuckv
Content type: text/plain
File size: 8029 byte(s)
Log Message:
Fixed double inclusion of mpiBASSEventType with define in
header file.

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