# | Line 8 | Line 8 | |
---|---|---|
8 | #include "mpiSimulation.hpp" | |
9 | #define TAKE_THIS_TAG_CHAR 1 | |
10 | #define TAKE_THIS_TAG_INT 2 | |
11 | + | |
12 | + | namespace dWrite{ |
13 | + | void nodeZeroError( void ); |
14 | + | void anonymousNodeDie( void ); |
15 | + | } |
16 | + | |
17 | + | using namespace dWrite; |
18 | #endif //is_mpi | |
19 | ||
20 | #include "ReadWrite.hpp" | |
# | Line 121 | Line 128 | void DumpWriter::writeDump( double currentTime ){ | |
128 | ||
129 | #else // is_mpi | |
130 | ||
131 | + | // first thing first, suspend fatalities. |
132 | + | painCave.isEventLoop = 1; |
133 | + | |
134 | + | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
135 | + | int haveError; |
136 | + | |
137 | MPI::Status istatus; | |
138 | int *AtomToProcMap = mpiSim->getAtomToProcMap(); | |
139 | ||
# | Line 141 | Line 154 | void DumpWriter::writeDump( double currentTime ){ | |
154 | ||
155 | if (which_node == 0 ) { | |
156 | ||
157 | + | haveError = 0; |
158 | which_atom = i; | |
159 | local_index=-1; | |
160 | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { | |
# | Line 180 | Line 194 | void DumpWriter::writeDump( double currentTime ){ | |
194 | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); | |
195 | } | |
196 | else { | |
197 | < | strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
197 | > | sprintf(painCave.errMsg, |
198 | > | "Atom %d not found on processor %d\n", |
199 | > | i, worldRank ); |
200 | > | haveError= 1; |
201 | > | simError(); |
202 | } | |
203 | < | } |
203 | > | |
204 | > | if(haveError) nodeZeroError(); |
205 | > | |
206 | > | } |
207 | else { | |
208 | < | |
209 | < | //std::cerr << "node 0: sending node " << which_node << " request for atom " << i << "\n"; |
208 | > | myStatus = 1; |
209 | > | MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node, |
210 | > | TAKE_THIS_TAG_INT); |
211 | MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); | |
190 | – | //std::cerr << "node 0: sent!\n"; |
212 | MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, | |
213 | TAKE_THIS_TAG_CHAR, istatus); | |
214 | < | //std::cerr << "node 0: got this line: " << writeLine; |
214 | > | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node, |
215 | > | TAKE_THIS_TAG_INT, istatus); |
216 | > | |
217 | > | if(!myStatus) nodeZeroError(); |
218 | > | |
219 | } | |
220 | ||
221 | outFile << writeLine; | |
# | Line 198 | Line 223 | void DumpWriter::writeDump( double currentTime ){ | |
223 | } | |
224 | ||
225 | // kill everyone off: | |
226 | < | game_over = -1; |
226 | > | myStatus = -1; |
227 | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { | |
228 | < | MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT); |
228 | > | MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, j, |
229 | > | TAKE_THIS_TAG_INT); |
230 | } | |
231 | ||
232 | } else { | |
233 | ||
234 | done = 0; | |
235 | while (!done) { | |
236 | < | //std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n"; |
236 | > | |
237 | > | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0, |
238 | > | TAKE_THIS_TAG_INT, istatus); |
239 | > | |
240 | > | if(!myStatus) anonymousNodeDie(); |
241 | > | |
242 | > | if(myStatus < 0) break; |
243 | > | |
244 | MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, | |
245 | TAKE_THIS_TAG_INT, istatus); | |
246 | < | //std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n"; |
247 | < | if (which_atom == -1) { |
248 | < | done=1; |
249 | < | continue; |
250 | < | } else { |
218 | < | local_index=-1; |
219 | < | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
220 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
221 | < | } |
222 | < | if (local_index != -1) { |
223 | < | //format the line |
224 | < | sprintf( tempBuffer, |
225 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
226 | < | atoms[local_index]->getType(), |
227 | < | atoms[local_index]->getX(), |
228 | < | atoms[local_index]->getY(), |
229 | < | atoms[local_index]->getZ(), |
230 | < | atoms[local_index]->get_vx(), |
231 | < | atoms[local_index]->get_vy(), |
232 | < | atoms[local_index]->get_vz()); // check here. |
233 | < | strcpy( writeLine, tempBuffer ); |
234 | < | |
235 | < | if( atoms[local_index]->isDirectional() ){ |
236 | < | |
237 | < | dAtom = (DirectionalAtom *)atoms[local_index]; |
238 | < | dAtom->getQ( q ); |
239 | < | |
240 | < | sprintf( tempBuffer, |
241 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
242 | < | q[0], |
243 | < | q[1], |
244 | < | q[2], |
245 | < | q[3], |
246 | < | dAtom->getJx(), |
247 | < | dAtom->getJy(), |
248 | < | dAtom->getJz()); |
249 | < | strcat( writeLine, tempBuffer ); |
250 | < | } |
251 | < | else |
252 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
253 | < | // std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine; |
254 | < | MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
255 | < | TAKE_THIS_TAG_CHAR); |
256 | < | } else { |
257 | < | strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
258 | < | MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
259 | < | TAKE_THIS_TAG_CHAR); |
260 | < | } |
246 | > | |
247 | > | myStatus = 1; |
248 | > | local_index=-1; |
249 | > | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
250 | > | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
251 | } | |
252 | + | if (local_index != -1) { |
253 | + | //format the line |
254 | + | sprintf( tempBuffer, |
255 | + | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
256 | + | atoms[local_index]->getType(), |
257 | + | atoms[local_index]->getX(), |
258 | + | atoms[local_index]->getY(), |
259 | + | atoms[local_index]->getZ(), |
260 | + | atoms[local_index]->get_vx(), |
261 | + | atoms[local_index]->get_vy(), |
262 | + | atoms[local_index]->get_vz()); // check here. |
263 | + | strcpy( writeLine, tempBuffer ); |
264 | + | |
265 | + | if( atoms[local_index]->isDirectional() ){ |
266 | + | |
267 | + | dAtom = (DirectionalAtom *)atoms[local_index]; |
268 | + | dAtom->getQ( q ); |
269 | + | |
270 | + | sprintf( tempBuffer, |
271 | + | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
272 | + | q[0], |
273 | + | q[1], |
274 | + | q[2], |
275 | + | q[3], |
276 | + | dAtom->getJx(), |
277 | + | dAtom->getJy(), |
278 | + | dAtom->getJz()); |
279 | + | strcat( writeLine, tempBuffer ); |
280 | + | } |
281 | + | else{ |
282 | + | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
283 | + | } |
284 | + | } |
285 | + | else { |
286 | + | sprintf(painCave.errMsg, |
287 | + | "Atom %d not found on processor %d\n", |
288 | + | which_atom, worldRank ); |
289 | + | myStatus = 0; |
290 | + | simError(); |
291 | + | |
292 | + | strcpy( writeLine, "Hello, I'm an error.\n"); |
293 | + | } |
294 | + | |
295 | + | MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
296 | + | TAKE_THIS_TAG_CHAR); |
297 | + | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0, |
298 | + | TAKE_THIS_TAG_INT); |
299 | } | |
300 | } | |
301 | outFile.flush(); | |
302 | sprintf( checkPointMsg, | |
303 | "Sucessfully took a dump.\n"); | |
304 | MPIcheckPoint(); | |
305 | + | |
306 | + | // last thing last, enable fatalities. |
307 | + | painCave.isEventLoop = 0; |
308 | + | |
309 | #endif // is_mpi | |
310 | } | |
311 | ||
# | Line 357 | Line 398 | void DumpWriter::writeFinal(){ | |
398 | ||
399 | #else // is_mpi | |
400 | ||
401 | + | // first thing first, suspend fatalities. |
402 | + | painCave.isEventLoop = 1; |
403 | + | |
404 | + | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
405 | + | int haveError; |
406 | + | |
407 | MPI::Status istatus; | |
408 | int *AtomToProcMap = mpiSim->getAtomToProcMap(); | |
409 | ||
410 | // write out header and node 0's coordinates | |
411 | ||
412 | + | haveError = 0; |
413 | if( worldRank == 0 ){ | |
414 | finalOut << mpiSim->getTotAtoms() << "\n"; | |
415 | ||
# | Line 375 | Line 423 | void DumpWriter::writeFinal(){ | |
423 | which_node = AtomToProcMap[i]; | |
424 | ||
425 | if (which_node == mpiSim->getMyNode()) { | |
426 | < | |
427 | < | sprintf( tempBuffer, |
428 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
429 | < | atoms[i]->getType(), |
430 | < | atoms[i]->getX(), |
383 | < | atoms[i]->getY(), |
384 | < | atoms[i]->getZ(), |
385 | < | atoms[i]->get_vx(), |
386 | < | atoms[i]->get_vy(), |
387 | < | atoms[i]->get_vz()); |
388 | < | strcpy( writeLine, tempBuffer ); |
389 | < | |
390 | < | if( atoms[i]->isDirectional() ){ |
391 | < | |
392 | < | dAtom = (DirectionalAtom *)atoms[i]; |
393 | < | dAtom->getQ( q ); |
394 | < | |
395 | < | sprintf( tempBuffer, |
396 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
397 | < | q[0], |
398 | < | q[1], |
399 | < | q[2], |
400 | < | q[3], |
401 | < | dAtom->getJx(), |
402 | < | dAtom->getJy(), |
403 | < | dAtom->getJz()); |
404 | < | strcat( writeLine, tempBuffer ); |
426 | > | |
427 | > | which_atom = i; |
428 | > | local_index=-1; |
429 | > | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
430 | > | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
431 | } | |
432 | < | else |
433 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
434 | < | |
435 | < | } else { |
432 | > | if (local_index != -1) { |
433 | > | sprintf( tempBuffer, |
434 | > | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
435 | > | atoms[local_index]->getType(), |
436 | > | atoms[local_index]->getX(), |
437 | > | atoms[local_index]->getY(), |
438 | > | atoms[local_index]->getZ(), |
439 | > | atoms[local_index]->get_vx(), |
440 | > | atoms[local_index]->get_vy(), |
441 | > | atoms[local_index]->get_vz()); |
442 | > | strcpy( writeLine, tempBuffer ); |
443 | > | |
444 | > | if( atoms[local_index]->isDirectional() ){ |
445 | > | |
446 | > | dAtom = (DirectionalAtom *)atoms[local_index]; |
447 | > | dAtom->getQ( q ); |
448 | > | |
449 | > | sprintf( tempBuffer, |
450 | > | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
451 | > | q[0], |
452 | > | q[1], |
453 | > | q[2], |
454 | > | q[3], |
455 | > | dAtom->getJx(), |
456 | > | dAtom->getJy(), |
457 | > | dAtom->getJz()); |
458 | > | strcat( writeLine, tempBuffer ); |
459 | > | } |
460 | > | else |
461 | > | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
462 | > | } |
463 | > | else { |
464 | > | sprintf(painCave.errMsg, |
465 | > | "Atom %d not found on processor %d\n", |
466 | > | i, worldRank ); |
467 | > | haveError= 1; |
468 | > | simError(); |
469 | > | } |
470 | > | |
471 | > | if(haveError) nodeZeroError(); |
472 | > | |
473 | > | } |
474 | > | else { |
475 | ||
476 | + | myStatus = 1; |
477 | + | MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node, |
478 | + | TAKE_THIS_TAG_INT); |
479 | MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); | |
480 | MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, | |
481 | < | TAKE_THIS_TAG_CHAR, istatus); |
481 | > | TAKE_THIS_TAG_CHAR, istatus); |
482 | > | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node, |
483 | > | TAKE_THIS_TAG_INT, istatus); |
484 | > | |
485 | > | if(!myStatus) nodeZeroError(); |
486 | } | |
487 | ||
488 | finalOut << writeLine; | |
489 | } | |
490 | ||
491 | // kill everyone off: | |
492 | < | game_over = -1; |
493 | < | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
494 | < | MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT); |
492 | > | myStatus = -1; |
493 | > | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
494 | > | MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, j, |
495 | > | TAKE_THIS_TAG_INT); |
496 | } | |
497 | ||
498 | } else { | |
499 | ||
500 | done = 0; | |
501 | while (!done) { | |
502 | + | |
503 | + | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0, |
504 | + | TAKE_THIS_TAG_INT, istatus); |
505 | + | |
506 | + | if(!myStatus) anonymousNodeDie(); |
507 | + | |
508 | + | if(myStatus < 0) break; |
509 | + | |
510 | MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, | |
511 | TAKE_THIS_TAG_INT, istatus); | |
512 | + | |
513 | + | myStatus = 1; |
514 | + | local_index=-1; |
515 | + | for (j=0; j < mpiSim->getMyNlocal(); j++) { |
516 | + | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
517 | + | } |
518 | + | if (local_index != -1) { |
519 | ||
520 | < | if (which_atom == -1) { |
521 | < | done=1; |
522 | < | continue; |
523 | < | } else { |
524 | < | |
525 | < | local_index=-1; |
526 | < | for (j=0; j < mpiSim->getMyNlocal(); j++) { |
527 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
528 | < | } |
529 | < | if (local_index != -1) { |
530 | < | |
531 | < | //format the line |
532 | < | sprintf( tempBuffer, |
445 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
446 | < | atoms[local_index]->getType(), |
447 | < | atoms[local_index]->getX(), |
448 | < | atoms[local_index]->getY(), |
449 | < | atoms[local_index]->getZ(), |
450 | < | atoms[local_index]->get_vx(), |
451 | < | atoms[local_index]->get_vy(), |
452 | < | atoms[local_index]->get_vz()); // check here. |
453 | < | strcpy( writeLine, tempBuffer ); |
520 | > | //format the line |
521 | > | sprintf( tempBuffer, |
522 | > | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
523 | > | atoms[local_index]->getType(), |
524 | > | atoms[local_index]->getX(), |
525 | > | atoms[local_index]->getY(), |
526 | > | atoms[local_index]->getZ(), |
527 | > | atoms[local_index]->get_vx(), |
528 | > | atoms[local_index]->get_vy(), |
529 | > | atoms[local_index]->get_vz()); // check here. |
530 | > | strcpy( writeLine, tempBuffer ); |
531 | > | |
532 | > | if( atoms[local_index]->isDirectional() ){ |
533 | ||
534 | < | if( atoms[local_index]->isDirectional() ){ |
535 | < | |
536 | < | dAtom = (DirectionalAtom *)atoms[local_index]; |
537 | < | dAtom->getQ( q ); |
538 | < | |
539 | < | sprintf( tempBuffer, |
540 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
541 | < | q[0], |
542 | < | q[1], |
543 | < | q[2], |
544 | < | q[3], |
545 | < | dAtom->getJx(), |
546 | < | dAtom->getJy(), |
547 | < | dAtom->getJz()); |
548 | < | strcat( writeLine, tempBuffer ); |
549 | < | } |
550 | < | else |
551 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
552 | < | |
553 | < | MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
554 | < | TAKE_THIS_TAG_CHAR); |
555 | < | } else { |
556 | < | strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
557 | < | MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
558 | < | TAKE_THIS_TAG_CHAR); |
559 | < | } |
534 | > | dAtom = (DirectionalAtom *)atoms[local_index]; |
535 | > | dAtom->getQ( q ); |
536 | > | |
537 | > | sprintf( tempBuffer, |
538 | > | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
539 | > | q[0], |
540 | > | q[1], |
541 | > | q[2], |
542 | > | q[3], |
543 | > | dAtom->getJx(), |
544 | > | dAtom->getJy(), |
545 | > | dAtom->getJz()); |
546 | > | strcat( writeLine, tempBuffer ); |
547 | > | } |
548 | > | else{ |
549 | > | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
550 | > | } |
551 | > | } |
552 | > | else { |
553 | > | sprintf(painCave.errMsg, |
554 | > | "Atom %d not found on processor %d\n", |
555 | > | which_atom, worldRank ); |
556 | > | myStatus = 0; |
557 | > | simError(); |
558 | > | |
559 | > | strcpy( writeLine, "Hello, I'm an error.\n"); |
560 | } | |
561 | + | |
562 | + | MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
563 | + | TAKE_THIS_TAG_CHAR); |
564 | + | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0, |
565 | + | TAKE_THIS_TAG_INT); |
566 | } | |
567 | } | |
568 | finalOut.flush(); | |
569 | sprintf( checkPointMsg, | |
570 | "Sucessfully took a dump.\n"); | |
571 | MPIcheckPoint(); | |
572 | < | |
572 | > | |
573 | if( worldRank == 0 ) finalOut.close(); | |
574 | #endif // is_mpi | |
575 | } | |
576 | + | |
577 | + | |
578 | + | |
579 | + | #ifdef IS_MPI |
580 | + | |
581 | + | // a couple of functions to let us escape the write loop |
582 | + | |
583 | + | void dWrite::nodeZeroError( void ){ |
584 | + | int j, myStatus; |
585 | + | |
586 | + | myStatus = 0; |
587 | + | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
588 | + | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j, |
589 | + | TAKE_THIS_TAG_INT); |
590 | + | } |
591 | + | |
592 | + | |
593 | + | MPI_Finalize(); |
594 | + | exit (0); |
595 | + | |
596 | + | } |
597 | + | |
598 | + | void dWrite::anonymousNodeDie( void ){ |
599 | + | |
600 | + | MPI_Finalize(); |
601 | + | exit (0); |
602 | + | } |
603 | + | |
604 | + | #endif //is_mpi |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |