4 |
|
|
5 |
|
#ifdef IS_MPI |
6 |
|
#include <mpi.h> |
7 |
– |
#include <mpi++.h> |
7 |
|
#include "mpiSimulation.hpp" |
8 |
|
#define TAKE_THIS_TAG_CHAR 1 |
9 |
|
#define TAKE_THIS_TAG_INT 2 |
10 |
+ |
|
11 |
+ |
namespace dWrite{ |
12 |
+ |
void nodeZeroError( void ); |
13 |
+ |
void anonymousNodeDie( void ); |
14 |
+ |
} |
15 |
+ |
|
16 |
+ |
using namespace dWrite; |
17 |
|
#endif //is_mpi |
18 |
|
|
19 |
|
#include "ReadWrite.hpp" |
27 |
|
if(worldRank == 0 ){ |
28 |
|
#endif // is_mpi |
29 |
|
|
24 |
– |
|
25 |
– |
|
30 |
|
strcpy( outName, entry_plug->sampleName ); |
31 |
|
|
32 |
|
outFile.open(outName, ios::out | ios::trunc ); |
39 |
|
painCave.isFatal = 1; |
40 |
|
simError(); |
41 |
|
} |
42 |
< |
|
42 |
> |
|
43 |
|
//outFile.setf( ios::scientific ); |
44 |
|
|
45 |
|
#ifdef IS_MPI |
70 |
|
char tempBuffer[BUFFERSIZE]; |
71 |
|
char writeLine[BUFFERSIZE]; |
72 |
|
|
73 |
< |
int i, j, which_node, done, game_over, which_atom, local_index; |
73 |
> |
int i, j, which_node, done, which_atom, local_index; |
74 |
|
double q[4]; |
75 |
|
DirectionalAtom* dAtom; |
76 |
|
int nAtoms = entry_plug->n_atoms; |
125 |
|
|
126 |
|
#else // is_mpi |
127 |
|
|
128 |
< |
MPI::Status istatus; |
128 |
> |
// first thing first, suspend fatalities. |
129 |
> |
painCave.isEventLoop = 1; |
130 |
> |
|
131 |
> |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
132 |
> |
int haveError; |
133 |
> |
|
134 |
> |
MPI_Status istatus; |
135 |
|
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
136 |
|
|
137 |
|
// write out header and node 0's coordinates |
151 |
|
|
152 |
|
if (which_node == 0 ) { |
153 |
|
|
154 |
+ |
haveError = 0; |
155 |
|
which_atom = i; |
156 |
|
local_index=-1; |
157 |
|
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
191 |
|
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
192 |
|
} |
193 |
|
else { |
194 |
< |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
194 |
> |
sprintf(painCave.errMsg, |
195 |
> |
"Atom %d not found on processor %d\n", |
196 |
> |
i, worldRank ); |
197 |
> |
haveError= 1; |
198 |
> |
simError(); |
199 |
|
} |
200 |
< |
} |
200 |
> |
|
201 |
> |
if(haveError) nodeZeroError(); |
202 |
> |
|
203 |
> |
} |
204 |
|
else { |
205 |
< |
|
206 |
< |
//std::cerr << "node 0: sending node " << which_node << " request for atom " << i << "\n"; |
207 |
< |
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); |
208 |
< |
//std::cerr << "node 0: sent!\n"; |
209 |
< |
MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
210 |
< |
TAKE_THIS_TAG_CHAR, istatus); |
211 |
< |
//std::cerr << "node 0: got this line: " << writeLine; |
205 |
> |
myStatus = 1; |
206 |
> |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
207 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
208 |
> |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
209 |
> |
MPI_COMM_WORLD); |
210 |
> |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
211 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
212 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
213 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
214 |
> |
|
215 |
> |
if(!myStatus) nodeZeroError(); |
216 |
> |
|
217 |
|
} |
218 |
|
|
219 |
|
outFile << writeLine; |
221 |
|
} |
222 |
|
|
223 |
|
// kill everyone off: |
224 |
< |
game_over = -1; |
224 |
> |
myStatus = -1; |
225 |
|
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
226 |
< |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT); |
226 |
> |
MPI_Send(&myStatus, 1, MPI_INT, j, |
227 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
228 |
|
} |
229 |
|
|
230 |
|
} else { |
231 |
|
|
232 |
|
done = 0; |
233 |
|
while (!done) { |
234 |
< |
//std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n"; |
235 |
< |
MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
236 |
< |
TAKE_THIS_TAG_INT, istatus); |
237 |
< |
//std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n"; |
238 |
< |
if (which_atom == -1) { |
239 |
< |
done=1; |
240 |
< |
continue; |
241 |
< |
} else { |
242 |
< |
local_index=-1; |
243 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
244 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
245 |
< |
} |
246 |
< |
if (local_index != -1) { |
247 |
< |
//format the line |
248 |
< |
sprintf( tempBuffer, |
249 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
250 |
< |
atoms[local_index]->getType(), |
251 |
< |
atoms[local_index]->getX(), |
252 |
< |
atoms[local_index]->getY(), |
253 |
< |
atoms[local_index]->getZ(), |
254 |
< |
atoms[local_index]->get_vx(), |
255 |
< |
atoms[local_index]->get_vy(), |
256 |
< |
atoms[local_index]->get_vz()); // check here. |
257 |
< |
strcpy( writeLine, tempBuffer ); |
234 |
> |
|
235 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
236 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
237 |
> |
|
238 |
> |
if(!myStatus) anonymousNodeDie(); |
239 |
> |
|
240 |
> |
if(myStatus < 0) break; |
241 |
> |
|
242 |
> |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
243 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
244 |
> |
|
245 |
> |
myStatus = 1; |
246 |
> |
local_index=-1; |
247 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
248 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
249 |
> |
} |
250 |
> |
if (local_index != -1) { |
251 |
> |
//format the line |
252 |
> |
sprintf( tempBuffer, |
253 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
254 |
> |
atoms[local_index]->getType(), |
255 |
> |
atoms[local_index]->getX(), |
256 |
> |
atoms[local_index]->getY(), |
257 |
> |
atoms[local_index]->getZ(), |
258 |
> |
atoms[local_index]->get_vx(), |
259 |
> |
atoms[local_index]->get_vy(), |
260 |
> |
atoms[local_index]->get_vz()); // check here. |
261 |
> |
strcpy( writeLine, tempBuffer ); |
262 |
> |
|
263 |
> |
if( atoms[local_index]->isDirectional() ){ |
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 |
< |
// std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine; |
284 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
285 |
< |
TAKE_THIS_TAG_CHAR); |
286 |
< |
} else { |
287 |
< |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
288 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
289 |
< |
TAKE_THIS_TAG_CHAR); |
290 |
< |
} |
265 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
266 |
> |
dAtom->getQ( q ); |
267 |
> |
|
268 |
> |
sprintf( tempBuffer, |
269 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
270 |
> |
q[0], |
271 |
> |
q[1], |
272 |
> |
q[2], |
273 |
> |
q[3], |
274 |
> |
dAtom->getJx(), |
275 |
> |
dAtom->getJy(), |
276 |
> |
dAtom->getJz()); |
277 |
> |
strcat( writeLine, tempBuffer ); |
278 |
> |
} |
279 |
> |
else{ |
280 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
281 |
> |
} |
282 |
> |
} |
283 |
> |
else { |
284 |
> |
sprintf(painCave.errMsg, |
285 |
> |
"Atom %d not found on processor %d\n", |
286 |
> |
which_atom, worldRank ); |
287 |
> |
myStatus = 0; |
288 |
> |
simError(); |
289 |
> |
|
290 |
> |
strcpy( writeLine, "Hello, I'm an error.\n"); |
291 |
|
} |
292 |
+ |
|
293 |
+ |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
294 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
295 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
296 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
297 |
|
} |
298 |
|
} |
299 |
|
outFile.flush(); |
300 |
|
sprintf( checkPointMsg, |
301 |
|
"Sucessfully took a dump.\n"); |
302 |
|
MPIcheckPoint(); |
303 |
+ |
|
304 |
+ |
// last thing last, enable fatalities. |
305 |
+ |
painCave.isEventLoop = 0; |
306 |
+ |
|
307 |
|
#endif // is_mpi |
308 |
|
} |
309 |
|
|
396 |
|
|
397 |
|
#else // is_mpi |
398 |
|
|
399 |
< |
MPI::Status istatus; |
399 |
> |
// first thing first, suspend fatalities. |
400 |
> |
painCave.isEventLoop = 1; |
401 |
> |
|
402 |
> |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
403 |
> |
int haveError; |
404 |
> |
|
405 |
> |
MPI_Status istatus; |
406 |
|
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
407 |
|
|
408 |
|
// write out header and node 0's coordinates |
409 |
|
|
410 |
+ |
haveError = 0; |
411 |
|
if( worldRank == 0 ){ |
412 |
|
finalOut << mpiSim->getTotAtoms() << "\n"; |
413 |
|
|
459 |
|
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
460 |
|
} |
461 |
|
else { |
462 |
< |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
462 |
> |
sprintf(painCave.errMsg, |
463 |
> |
"Atom %d not found on processor %d\n", |
464 |
> |
i, worldRank ); |
465 |
> |
haveError= 1; |
466 |
> |
simError(); |
467 |
|
} |
468 |
+ |
|
469 |
+ |
if(haveError) nodeZeroError(); |
470 |
|
|
471 |
< |
} else { |
471 |
> |
} |
472 |
> |
else { |
473 |
|
|
474 |
< |
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); |
475 |
< |
MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
476 |
< |
TAKE_THIS_TAG_CHAR, istatus); |
474 |
> |
myStatus = 1; |
475 |
> |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
476 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
477 |
> |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
478 |
> |
MPI_COMM_WORLD); |
479 |
> |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
480 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
481 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
482 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
483 |
> |
|
484 |
> |
if(!myStatus) nodeZeroError(); |
485 |
|
} |
486 |
|
|
487 |
|
finalOut << writeLine; |
488 |
|
} |
489 |
|
|
490 |
|
// kill everyone off: |
491 |
< |
game_over = -1; |
492 |
< |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
493 |
< |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT); |
491 |
> |
myStatus = -1; |
492 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
493 |
> |
MPI_Send(&myStatus, 1, MPI_INT, j, |
494 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
495 |
|
} |
496 |
|
|
497 |
|
} else { |
498 |
|
|
499 |
|
done = 0; |
500 |
|
while (!done) { |
439 |
– |
MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
440 |
– |
TAKE_THIS_TAG_INT, istatus); |
501 |
|
|
502 |
< |
if (which_atom == -1) { |
503 |
< |
done=1; |
504 |
< |
continue; |
505 |
< |
} else { |
502 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
503 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
504 |
> |
|
505 |
> |
if(!myStatus) anonymousNodeDie(); |
506 |
> |
|
507 |
> |
if(myStatus < 0) break; |
508 |
> |
|
509 |
> |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
510 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
511 |
> |
|
512 |
> |
myStatus = 1; |
513 |
> |
local_index=-1; |
514 |
> |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
515 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
516 |
> |
} |
517 |
> |
if (local_index != -1) { |
518 |
|
|
519 |
< |
local_index=-1; |
520 |
< |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
521 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
522 |
< |
} |
523 |
< |
if (local_index != -1) { |
524 |
< |
|
525 |
< |
//format the line |
526 |
< |
sprintf( tempBuffer, |
527 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
528 |
< |
atoms[local_index]->getType(), |
529 |
< |
atoms[local_index]->getX(), |
530 |
< |
atoms[local_index]->getY(), |
531 |
< |
atoms[local_index]->getZ(), |
460 |
< |
atoms[local_index]->get_vx(), |
461 |
< |
atoms[local_index]->get_vy(), |
462 |
< |
atoms[local_index]->get_vz()); // check here. |
463 |
< |
strcpy( writeLine, tempBuffer ); |
519 |
> |
//format the line |
520 |
> |
sprintf( tempBuffer, |
521 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
522 |
> |
atoms[local_index]->getType(), |
523 |
> |
atoms[local_index]->getX(), |
524 |
> |
atoms[local_index]->getY(), |
525 |
> |
atoms[local_index]->getZ(), |
526 |
> |
atoms[local_index]->get_vx(), |
527 |
> |
atoms[local_index]->get_vy(), |
528 |
> |
atoms[local_index]->get_vz()); // check here. |
529 |
> |
strcpy( writeLine, tempBuffer ); |
530 |
> |
|
531 |
> |
if( atoms[local_index]->isDirectional() ){ |
532 |
|
|
533 |
< |
if( atoms[local_index]->isDirectional() ){ |
534 |
< |
|
535 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
536 |
< |
dAtom->getQ( q ); |
537 |
< |
|
538 |
< |
sprintf( tempBuffer, |
539 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
540 |
< |
q[0], |
541 |
< |
q[1], |
542 |
< |
q[2], |
543 |
< |
q[3], |
544 |
< |
dAtom->getJx(), |
545 |
< |
dAtom->getJy(), |
546 |
< |
dAtom->getJz()); |
547 |
< |
strcat( writeLine, tempBuffer ); |
548 |
< |
} |
549 |
< |
else |
550 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
551 |
< |
|
552 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
553 |
< |
TAKE_THIS_TAG_CHAR); |
554 |
< |
} else { |
555 |
< |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
556 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
557 |
< |
TAKE_THIS_TAG_CHAR); |
558 |
< |
} |
533 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
534 |
> |
dAtom->getQ( q ); |
535 |
> |
|
536 |
> |
sprintf( tempBuffer, |
537 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
538 |
> |
q[0], |
539 |
> |
q[1], |
540 |
> |
q[2], |
541 |
> |
q[3], |
542 |
> |
dAtom->getJx(), |
543 |
> |
dAtom->getJy(), |
544 |
> |
dAtom->getJz()); |
545 |
> |
strcat( writeLine, tempBuffer ); |
546 |
> |
} |
547 |
> |
else{ |
548 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
549 |
> |
} |
550 |
> |
} |
551 |
> |
else { |
552 |
> |
sprintf(painCave.errMsg, |
553 |
> |
"Atom %d not found on processor %d\n", |
554 |
> |
which_atom, worldRank ); |
555 |
> |
myStatus = 0; |
556 |
> |
simError(); |
557 |
> |
|
558 |
> |
strcpy( writeLine, "Hello, I'm an error.\n"); |
559 |
|
} |
560 |
+ |
|
561 |
+ |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
562 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
563 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
564 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
565 |
|
} |
566 |
|
} |
567 |
|
finalOut.flush(); |
568 |
|
sprintf( checkPointMsg, |
569 |
|
"Sucessfully took a dump.\n"); |
570 |
|
MPIcheckPoint(); |
571 |
< |
|
571 |
> |
|
572 |
|
if( worldRank == 0 ) finalOut.close(); |
573 |
|
#endif // is_mpi |
574 |
|
} |
575 |
+ |
|
576 |
+ |
|
577 |
+ |
|
578 |
+ |
#ifdef IS_MPI |
579 |
+ |
|
580 |
+ |
// a couple of functions to let us escape the write loop |
581 |
+ |
|
582 |
+ |
void dWrite::nodeZeroError( void ){ |
583 |
+ |
int j, myStatus; |
584 |
+ |
|
585 |
+ |
myStatus = 0; |
586 |
+ |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
587 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, j, |
588 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
589 |
+ |
} |
590 |
+ |
|
591 |
+ |
|
592 |
+ |
MPI_Finalize(); |
593 |
+ |
exit (0); |
594 |
+ |
|
595 |
+ |
} |
596 |
+ |
|
597 |
+ |
void dWrite::anonymousNodeDie( void ){ |
598 |
+ |
|
599 |
+ |
MPI_Finalize(); |
600 |
+ |
exit (0); |
601 |
+ |
} |
602 |
+ |
|
603 |
+ |
#endif //is_mpi |