ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/mpi_implementation/mpiInterface.c
Revision: 123
Committed: Mon Sep 30 19:37:26 2002 UTC (22 years, 7 months ago) by chuckv
Content type: text/plain
File size: 7438 byte(s)
Log Message:
changed dirs...

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     mpiEventInit()
14     {
15     int blockCounts[4] = {1,3,4,120}
16     MPI_Aint dspls[4];
17     MPI_Datatype types[4];
18     mBEvent protoEvent;
19    
20     int i;
21    
22     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    
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     throwMPIEvent(event* the_event)
42     {
43     mBEvent mpiBEventContainer;
44     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     if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort();
54     exit (0);
55     }
56    
57     if (!mpiStatus){
58     switch (the_event->event_type){
59     case MOLECULE:
60     mpiEventContainer.type = mpiMOLECULE;
61     mpiEventContainer.i1 = the_event->evt.block_index; // pack block index into first int
62     break;
63    
64     case ATOM:
65     mpiEventContainer.type = mpiATOM;
66     mpiEventContainer.i1 = the_event->evt.block_index; // pack block index into first int
67     break;
68    
69     case BOND:
70     mpiEventContainer.type = mpiBOND;
71     mpiEventContainer.i1 = the_event->evt.block_index; // pack block index into first int
72     break;
73    
74     case BEND:
75     mpiEventContainer.type = mpiBEND;
76     mpiEventContainer.i1 = the_event->evt.block_index; // pack block index into first int
77     break;
78    
79     case TORSION:
80     mpiEventContainer.type = mpiTORSION;
81     mpiEventContainer.i1 = the_event->evt.block_index; // pack block index into first int
82     break;
83    
84     case COMPONENT:
85     mpiEventContainer.type = mpiCOMPONENT;
86     mpiEventContainer.i1 = the_event->evt.block_index; // pack block index into first int
87     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     strcpy(mpiEventContainer.cArray,the_event->evt.asmt.sval);
121     break;
122    
123     case INT:
124     mpiEventContainer.type = mpiASSIGNMENT_i;
125     mpiEventContainer.i1 = the_event->evt.asmt.ival;
126     break;
127    
128     case DOUBLE:
129     mpiEventContainer.type = mpiASSIGNMENT_d;
130     mpiEventContainer.d1 = the_event->evt.asmt.dval;
131     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     if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort();
146     exit (0);
147     }
148     }
149     }
150    
151    
152     // Everybody but node 0 runs this
153     mpiEventLoop()
154     {
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     if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort();
162     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     if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort();
174     exit (0);
175     }
176     }
177    
178     if (mpiContinue == MPI_INTERFACE_ABORT){
179     mpiError = MPI_Finalize();
180     if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort();
181     exit (0);
182     }
183     }
184    
185     mpiCatchEvent()
186     {
187     event the_event;
188     mBEvent mpiBEventContainer;
189     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     if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort();
197     exit (0);
198     }
199    
200    
201     switch (mpiEventContainer.type){
202     case mpiMOLECULE:
203     the_event.event_type = MOLECULE;
204     the_event.evt.block_index = mpiEventContainer.i1;
205     break;
206    
207     case mpiATOM:
208     the_event.event_type = ATOM;
209     the_event.evt.block_index = mpiEventContainer.i1;
210     break;
211    
212     case mpiBOND:
213     the_event.event_type = BOND;
214     the_event.evt.block_index = mpiEventContainer.i1;
215     break;
216    
217     case mpiBEND:
218     the_event.event_type = BEND;
219     the_event.evt.block_index = mpiEventContainer.i1;
220     break;
221    
222     case mpiTORSION:
223     the_event.event_type = TORSION;
224     the_event.evt.block_index = mpiEventContainer.i1;
225     break;
226    
227     case mpiCOMPONENT:
228     the_event.event_type = COMPONENT;
229     the_event.evt.block_index = mpiEventContainer.i1;
230     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     strcpy(the_event.evt.asmt.sval,mpiEventContainer.cArray);
264     break;
265    
266     case mpiASSIGNMENT_i:
267     the_event.event_type = ASSIGNMENT;
268     the_event.evt.asmt.asmt_type = INT;
269     the_event.evt.asmt.ival = mpiEventContainer.i1;
270     break;
271    
272     case mpiASSIGNMENT_d:
273     the_event.event_type = ASSIGNMENT;
274     the_event.evt.asmt.asmt_type = DOUBLE;
275     the_event.evt.asmt.dval = mpiEventContainer.d1;
276     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     sprintf(stderr,"MPI event handling error => %s\n",the_event.err_msg);
286     mpiError = MPI_Finalize();
287     if (mpiError != MPI_SUCCESS) mpiError = MPI_Abort();
288     exit (0);
289     }
290     }