# | Line 15 | Line 15 | |
---|---|---|
15 | #include <mpi.h> | |
16 | #include <mpi++.h> | |
17 | #include "mpiSimulation.hpp" | |
18 | < | #define TAKE_THIS_TAG 0 |
18 | > | #define TAKE_THIS_TAG_CHAR 0 |
19 | > | #define TAKE_THIS_TAG_INT 1 |
20 | > | |
21 | > | void nodeZeroError( void ); |
22 | > | void anonymousNodeDie( void ); |
23 | > | |
24 | #endif // is_mpi | |
25 | ||
26 | InitializeFromFile :: InitializeFromFile( char *in_name ){ | |
# | Line 139 | Line 144 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
144 | // MPI Section of code.......... | |
145 | #else //IS_MPI | |
146 | ||
147 | + | // first thing first, suspend fatalities. |
148 | + | painCave.isEventLoop = 1; |
149 | + | |
150 | + | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
151 | + | int haveError; |
152 | + | |
153 | MPI::Status istatus; | |
154 | int *AtomToProcMap = mpiSim->getAtomToProcMap(); | |
155 | ||
156 | + | |
157 | + | haveError = 0; |
158 | if (worldRank == 0) { | |
159 | + | |
160 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
161 | if( eof_test == NULL ){ | |
162 | sprintf( painCave.errMsg, | |
163 | "Error reading 1st line of %d \n ",c_in_name); | |
164 | < | painCave.isFatal = 1; |
164 | > | haveError = 1; |
165 | simError(); | |
166 | } | |
167 | ||
# | Line 164 | Line 178 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
178 | "Initialize from File error. %s n_atoms, %d, " | |
179 | "does not match the BASS file's n_atoms, %d.\n", | |
180 | c_in_name, n_atoms, entry_plug->n_atoms ); | |
181 | < | painCave.isFatal = 1; |
181 | > | haveError= 1; |
182 | simError(); | |
183 | } | |
184 | ||
# | Line 174 | Line 188 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
188 | if(eof_test == NULL){ | |
189 | sprintf( painCave.errMsg, | |
190 | "error in reading commment in %s\n", c_in_name); | |
191 | < | painCave.isFatal = 1; |
191 | > | haveError= 1; |
192 | simError(); | |
193 | } | |
194 | ||
195 | + | if(haveError) nodeZeroError(); |
196 | ||
197 | for (i=0 ; i < mpiSim->getTotAtoms(); i++) { | |
198 | ||
# | Line 188 | Line 203 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
203 | "natoms = %d; index = %d\n" | |
204 | "error reading the line from the file.\n", | |
205 | c_in_name, n_atoms, i ); | |
206 | < | painCave.isFatal = 1; |
206 | > | haveError= 1; |
207 | simError(); | |
208 | } | |
209 | ||
210 | + | if(haveError) nodeZeroError(); |
211 | + | |
212 | // Get the Node number which wants this atom: | |
213 | which_node = AtomToProcMap[i]; | |
214 | < | if (which_node == mpiSim->getMyNode()) { |
214 | > | if (which_node == 0) { |
215 | parseErr = parseDumpLine( read_buffer, i ); | |
216 | if( parseErr != NULL ){ | |
217 | strcpy( painCave.errMsg, parseErr ); | |
218 | < | painCave.isFatal = 1; |
218 | > | haveError = 1; |
219 | simError(); | |
220 | } | |
221 | < | } else { |
221 | > | if(haveError) nodeZeroError(); |
222 | > | } |
223 | > | |
224 | > | else { |
225 | > | |
226 | > | myStatus = 1; |
227 | > | MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node, |
228 | > | TAKE_THIS_TAG_INT); |
229 | MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, | |
230 | < | TAKE_THIS_TAG); |
231 | < | MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG); |
230 | > | TAKE_THIS_TAG_CHAR); |
231 | > | MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); |
232 | > | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, istatus); |
233 | > | |
234 | > | if(!myStatus) nodeZeroError(); |
235 | } | |
236 | } | |
237 | < | sprintf(read_buffer, "GAMEOVER"); |
237 | > | myStatus = -1; |
238 | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { | |
239 | < | MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, j, |
240 | < | TAKE_THIS_TAG); |
239 | > | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j, |
240 | > | TAKE_THIS_TAG_INT); |
241 | } | |
242 | < | |
242 | > | |
243 | } else { | |
244 | < | |
244 | > | |
245 | done = 0; | |
246 | while (!done) { | |
247 | < | MPI::COMM_WORLD.Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
248 | < | TAKE_THIS_TAG, istatus); |
249 | < | if (strcmp(read_buffer, "GAMEOVER")) { |
250 | < | done = 1; |
251 | < | continue; |
252 | < | } else { |
253 | < | MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
254 | < | TAKE_THIS_TAG, istatus); |
255 | < | parseErr = parseDumpLine( read_buffer, which_atom ); |
256 | < | if( parseErr != NULL ){ |
257 | < | strcpy( painCave.errMsg, parseErr ); |
258 | < | painCave.isFatal = 1; |
259 | < | simError(); |
260 | < | } |
247 | > | |
248 | > | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0, |
249 | > | TAKE_THIS_TAG_INT, istatus); |
250 | > | |
251 | > | if(!myStatus) anonymousNodeDie(); |
252 | > | |
253 | > | if(myStatus < 0) break; |
254 | > | |
255 | > | MPI::COMM_WORLD.Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
256 | > | TAKE_THIS_TAG_CHAR, istatus); |
257 | > | MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
258 | > | TAKE_THIS_TAG_INT, istatus); |
259 | > | |
260 | > | myStatus = 1; |
261 | > | parseErr = parseDumpLine( read_buffer, which_atom ); |
262 | > | if( parseErr != NULL ){ |
263 | > | strcpy( painCave.errMsg, parseErr ); |
264 | > | myStatus = 0;; |
265 | > | simError(); |
266 | } | |
267 | + | |
268 | + | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0, |
269 | + | TAKE_THIS_TAG_INT); |
270 | + | |
271 | } | |
272 | } | |
273 | < | |
273 | > | |
274 | > | // last thing last, enable fatalities. |
275 | > | painCave.isEventLoop = 0; |
276 | > | |
277 | #endif | |
278 | } | |
279 | ||
280 | < | char* InitializeFromFile::parseDumpLine(char* readLine, int atomIndex){ |
280 | > | char* InitializeFromFile::parseDumpLine(char* readLine, int globalIndex){ |
281 | ||
282 | char *foo; // the pointer to the current string token | |
283 | ||
# | Line 251 | Line 290 | char* InitializeFromFile::parseDumpLine(char* readLine | |
290 | Atom **atoms = entry_plug->atoms; | |
291 | DirectionalAtom* dAtom; | |
292 | ||
293 | < | int n_atoms; |
293 | > | int j, n_atoms, atomIndex; |
294 | ||
295 | #ifdef IS_MPI | |
296 | n_atoms = mpiSim->getTotAtoms(); | |
297 | + | atomIndex=-1; |
298 | + | for (j=0; j < mpiSim->getMyNlocal(); j++) { |
299 | + | if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j; |
300 | + | } |
301 | + | if (atomIndex == -1) { |
302 | + | sprintf( painCave.errMsg, |
303 | + | "Initialize from file error. Atom at index %d " |
304 | + | "in file %s does not exist on processor %d .\n", |
305 | + | globalIndex, c_in_name, mpiSim->getMyNode() ); |
306 | + | return strdup( painCave.errMsg ); |
307 | + | } |
308 | #else | |
309 | n_atoms = entry_plug->n_atoms; | |
310 | + | atomIndex = globalIndex; |
311 | #endif // is_mpi | |
312 | ||
262 | – | |
313 | // set the string tokenizer | |
314 | ||
315 | foo = strtok(readLine, " ,;\t"); | |
# | Line 450 | Line 500 | char* InitializeFromFile::parseDumpLine(char* readLine | |
500 | ||
501 | return NULL; | |
502 | } | |
503 | + | |
504 | + | |
505 | + | #ifdef IS_MPI |
506 | + | |
507 | + | // a couple of functions to let us escape the read loop |
508 | + | |
509 | + | void nodeZeroError( void ){ |
510 | + | int j, myStatus; |
511 | + | |
512 | + | myStatus = 0; |
513 | + | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
514 | + | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j, |
515 | + | TAKE_THIS_TAG_INT); |
516 | + | } |
517 | + | |
518 | + | |
519 | + | MPI_Finalize(); |
520 | + | exit (0); |
521 | + | |
522 | + | } |
523 | + | |
524 | + | void anonymousNodeDie( void ){ |
525 | + | |
526 | + | MPI_Finalize(); |
527 | + | exit (0); |
528 | + | } |
529 | + | |
530 | + | #endif //is_mpi |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |