| 7 |
|
#ifdef IS_MPI |
| 8 |
|
#include <mpi.h> |
| 9 |
|
#include "mpiSimulation.hpp" |
| 10 |
– |
#define TAKE_THIS_TAG_CHAR 15 |
| 11 |
– |
#define TAKE_THIS_TAG_INT 20 |
| 10 |
|
|
| 11 |
|
namespace dWrite{ |
| 12 |
< |
void nodeZeroError( void ); |
| 15 |
< |
void anonymousNodeDie( void ); |
| 12 |
> |
void DieDieDie( void ); |
| 13 |
|
} |
| 14 |
|
|
| 15 |
|
using namespace dWrite; |
| 66 |
|
void DumpWriter::writeDump( double currentTime ){ |
| 67 |
|
|
| 68 |
|
const int BUFFERSIZE = 2000; |
| 69 |
+ |
const int MINIBUFFERSIZE = 10; |
| 70 |
+ |
|
| 71 |
|
char tempBuffer[BUFFERSIZE]; |
| 72 |
|
char writeLine[BUFFERSIZE]; |
| 73 |
|
|
| 74 |
|
int i; |
| 75 |
|
#ifdef IS_MPI |
| 76 |
|
int j, which_node, done, which_atom, local_index; |
| 77 |
+ |
double atomTransData[6]; |
| 78 |
+ |
double atomOrientData[7]; |
| 79 |
+ |
int isDirectional; |
| 80 |
+ |
char* atomTypeString; |
| 81 |
+ |
int me; |
| 82 |
+ |
int atomTypeTag; |
| 83 |
+ |
int atomIsDirectionalTag; |
| 84 |
+ |
int atomTransDataTag; |
| 85 |
+ |
int atomOrientDataTag; |
| 86 |
|
#else //is_mpi |
| 87 |
|
int nAtoms = entry_plug->n_atoms; |
| 88 |
|
#endif //is_mpi |
| 92 |
|
Atom** atoms = entry_plug->atoms; |
| 93 |
|
double pos[3], vel[3]; |
| 94 |
|
|
| 87 |
– |
|
| 95 |
|
// write current frame to the eor file |
| 96 |
|
|
| 97 |
|
this->writeFinal( currentTime ); |
| 192 |
|
|
| 193 |
|
which_node = AtomToProcMap[i]; |
| 194 |
|
|
| 195 |
< |
if (which_node == 0 ) { |
| 195 |
> |
if (which_node != 0) { |
| 196 |
> |
|
| 197 |
> |
atomTypeTag = 4*i; |
| 198 |
> |
atomIsDirectionalTag = 4*i + 1; |
| 199 |
> |
atomTransDataTag = 4*i + 2; |
| 200 |
> |
atomOrientDataTag = 4*i + 3; |
| 201 |
|
|
| 202 |
+ |
MPI_Recv(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
| 203 |
+ |
atomTypeTag, MPI_COMM_WORLD, &istatus); |
| 204 |
+ |
|
| 205 |
+ |
MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
| 206 |
+ |
atomIsDirectionalTag, MPI_COMM_WORLD, &istatus); |
| 207 |
+ |
|
| 208 |
+ |
MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node, |
| 209 |
+ |
atomTransDataTag, MPI_COMM_WORLD, &istatus); |
| 210 |
+ |
|
| 211 |
+ |
if (isDirectional) { |
| 212 |
+ |
|
| 213 |
+ |
MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node, |
| 214 |
+ |
atomOrientDataTag, MPI_COMM_WORLD, &istatus); |
| 215 |
+ |
|
| 216 |
+ |
} |
| 217 |
+ |
|
| 218 |
+ |
} else { |
| 219 |
+ |
|
| 220 |
|
haveError = 0; |
| 221 |
|
which_atom = i; |
| 222 |
|
local_index=-1; |
| 223 |
+ |
|
| 224 |
|
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
| 225 |
|
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 226 |
|
} |
| 227 |
+ |
|
| 228 |
|
if (local_index != -1) { |
| 197 |
– |
//format the line |
| 229 |
|
|
| 230 |
+ |
atomTypeString = atoms[local_index]->getType(); |
| 231 |
+ |
|
| 232 |
|
atoms[local_index]->getPos(pos); |
| 233 |
|
atoms[local_index]->getVel(vel); |
| 234 |
|
|
| 235 |
< |
sprintf( tempBuffer, |
| 236 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 237 |
< |
atoms[local_index]->getType(), |
| 205 |
< |
pos[0], |
| 206 |
< |
pos[1], |
| 207 |
< |
pos[2], |
| 208 |
< |
vel[0], |
| 209 |
< |
vel[1], |
| 210 |
< |
vel[2]); // check here. |
| 211 |
< |
strcpy( writeLine, tempBuffer ); |
| 235 |
> |
atomTransData[0] = pos[0]; |
| 236 |
> |
atomTransData[1] = pos[1]; |
| 237 |
> |
atomTransData[2] = pos[2]; |
| 238 |
|
|
| 239 |
+ |
atomTransData[3] = vel[0]; |
| 240 |
+ |
atomTransData[4] = vel[1]; |
| 241 |
+ |
atomTransData[5] = vel[2]; |
| 242 |
+ |
|
| 243 |
+ |
isDirectional = 0; |
| 244 |
+ |
|
| 245 |
|
if( atoms[local_index]->isDirectional() ){ |
| 246 |
|
|
| 247 |
+ |
isDirectional = 1; |
| 248 |
+ |
|
| 249 |
|
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 250 |
|
dAtom->getQ( q ); |
| 251 |
+ |
|
| 252 |
+ |
atomOrientData[0] = q[0]; |
| 253 |
+ |
atomOrientData[1] = q[1]; |
| 254 |
+ |
atomOrientData[2] = q[2]; |
| 255 |
+ |
atomOrientData[3] = q[3]; |
| 256 |
|
|
| 257 |
< |
sprintf( tempBuffer, |
| 258 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 259 |
< |
q[0], |
| 260 |
< |
q[1], |
| 222 |
< |
q[2], |
| 223 |
< |
q[3], |
| 224 |
< |
dAtom->getJx(), |
| 225 |
< |
dAtom->getJy(), |
| 226 |
< |
dAtom->getJz()); |
| 227 |
< |
strcat( writeLine, tempBuffer ); |
| 257 |
> |
atomOrientData[4] = dAtom->getJx(); |
| 258 |
> |
atomOrientData[5] = dAtom->getJy(); |
| 259 |
> |
atomOrientData[6] = dAtom->getJz(); |
| 260 |
> |
} |
| 261 |
|
|
| 262 |
< |
} |
| 230 |
< |
else |
| 231 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 232 |
< |
} |
| 233 |
< |
else { |
| 262 |
> |
} else { |
| 263 |
|
sprintf(painCave.errMsg, |
| 264 |
|
"Atom %d not found on processor %d\n", |
| 265 |
|
i, worldRank ); |
| 267 |
|
simError(); |
| 268 |
|
} |
| 269 |
|
|
| 270 |
< |
if(haveError) nodeZeroError(); |
| 270 |
> |
if(haveError) DieDieDie(); |
| 271 |
> |
|
| 272 |
> |
// If we've survived to here, format the line: |
| 273 |
> |
|
| 274 |
> |
sprintf( tempBuffer, |
| 275 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 276 |
> |
atomTypeString, |
| 277 |
> |
atomTransData[0], |
| 278 |
> |
atomTransData[1], |
| 279 |
> |
atomTransData[2], |
| 280 |
> |
atomTransData[3], |
| 281 |
> |
atomTransData[4], |
| 282 |
> |
atomTransData[5]); |
| 283 |
|
|
| 284 |
< |
} |
| 244 |
< |
else { |
| 245 |
< |
myStatus = 1; |
| 246 |
< |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
| 247 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 248 |
< |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
| 249 |
< |
MPI_COMM_WORLD); |
| 250 |
< |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 251 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
| 252 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
| 253 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 284 |
> |
strcpy( writeLine, tempBuffer ); |
| 285 |
|
|
| 286 |
< |
if(!myStatus) nodeZeroError(); |
| 286 |
> |
if (isDirectional) { |
| 287 |
|
|
| 288 |
< |
} |
| 288 |
> |
sprintf( tempBuffer, |
| 289 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 290 |
> |
atomOrientData[0], |
| 291 |
> |
atomOrientData[1], |
| 292 |
> |
atomOrientData[2], |
| 293 |
> |
atomOrientData[3], |
| 294 |
> |
atomOrientData[4], |
| 295 |
> |
atomOrientData[5], |
| 296 |
> |
atomOrientData[6]); |
| 297 |
> |
strcat( writeLine, tempBuffer ); |
| 298 |
|
|
| 299 |
< |
outFile << writeLine; |
| 300 |
< |
outFile.flush(); |
| 301 |
< |
} |
| 299 |
> |
} else { |
| 300 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 301 |
> |
} |
| 302 |
|
|
| 303 |
< |
// kill everyone off: |
| 304 |
< |
myStatus = -1; |
| 305 |
< |
for (j = 1; j < mpiSim->getNumberProcessors(); j++) { |
| 266 |
< |
MPI_Send(&myStatus, 1, MPI_INT, j, |
| 267 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 303 |
> |
outFile << writeLine; |
| 304 |
> |
outFile.flush(); |
| 305 |
> |
} |
| 306 |
|
} |
| 307 |
|
|
| 308 |
+ |
outFile.flush(); |
| 309 |
+ |
sprintf( checkPointMsg, |
| 310 |
+ |
"Sucessfully took a dump.\n"); |
| 311 |
+ |
MPIcheckPoint(); |
| 312 |
+ |
|
| 313 |
|
} else { |
| 314 |
|
|
| 315 |
< |
done = 0; |
| 316 |
< |
while (!done) { |
| 315 |
> |
// worldRank != 0, so I'm a remote node. |
| 316 |
> |
|
| 317 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
| 318 |
> |
|
| 319 |
> |
// Am I the node which has this atom? |
| 320 |
> |
|
| 321 |
> |
if (AtomToProcMap[i] == worldRank) { |
| 322 |
|
|
| 323 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
| 324 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 323 |
> |
local_index=-1; |
| 324 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
| 325 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 326 |
> |
} |
| 327 |
> |
if (local_index != -1) { |
| 328 |
> |
|
| 329 |
> |
atomTypeString = atoms[local_index]->getType(); |
| 330 |
|
|
| 331 |
< |
if(!myStatus) anonymousNodeDie(); |
| 332 |
< |
|
| 280 |
< |
if(myStatus < 0) break; |
| 331 |
> |
atoms[local_index]->getPos(pos); |
| 332 |
> |
atoms[local_index]->getVel(vel); |
| 333 |
|
|
| 334 |
< |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
| 335 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 334 |
> |
atomTransData[0] = pos[0]; |
| 335 |
> |
atomTransData[1] = pos[1]; |
| 336 |
> |
atomTransData[2] = pos[2]; |
| 337 |
|
|
| 338 |
< |
myStatus = 1; |
| 339 |
< |
local_index=-1; |
| 340 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
| 341 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 342 |
< |
} |
| 290 |
< |
if (local_index != -1) { |
| 291 |
< |
//format the line |
| 338 |
> |
atomTransData[3] = vel[0]; |
| 339 |
> |
atomTransData[4] = vel[1]; |
| 340 |
> |
atomTransData[5] = vel[2]; |
| 341 |
> |
|
| 342 |
> |
isDirectional = 0; |
| 343 |
|
|
| 344 |
< |
atoms[local_index]->getPos(pos); |
| 294 |
< |
atoms[local_index]->getVel(vel); |
| 344 |
> |
if( atoms[local_index]->isDirectional() ){ |
| 345 |
|
|
| 346 |
< |
sprintf( tempBuffer, |
| 347 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 348 |
< |
atoms[local_index]->getType(), |
| 349 |
< |
pos[0], |
| 350 |
< |
pos[1], |
| 351 |
< |
pos[2], |
| 352 |
< |
vel[0], |
| 353 |
< |
vel[1], |
| 354 |
< |
vel[2]); // check here. |
| 305 |
< |
strcpy( writeLine, tempBuffer ); |
| 346 |
> |
isDirectional = 1; |
| 347 |
> |
|
| 348 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 349 |
> |
dAtom->getQ( q ); |
| 350 |
> |
|
| 351 |
> |
atomOrientData[0] = q[0]; |
| 352 |
> |
atomOrientData[1] = q[1]; |
| 353 |
> |
atomOrientData[2] = q[2]; |
| 354 |
> |
atomOrientData[3] = q[3]; |
| 355 |
|
|
| 356 |
< |
if( atoms[local_index]->isDirectional() ){ |
| 356 |
> |
atomOrientData[4] = dAtom->getJx(); |
| 357 |
> |
atomOrientData[5] = dAtom->getJy(); |
| 358 |
> |
atomOrientData[6] = dAtom->getJz(); |
| 359 |
> |
} |
| 360 |
|
|
| 361 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 362 |
< |
dAtom->getQ( q ); |
| 363 |
< |
|
| 364 |
< |
sprintf( tempBuffer, |
| 365 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 366 |
< |
q[0], |
| 315 |
< |
q[1], |
| 316 |
< |
q[2], |
| 317 |
< |
q[3], |
| 318 |
< |
dAtom->getJx(), |
| 319 |
< |
dAtom->getJy(), |
| 320 |
< |
dAtom->getJz()); |
| 321 |
< |
strcat( writeLine, tempBuffer ); |
| 361 |
> |
} else { |
| 362 |
> |
sprintf(painCave.errMsg, |
| 363 |
> |
"Atom %d not found on processor %d\n", |
| 364 |
> |
i, worldRank ); |
| 365 |
> |
haveError= 1; |
| 366 |
> |
simError(); |
| 367 |
|
} |
| 323 |
– |
else{ |
| 324 |
– |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 325 |
– |
} |
| 326 |
– |
} |
| 327 |
– |
else { |
| 328 |
– |
sprintf(painCave.errMsg, |
| 329 |
– |
"Atom %d not found on processor %d\n", |
| 330 |
– |
which_atom, worldRank ); |
| 331 |
– |
myStatus = 0; |
| 332 |
– |
simError(); |
| 368 |
|
|
| 369 |
< |
strcpy( writeLine, "Hello, I'm an error.\n"); |
| 335 |
< |
} |
| 369 |
> |
// I've survived this far, so send off the data! |
| 370 |
|
|
| 371 |
< |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 372 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
| 373 |
< |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
| 374 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 371 |
> |
atomTypeTag = 4*i; |
| 372 |
> |
atomIsDirectionalTag = 4*i + 1; |
| 373 |
> |
atomTransDataTag = 4*i + 2; |
| 374 |
> |
atomOrientDataTag = 4*i + 3; |
| 375 |
> |
|
| 376 |
> |
MPI_Send(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
| 377 |
> |
atomTypeTag, MPI_COMM_WORLD); |
| 378 |
> |
|
| 379 |
> |
MPI_Send(&isDirectional, 1, MPI_INT, 0, |
| 380 |
> |
atomIsDirectionalTag, MPI_COMM_WORLD); |
| 381 |
> |
|
| 382 |
> |
MPI_Send(atomTransData, 6, MPI_DOUBLE, 0, |
| 383 |
> |
atomTransDataTag, MPI_COMM_WORLD); |
| 384 |
> |
|
| 385 |
> |
if (isDirectional) { |
| 386 |
> |
|
| 387 |
> |
MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0, |
| 388 |
> |
atomOrientDataTag, MPI_COMM_WORLD); |
| 389 |
> |
|
| 390 |
> |
} |
| 391 |
> |
|
| 392 |
> |
} |
| 393 |
|
} |
| 342 |
– |
} |
| 343 |
– |
outFile.flush(); |
| 344 |
– |
sprintf( checkPointMsg, |
| 345 |
– |
"Sucessfully took a dump.\n"); |
| 346 |
– |
MPIcheckPoint(); |
| 394 |
|
|
| 395 |
< |
// last thing last, enable fatalities. |
| 395 |
> |
sprintf( checkPointMsg, |
| 396 |
> |
"Sucessfully took a dump.\n"); |
| 397 |
> |
MPIcheckPoint(); |
| 398 |
> |
|
| 399 |
> |
} |
| 400 |
> |
|
| 401 |
|
painCave.isEventLoop = 0; |
| 402 |
|
|
| 403 |
|
#endif // is_mpi |
| 409 |
|
ofstream finalOut; |
| 410 |
|
|
| 411 |
|
const int BUFFERSIZE = 2000; |
| 412 |
+ |
const int MINIBUFFERSIZE = 10; |
| 413 |
|
char tempBuffer[BUFFERSIZE]; |
| 414 |
|
char writeLine[BUFFERSIZE]; |
| 415 |
|
|
| 419 |
|
int i; |
| 420 |
|
#ifdef IS_MPI |
| 421 |
|
int j, which_node, done, which_atom, local_index; |
| 422 |
+ |
double atomTransData[6]; |
| 423 |
+ |
double atomOrientData[7]; |
| 424 |
+ |
int isDirectional; |
| 425 |
+ |
char* atomTypeString; |
| 426 |
+ |
int atomTypeTag; |
| 427 |
+ |
int atomIsDirectionalTag; |
| 428 |
+ |
int atomTransDataTag; |
| 429 |
+ |
int atomOrientDataTag; |
| 430 |
|
#else //is_mpi |
| 431 |
|
int nAtoms = entry_plug->n_atoms; |
| 432 |
|
#endif //is_mpi |
| 533 |
|
|
| 534 |
|
// write out header and node 0's coordinates |
| 535 |
|
|
| 475 |
– |
haveError = 0; |
| 536 |
|
if( worldRank == 0 ){ |
| 537 |
|
finalOut << mpiSim->getTotAtoms() << "\n"; |
| 538 |
|
|
| 539 |
|
finalOut << finalTime << ";\t" |
| 540 |
< |
<< entry_plug->Hmat[0][0] << "\t" |
| 541 |
< |
<< entry_plug->Hmat[1][0] << "\t" |
| 542 |
< |
<< entry_plug->Hmat[2][0] << ";\t" |
| 540 |
> |
<< entry_plug->Hmat[0][0] << "\t" |
| 541 |
> |
<< entry_plug->Hmat[1][0] << "\t" |
| 542 |
> |
<< entry_plug->Hmat[2][0] << ";\t" |
| 543 |
|
|
| 544 |
< |
<< entry_plug->Hmat[0][1] << "\t" |
| 545 |
< |
<< entry_plug->Hmat[1][1] << "\t" |
| 546 |
< |
<< entry_plug->Hmat[2][1] << ";\t" |
| 544 |
> |
<< entry_plug->Hmat[0][1] << "\t" |
| 545 |
> |
<< entry_plug->Hmat[1][1] << "\t" |
| 546 |
> |
<< entry_plug->Hmat[2][1] << ";\t" |
| 547 |
|
|
| 548 |
< |
<< entry_plug->Hmat[0][2] << "\t" |
| 549 |
< |
<< entry_plug->Hmat[1][2] << "\t" |
| 550 |
< |
<< entry_plug->Hmat[2][2] << ";"; |
| 548 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
| 549 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
| 550 |
> |
<< entry_plug->Hmat[2][2] << ";"; |
| 551 |
|
|
| 492 |
– |
//write out additional parameters, such as chi and eta |
| 552 |
|
finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
| 553 |
|
finalOut << endl; |
| 554 |
< |
|
| 554 |
> |
finalOut.flush(); |
| 555 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
| 556 |
< |
// Get the Node number which has this molecule: |
| 556 |
> |
// Get the Node number which has this atom; |
| 557 |
|
|
| 558 |
|
which_node = AtomToProcMap[i]; |
| 559 |
|
|
| 560 |
< |
if (which_node == mpiSim->getMyNode()) { |
| 560 |
> |
if (which_node != 0) { |
| 561 |
> |
|
| 562 |
> |
atomTypeTag = 4*i; |
| 563 |
> |
atomIsDirectionalTag = 4*i + 1; |
| 564 |
> |
atomTransDataTag = 4*i + 2; |
| 565 |
> |
atomOrientDataTag = 4*i + 3; |
| 566 |
|
|
| 567 |
+ |
MPI_Recv(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
| 568 |
+ |
atomTypeTag, MPI_COMM_WORLD, &istatus); |
| 569 |
+ |
|
| 570 |
+ |
MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
| 571 |
+ |
atomIsDirectionalTag, MPI_COMM_WORLD, &istatus); |
| 572 |
+ |
|
| 573 |
+ |
MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node, |
| 574 |
+ |
atomTransDataTag, MPI_COMM_WORLD, &istatus); |
| 575 |
+ |
|
| 576 |
+ |
if (isDirectional) { |
| 577 |
+ |
|
| 578 |
+ |
MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node, |
| 579 |
+ |
atomOrientDataTag, MPI_COMM_WORLD, &istatus); |
| 580 |
+ |
|
| 581 |
+ |
} |
| 582 |
+ |
|
| 583 |
+ |
} else { |
| 584 |
+ |
|
| 585 |
+ |
haveError = 0; |
| 586 |
|
which_atom = i; |
| 587 |
|
local_index=-1; |
| 588 |
+ |
|
| 589 |
|
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
| 590 |
|
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 591 |
|
} |
| 592 |
+ |
|
| 593 |
|
if (local_index != -1) { |
| 594 |
|
|
| 595 |
+ |
atomTypeString = atoms[local_index]->getType(); |
| 596 |
+ |
|
| 597 |
|
atoms[local_index]->getPos(pos); |
| 598 |
|
atoms[local_index]->getVel(vel); |
| 599 |
|
|
| 600 |
< |
sprintf( tempBuffer, |
| 601 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 602 |
< |
atoms[local_index]->getType(), |
| 516 |
< |
pos[0], |
| 517 |
< |
pos[1], |
| 518 |
< |
pos[2], |
| 519 |
< |
vel[0], |
| 520 |
< |
vel[1], |
| 521 |
< |
vel[2]); |
| 522 |
< |
strcpy( writeLine, tempBuffer ); |
| 600 |
> |
atomTransData[0] = pos[0]; |
| 601 |
> |
atomTransData[1] = pos[1]; |
| 602 |
> |
atomTransData[2] = pos[2]; |
| 603 |
|
|
| 604 |
< |
if( atoms[local_index]->isDirectional() ){ |
| 604 |
> |
atomTransData[3] = vel[0]; |
| 605 |
> |
atomTransData[4] = vel[1]; |
| 606 |
> |
atomTransData[5] = vel[2]; |
| 607 |
> |
|
| 608 |
> |
isDirectional = 0; |
| 609 |
|
|
| 610 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 527 |
< |
dAtom->getQ( q ); |
| 610 |
> |
if( atoms[local_index]->isDirectional() ){ |
| 611 |
|
|
| 612 |
< |
sprintf( tempBuffer, |
| 613 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 614 |
< |
q[0], |
| 615 |
< |
q[1], |
| 616 |
< |
q[2], |
| 617 |
< |
q[3], |
| 618 |
< |
dAtom->getJx(), |
| 619 |
< |
dAtom->getJy(), |
| 620 |
< |
dAtom->getJz()); |
| 621 |
< |
strcat( writeLine, tempBuffer ); |
| 622 |
< |
} |
| 623 |
< |
else |
| 624 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 625 |
< |
} |
| 626 |
< |
else { |
| 612 |
> |
isDirectional = 1; |
| 613 |
> |
|
| 614 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 615 |
> |
dAtom->getQ( q ); |
| 616 |
> |
|
| 617 |
> |
atomOrientData[0] = q[0]; |
| 618 |
> |
atomOrientData[1] = q[1]; |
| 619 |
> |
atomOrientData[2] = q[2]; |
| 620 |
> |
atomOrientData[3] = q[3]; |
| 621 |
> |
|
| 622 |
> |
atomOrientData[4] = dAtom->getJx(); |
| 623 |
> |
atomOrientData[5] = dAtom->getJy(); |
| 624 |
> |
atomOrientData[6] = dAtom->getJz(); |
| 625 |
> |
} |
| 626 |
> |
|
| 627 |
> |
} else { |
| 628 |
|
sprintf(painCave.errMsg, |
| 629 |
|
"Atom %d not found on processor %d\n", |
| 630 |
|
i, worldRank ); |
| 632 |
|
simError(); |
| 633 |
|
} |
| 634 |
|
|
| 635 |
< |
if(haveError) nodeZeroError(); |
| 635 |
> |
if(haveError) DieDieDie(); |
| 636 |
> |
|
| 637 |
> |
// If we've survived to here, format the line: |
| 638 |
> |
|
| 639 |
> |
sprintf( tempBuffer, |
| 640 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 641 |
> |
atomTypeString, |
| 642 |
> |
atomTransData[0], |
| 643 |
> |
atomTransData[1], |
| 644 |
> |
atomTransData[2], |
| 645 |
> |
atomTransData[3], |
| 646 |
> |
atomTransData[4], |
| 647 |
> |
atomTransData[5]); |
| 648 |
|
|
| 649 |
< |
} |
| 554 |
< |
else { |
| 649 |
> |
strcpy( writeLine, tempBuffer ); |
| 650 |
|
|
| 651 |
< |
myStatus = 1; |
| 557 |
< |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
| 558 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 559 |
< |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
| 560 |
< |
MPI_COMM_WORLD); |
| 561 |
< |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 562 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
| 563 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
| 564 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 651 |
> |
if (isDirectional) { |
| 652 |
|
|
| 653 |
< |
if(!myStatus) nodeZeroError(); |
| 654 |
< |
} |
| 653 |
> |
sprintf( tempBuffer, |
| 654 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 655 |
> |
atomOrientData[0], |
| 656 |
> |
atomOrientData[1], |
| 657 |
> |
atomOrientData[2], |
| 658 |
> |
atomOrientData[3], |
| 659 |
> |
atomOrientData[4], |
| 660 |
> |
atomOrientData[5], |
| 661 |
> |
atomOrientData[6]); |
| 662 |
> |
strcat( writeLine, tempBuffer ); |
| 663 |
|
|
| 664 |
< |
finalOut << writeLine; |
| 665 |
< |
} |
| 664 |
> |
} else { |
| 665 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 666 |
> |
} |
| 667 |
|
|
| 668 |
< |
// kill everyone off: |
| 669 |
< |
myStatus = -1; |
| 670 |
< |
for (j = 1; j < mpiSim->getNumberProcessors(); j++) { |
| 575 |
< |
MPI_Send(&myStatus, 1, MPI_INT, j, |
| 576 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 668 |
> |
finalOut << writeLine; |
| 669 |
> |
finalOut.flush(); |
| 670 |
> |
} |
| 671 |
|
} |
| 672 |
|
|
| 673 |
+ |
finalOut.flush(); |
| 674 |
+ |
sprintf( checkPointMsg, |
| 675 |
+ |
"Sucessfully took a dump.\n"); |
| 676 |
+ |
MPIcheckPoint(); |
| 677 |
+ |
|
| 678 |
|
} else { |
| 679 |
|
|
| 680 |
< |
done = 0; |
| 681 |
< |
while (!done) { |
| 680 |
> |
// worldRank != 0, so I'm a remote node. |
| 681 |
> |
|
| 682 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
| 683 |
> |
|
| 684 |
> |
// Am I the node which has this atom? |
| 685 |
> |
|
| 686 |
> |
if (AtomToProcMap[i] == worldRank) { |
| 687 |
|
|
| 688 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
| 689 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 688 |
> |
local_index=-1; |
| 689 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
| 690 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 691 |
> |
} |
| 692 |
> |
if (local_index != -1) { |
| 693 |
> |
|
| 694 |
> |
atomTypeString = atoms[local_index]->getType(); |
| 695 |
|
|
| 696 |
< |
if(!myStatus) anonymousNodeDie(); |
| 696 |
> |
atoms[local_index]->getPos(pos); |
| 697 |
> |
atoms[local_index]->getVel(vel); |
| 698 |
|
|
| 699 |
< |
if(myStatus < 0) break; |
| 699 |
> |
atomTransData[0] = pos[0]; |
| 700 |
> |
atomTransData[1] = pos[1]; |
| 701 |
> |
atomTransData[2] = pos[2]; |
| 702 |
|
|
| 703 |
< |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
| 704 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 703 |
> |
atomTransData[3] = vel[0]; |
| 704 |
> |
atomTransData[4] = vel[1]; |
| 705 |
> |
atomTransData[5] = vel[2]; |
| 706 |
> |
|
| 707 |
> |
isDirectional = 0; |
| 708 |
|
|
| 709 |
< |
myStatus = 1; |
| 595 |
< |
local_index=-1; |
| 596 |
< |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
| 597 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 598 |
< |
} |
| 599 |
< |
if (local_index != -1) { |
| 709 |
> |
if( atoms[local_index]->isDirectional() ){ |
| 710 |
|
|
| 711 |
< |
atoms[local_index]->getPos(pos); |
| 712 |
< |
atoms[local_index]->getVel(vel); |
| 711 |
> |
isDirectional = 1; |
| 712 |
> |
|
| 713 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 714 |
> |
dAtom->getQ( q ); |
| 715 |
> |
|
| 716 |
> |
atomOrientData[0] = q[0]; |
| 717 |
> |
atomOrientData[1] = q[1]; |
| 718 |
> |
atomOrientData[2] = q[2]; |
| 719 |
> |
atomOrientData[3] = q[3]; |
| 720 |
|
|
| 721 |
< |
//format the line |
| 722 |
< |
sprintf( tempBuffer, |
| 723 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 724 |
< |
atoms[local_index]->getType(), |
| 608 |
< |
pos[0], |
| 609 |
< |
pos[1], |
| 610 |
< |
pos[2], |
| 611 |
< |
vel[0], |
| 612 |
< |
vel[1], |
| 613 |
< |
vel[2]); // check here. |
| 614 |
< |
strcpy( writeLine, tempBuffer ); |
| 721 |
> |
atomOrientData[4] = dAtom->getJx(); |
| 722 |
> |
atomOrientData[5] = dAtom->getJy(); |
| 723 |
> |
atomOrientData[6] = dAtom->getJz(); |
| 724 |
> |
} |
| 725 |
|
|
| 726 |
< |
if( atoms[local_index]->isDirectional() ){ |
| 726 |
> |
} else { |
| 727 |
> |
sprintf(painCave.errMsg, |
| 728 |
> |
"Atom %d not found on processor %d\n", |
| 729 |
> |
i, worldRank ); |
| 730 |
> |
haveError= 1; |
| 731 |
> |
simError(); |
| 732 |
> |
} |
| 733 |
|
|
| 734 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 619 |
< |
dAtom->getQ( q ); |
| 734 |
> |
// I've survived this far, so send off the data! |
| 735 |
|
|
| 736 |
< |
sprintf( tempBuffer, |
| 737 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 738 |
< |
q[0], |
| 739 |
< |
q[1], |
| 625 |
< |
q[2], |
| 626 |
< |
q[3], |
| 627 |
< |
dAtom->getJx(), |
| 628 |
< |
dAtom->getJy(), |
| 629 |
< |
dAtom->getJz()); |
| 630 |
< |
strcat( writeLine, tempBuffer ); |
| 631 |
< |
} |
| 632 |
< |
else{ |
| 633 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 634 |
< |
} |
| 635 |
< |
} |
| 636 |
< |
else { |
| 637 |
< |
sprintf(painCave.errMsg, |
| 638 |
< |
"Atom %d not found on processor %d\n", |
| 639 |
< |
which_atom, worldRank ); |
| 640 |
< |
myStatus = 0; |
| 641 |
< |
simError(); |
| 736 |
> |
atomTypeTag = 4*i; |
| 737 |
> |
atomIsDirectionalTag = 4*i + 1; |
| 738 |
> |
atomTransDataTag = 4*i + 2; |
| 739 |
> |
atomOrientDataTag = 4*i + 3; |
| 740 |
|
|
| 741 |
< |
strcpy( writeLine, "Hello, I'm an error.\n"); |
| 742 |
< |
} |
| 741 |
> |
MPI_Send(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
| 742 |
> |
atomTypeTag, MPI_COMM_WORLD); |
| 743 |
> |
|
| 744 |
> |
MPI_Send(&isDirectional, 1, MPI_INT, 0, |
| 745 |
> |
atomIsDirectionalTag, MPI_COMM_WORLD); |
| 746 |
> |
|
| 747 |
> |
MPI_Send(atomTransData, 6, MPI_DOUBLE, 0, |
| 748 |
> |
atomTransDataTag, MPI_COMM_WORLD); |
| 749 |
|
|
| 750 |
< |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 751 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
| 752 |
< |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
| 753 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 750 |
> |
if (isDirectional) { |
| 751 |
> |
|
| 752 |
> |
MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0, |
| 753 |
> |
atomOrientDataTag, MPI_COMM_WORLD); |
| 754 |
> |
|
| 755 |
> |
} |
| 756 |
> |
|
| 757 |
> |
} |
| 758 |
|
} |
| 759 |
+ |
|
| 760 |
+ |
sprintf( checkPointMsg, |
| 761 |
+ |
"Sucessfully wrote final file.\n"); |
| 762 |
+ |
MPIcheckPoint(); |
| 763 |
+ |
|
| 764 |
|
} |
| 765 |
< |
finalOut.flush(); |
| 766 |
< |
sprintf( checkPointMsg, |
| 654 |
< |
"Sucessfully took a dump.\n"); |
| 655 |
< |
MPIcheckPoint(); |
| 765 |
> |
|
| 766 |
> |
painCave.isEventLoop = 0; |
| 767 |
|
|
| 768 |
|
if( worldRank == 0 ) finalOut.close(); |
| 769 |
|
#endif // is_mpi |
| 775 |
|
|
| 776 |
|
// a couple of functions to let us escape the write loop |
| 777 |
|
|
| 778 |
< |
void dWrite::nodeZeroError( void ){ |
| 668 |
< |
int j, myStatus; |
| 778 |
> |
void dWrite::DieDieDie( void ){ |
| 779 |
|
|
| 670 |
– |
myStatus = 0; |
| 671 |
– |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
| 672 |
– |
MPI_Send( &myStatus, 1, MPI_INT, j, |
| 673 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 674 |
– |
} |
| 675 |
– |
|
| 676 |
– |
|
| 780 |
|
MPI_Finalize(); |
| 781 |
|
exit (0); |
| 679 |
– |
|
| 782 |
|
} |
| 783 |
|
|
| 682 |
– |
void dWrite::anonymousNodeDie( void ){ |
| 683 |
– |
|
| 684 |
– |
MPI_Finalize(); |
| 685 |
– |
exit (0); |
| 686 |
– |
} |
| 687 |
– |
|
| 784 |
|
#endif //is_mpi |