| 4 |
|
|
| 5 |
|
#ifdef IS_MPI |
| 6 |
|
#include <mpi.h> |
| 7 |
+ |
#include <mpi++.h> |
| 8 |
|
#include "mpiSimulation.hpp" |
| 9 |
|
#define TAKE_THIS_TAG 0 |
| 10 |
|
#endif //is_mpi |
| 12 |
|
#include "ReadWrite.hpp" |
| 13 |
|
#include "simError.h" |
| 14 |
|
|
| 14 |
– |
#define GAME_OVER -1 |
| 15 |
– |
|
| 15 |
|
DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ |
| 16 |
|
|
| 17 |
|
entry_plug = the_entry_plug; |
| 65 |
|
char tempBuffer[BUFFERSIZE]; |
| 66 |
|
char writeLine[BUFFERSIZE]; |
| 67 |
|
|
| 68 |
< |
int i; |
| 68 |
> |
int i, j, which_node, done, game_over, which_atom, local_index; |
| 69 |
|
double q[4]; |
| 70 |
|
DirectionalAtom* dAtom; |
| 71 |
|
int nAtoms = entry_plug->n_atoms; |
| 119 |
|
outFile.flush(); |
| 120 |
|
|
| 121 |
|
#else // is_mpi |
| 122 |
+ |
|
| 123 |
+ |
MPI::Status istatus; |
| 124 |
+ |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
| 125 |
|
|
| 124 |
– |
MPI_Status istatus[MPI_STATUS_SIZE]; |
| 125 |
– |
|
| 126 |
|
// write out header and node 0's coordinates |
| 127 |
|
|
| 128 |
|
if( worldRank == 0 ){ |
| 133 |
|
<< entry_plug->box_y << "\t" |
| 134 |
|
<< entry_plug->box_z << "\n"; |
| 135 |
|
|
| 136 |
< |
for (i = 0 ; i < mpiPlug->nAtomsGlobal; i++ ) { |
| 137 |
< |
// Get the Node number which has this molecule: |
| 136 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
| 137 |
> |
// Get the Node number which has this atom; |
| 138 |
|
|
| 139 |
|
which_node = AtomToProcMap[i]; |
| 140 |
|
|
| 141 |
< |
if (which_node == mpiPlug->myNode) { |
| 141 |
> |
if (which_node == mpiSim->getMyNode()) { |
| 142 |
|
|
| 143 |
|
sprintf( tempBuffer, |
| 144 |
|
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 173 |
|
} else { |
| 174 |
|
|
| 175 |
|
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG); |
| 176 |
< |
MPI::COMM_WORLD.Receive(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 176 |
> |
MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 177 |
|
TAKE_THIS_TAG, istatus); |
| 178 |
|
} |
| 179 |
|
|
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
// kill everyone off: |
| 184 |
< |
for (j = 0; j < mpiPlug->numberProcessors; j++) { |
| 185 |
< |
MPI::COMM_WORLD.Send(GAME_OVER, 1, MPI_INT, j, TAKE_THIS_TAG); |
| 184 |
> |
game_over = -1; |
| 185 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
| 186 |
> |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG); |
| 187 |
|
} |
| 188 |
|
|
| 189 |
|
} else { |
| 190 |
|
|
| 191 |
|
done = 0; |
| 192 |
|
while (!done) { |
| 193 |
< |
MPI::COMM_WORLD.Receive(&which_atom, 1, MPI_INT, 0, |
| 194 |
< |
TAKE_THIS_TAG, istatus); |
| 195 |
< |
|
| 196 |
< |
if (which_atom == GAME_OVER) { |
| 193 |
> |
MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
| 194 |
> |
TAKE_THIS_TAG, istatus); |
| 195 |
> |
|
| 196 |
> |
if (which_atom == -1) { |
| 197 |
|
done=1; |
| 198 |
|
continue; |
| 199 |
|
} else { |
| 200 |
< |
|
| 201 |
< |
//format the line |
| 202 |
< |
sprintf( tempBuffer, |
| 203 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 204 |
< |
atoms[which_atom]->getType(), |
| 205 |
< |
atoms[which_atom]->getX(), |
| 206 |
< |
atoms[which_atom]->getY(), |
| 207 |
< |
atoms[which_atom]->getZ(), |
| 208 |
< |
atoms[which_atom]->get_vx(), |
| 209 |
< |
atoms[which_atom]->get_vy(), |
| 210 |
< |
atoms[which_atom]->get_vz()); // check here. |
| 211 |
< |
strcpy( writeLine, tempBuffer ); |
| 200 |
> |
local_index=-1; |
| 201 |
> |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
| 202 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 203 |
> |
} |
| 204 |
> |
if (local_index != -1) { |
| 205 |
> |
//format the line |
| 206 |
> |
sprintf( tempBuffer, |
| 207 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 208 |
> |
atoms[local_index]->getType(), |
| 209 |
> |
atoms[local_index]->getX(), |
| 210 |
> |
atoms[local_index]->getY(), |
| 211 |
> |
atoms[local_index]->getZ(), |
| 212 |
> |
atoms[local_index]->get_vx(), |
| 213 |
> |
atoms[local_index]->get_vy(), |
| 214 |
> |
atoms[local_index]->get_vz()); // check here. |
| 215 |
> |
strcpy( writeLine, tempBuffer ); |
| 216 |
|
|
| 217 |
< |
if( atoms[which_atom]->isDirectional() ){ |
| 218 |
< |
|
| 219 |
< |
dAtom = (DirectionalAtom *)atoms[which_atom]; |
| 220 |
< |
dAtom->getQ( q ); |
| 221 |
< |
|
| 222 |
< |
sprintf( tempBuffer, |
| 223 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 224 |
< |
q[0], |
| 225 |
< |
q[1], |
| 226 |
< |
q[2], |
| 227 |
< |
q[3], |
| 228 |
< |
dAtom->getJx(), |
| 229 |
< |
dAtom->getJy(), |
| 230 |
< |
dAtom->getJz()); |
| 231 |
< |
strcat( writeLine, tempBuffer ); |
| 232 |
< |
} |
| 233 |
< |
else |
| 234 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 235 |
< |
|
| 236 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 237 |
< |
TAKE_THIS_TAG); |
| 217 |
> |
if( atoms[local_index]->isDirectional() ){ |
| 218 |
> |
|
| 219 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 220 |
> |
dAtom->getQ( q ); |
| 221 |
> |
|
| 222 |
> |
sprintf( tempBuffer, |
| 223 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 224 |
> |
q[0], |
| 225 |
> |
q[1], |
| 226 |
> |
q[2], |
| 227 |
> |
q[3], |
| 228 |
> |
dAtom->getJx(), |
| 229 |
> |
dAtom->getJy(), |
| 230 |
> |
dAtom->getJz()); |
| 231 |
> |
strcat( writeLine, tempBuffer ); |
| 232 |
> |
} |
| 233 |
> |
else |
| 234 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 235 |
> |
|
| 236 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 237 |
> |
TAKE_THIS_TAG); |
| 238 |
> |
} else { |
| 239 |
> |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
| 240 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 241 |
> |
TAKE_THIS_TAG); |
| 242 |
> |
} |
| 243 |
|
} |
| 244 |
|
} |
| 245 |
|
} |
| 251 |
|
} |
| 252 |
|
|
| 253 |
|
void DumpWriter::writeFinal(){ |
| 254 |
< |
|
| 254 |
> |
|
| 255 |
|
char finalName[500]; |
| 256 |
|
ofstream finalOut; |
| 257 |
+ |
|
| 258 |
+ |
const int BUFFERSIZE = 2000; |
| 259 |
+ |
char tempBuffer[BUFFERSIZE]; |
| 260 |
+ |
char writeLine[BUFFERSIZE]; |
| 261 |
+ |
|
| 262 |
+ |
double q[4]; |
| 263 |
+ |
DirectionalAtom* dAtom; |
| 264 |
+ |
int nAtoms = entry_plug->n_atoms; |
| 265 |
+ |
Atom** atoms = entry_plug->atoms; |
| 266 |
+ |
int i, j, which_node, done, game_over, which_atom, local_index; |
| 267 |
|
|
| 268 |
+ |
|
| 269 |
|
#ifdef IS_MPI |
| 270 |
|
if(worldRank == 0 ){ |
| 271 |
|
#endif // is_mpi |
| 299 |
|
finalOut << entry_plug->box_x << "\t" |
| 300 |
|
<< entry_plug->box_y << "\t" |
| 301 |
|
<< entry_plug->box_z << "\n"; |
| 302 |
< |
|
| 302 |
> |
|
| 303 |
|
for( i=0; i<nAtoms; i++ ){ |
| 304 |
|
|
| 305 |
|
sprintf( tempBuffer, |
| 339 |
|
|
| 340 |
|
#else // is_mpi |
| 341 |
|
|
| 342 |
< |
MPI_Status istatus[MPI_STATUS_SIZE]; |
| 343 |
< |
|
| 342 |
> |
MPI::Status istatus; |
| 343 |
> |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
| 344 |
> |
|
| 345 |
|
// write out header and node 0's coordinates |
| 346 |
|
|
| 347 |
|
if( worldRank == 0 ){ |
| 351 |
|
<< entry_plug->box_y << "\t" |
| 352 |
|
<< entry_plug->box_z << "\n"; |
| 353 |
|
|
| 354 |
< |
for (i = 0 ; i < mpiPlug->nAtomsGlobal; i++ ) { |
| 354 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
| 355 |
|
// Get the Node number which has this molecule: |
| 356 |
|
|
| 357 |
|
which_node = AtomToProcMap[i]; |
| 358 |
|
|
| 359 |
< |
if (which_node == mpiPlug->myNode) { |
| 359 |
> |
if (which_node == mpiSim->getMyNode()) { |
| 360 |
|
|
| 361 |
|
sprintf( tempBuffer, |
| 362 |
|
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 391 |
|
} else { |
| 392 |
|
|
| 393 |
|
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG); |
| 394 |
< |
MPI::COMM_WORLD.Receive(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 394 |
> |
MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 395 |
|
TAKE_THIS_TAG, istatus); |
| 396 |
|
} |
| 397 |
|
|
| 399 |
|
} |
| 400 |
|
|
| 401 |
|
// kill everyone off: |
| 402 |
< |
for (j = 0; j < mpiPlug->numberProcessors; j++) { |
| 403 |
< |
MPI::COMM_WORLD.Send(GAME_OVER, 1, MPI_INT, j, TAKE_THIS_TAG); |
| 402 |
> |
game_over = -1; |
| 403 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
| 404 |
> |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG); |
| 405 |
|
} |
| 406 |
|
|
| 407 |
|
} else { |
| 408 |
|
|
| 409 |
|
done = 0; |
| 410 |
|
while (!done) { |
| 411 |
< |
MPI::COMM_WORLD.Receive(&which_atom, 1, MPI_INT, 0, |
| 412 |
< |
TAKE_THIS_TAG, istatus); |
| 411 |
> |
MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
| 412 |
> |
TAKE_THIS_TAG, istatus); |
| 413 |
|
|
| 414 |
< |
if (which_atom == GAME_OVER) { |
| 414 |
> |
if (which_atom == -1) { |
| 415 |
|
done=1; |
| 416 |
|
continue; |
| 417 |
|
} else { |
| 418 |
|
|
| 419 |
< |
//format the line |
| 420 |
< |
sprintf( tempBuffer, |
| 421 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 422 |
< |
atoms[which_atom]->getType(), |
| 423 |
< |
atoms[which_atom]->getX(), |
| 424 |
< |
atoms[which_atom]->getY(), |
| 425 |
< |
atoms[which_atom]->getZ(), |
| 426 |
< |
atoms[which_atom]->get_vx(), |
| 427 |
< |
atoms[which_atom]->get_vy(), |
| 428 |
< |
atoms[which_atom]->get_vz()); // check here. |
| 429 |
< |
strcpy( writeLine, tempBuffer ); |
| 419 |
> |
local_index=-1; |
| 420 |
> |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
| 421 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 422 |
> |
} |
| 423 |
> |
if (local_index != -1) { |
| 424 |
> |
|
| 425 |
> |
//format the line |
| 426 |
> |
sprintf( tempBuffer, |
| 427 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 428 |
> |
atoms[local_index]->getType(), |
| 429 |
> |
atoms[local_index]->getX(), |
| 430 |
> |
atoms[local_index]->getY(), |
| 431 |
> |
atoms[local_index]->getZ(), |
| 432 |
> |
atoms[local_index]->get_vx(), |
| 433 |
> |
atoms[local_index]->get_vy(), |
| 434 |
> |
atoms[local_index]->get_vz()); // check here. |
| 435 |
> |
strcpy( writeLine, tempBuffer ); |
| 436 |
|
|
| 437 |
< |
if( atoms[which_atom]->isDirectional() ){ |
| 437 |
> |
if( atoms[local_index]->isDirectional() ){ |
| 438 |
> |
|
| 439 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 440 |
> |
dAtom->getQ( q ); |
| 441 |
|
|
| 442 |
< |
dAtom = (DirectionalAtom *)atoms[which_atom]; |
| 443 |
< |
dAtom->getQ( q ); |
| 444 |
< |
|
| 445 |
< |
sprintf( tempBuffer, |
| 446 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 447 |
< |
q[0], |
| 448 |
< |
q[1], |
| 449 |
< |
q[2], |
| 450 |
< |
q[3], |
| 451 |
< |
dAtom->getJx(), |
| 452 |
< |
dAtom->getJy(), |
| 453 |
< |
dAtom->getJz()); |
| 454 |
< |
strcat( writeLine, tempBuffer ); |
| 455 |
< |
} |
| 456 |
< |
else |
| 457 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 458 |
< |
|
| 459 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 460 |
< |
TAKE_THIS_TAG); |
| 442 |
> |
sprintf( tempBuffer, |
| 443 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 444 |
> |
q[0], |
| 445 |
> |
q[1], |
| 446 |
> |
q[2], |
| 447 |
> |
q[3], |
| 448 |
> |
dAtom->getJx(), |
| 449 |
> |
dAtom->getJy(), |
| 450 |
> |
dAtom->getJz()); |
| 451 |
> |
strcat( writeLine, tempBuffer ); |
| 452 |
> |
} |
| 453 |
> |
else |
| 454 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 455 |
> |
|
| 456 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 457 |
> |
TAKE_THIS_TAG); |
| 458 |
> |
} else { |
| 459 |
> |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
| 460 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 461 |
> |
TAKE_THIS_TAG); |
| 462 |
> |
} |
| 463 |
|
} |
| 464 |
|
} |
| 465 |
< |
} |
| 465 |
> |
} |
| 466 |
|
finalOut.flush(); |
| 467 |
|
sprintf( checkPointMsg, |
| 468 |
|
"Sucessfully took a dump.\n"); |