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