| 4 |
|
|
| 5 |
|
#ifdef IS_MPI |
| 6 |
|
#include <mpi.h> |
| 7 |
– |
#include <mpi++.h> |
| 7 |
|
#include "mpiSimulation.hpp" |
| 8 |
< |
#define TAKE_THIS_TAG 1 |
| 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 |
|
|
| 23 |
– |
|
| 24 |
– |
|
| 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; |
| 81 |
|
|
| 82 |
|
outFile << nAtoms << "\n"; |
| 83 |
|
|
| 84 |
< |
outFile << currentTime << "\t" |
| 85 |
< |
<< entry_plug->box_x << "\t" |
| 86 |
< |
<< entry_plug->box_y << "\t" |
| 87 |
< |
<< entry_plug->box_z << "\n"; |
| 84 |
> |
outFile << currentTime << ";\t" |
| 85 |
> |
<< entry_plug->Hmat[0][0] << "\t" |
| 86 |
> |
<< entry_plug->Hmat[1][0] << "\t" |
| 87 |
> |
<< entry_plug->Hmat[2][0] << ";\t" |
| 88 |
> |
|
| 89 |
> |
<< entry_plug->Hmat[0][1] << "\t" |
| 90 |
> |
<< entry_plug->Hmat[1][1] << "\t" |
| 91 |
> |
<< entry_plug->Hmat[2][1] << ";\t" |
| 92 |
> |
|
| 93 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
| 94 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
| 95 |
> |
<< entry_plug->Hmat[2][2] << ";\n"; |
| 96 |
|
|
| 97 |
|
for( i=0; i<nAtoms; i++ ){ |
| 98 |
|
|
| 133 |
|
|
| 134 |
|
#else // is_mpi |
| 135 |
|
|
| 136 |
< |
MPI::Status istatus; |
| 136 |
> |
// first thing first, suspend fatalities. |
| 137 |
> |
painCave.isEventLoop = 1; |
| 138 |
> |
|
| 139 |
> |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
| 140 |
> |
int haveError; |
| 141 |
> |
|
| 142 |
> |
MPI_Status istatus; |
| 143 |
|
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
| 144 |
|
|
| 145 |
|
// write out header and node 0's coordinates |
| 146 |
|
|
| 147 |
|
if( worldRank == 0 ){ |
| 148 |
|
outFile << mpiSim->getTotAtoms() << "\n"; |
| 149 |
< |
|
| 149 |
> |
|
| 150 |
|
outFile << currentTime << "\t" |
| 151 |
< |
<< entry_plug->box_x << "\t" |
| 152 |
< |
<< entry_plug->box_y << "\t" |
| 153 |
< |
<< entry_plug->box_z << "\n"; |
| 151 |
> |
<< entry_plug->Hmat[0] << "\t" |
| 152 |
> |
<< entry_plug->Hmat[1] << "\t" |
| 153 |
> |
<< entry_plug->Hmat[2] << "\t" |
| 154 |
> |
|
| 155 |
> |
<< entry_plug->Hmat[3] << "\t" |
| 156 |
> |
<< entry_plug->Hmat[4] << "\t" |
| 157 |
> |
<< entry_plug->Hmat[5] << "\t" |
| 158 |
> |
|
| 159 |
> |
<< entry_plug->Hmat[6] << "\t" |
| 160 |
> |
<< entry_plug->Hmat[7] << "\t" |
| 161 |
> |
<< entry_plug->Hmat[8] << "\n"; |
| 162 |
> |
; |
| 163 |
|
outFile.flush(); |
| 164 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
| 165 |
|
// Get the Node number which has this atom; |
| 166 |
|
|
| 167 |
|
which_node = AtomToProcMap[i]; |
| 168 |
|
|
| 169 |
< |
if (which_node == mpiSim->getMyNode()) { |
| 142 |
< |
sprintf( tempBuffer, |
| 143 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 144 |
< |
atoms[i]->getType(), |
| 145 |
< |
atoms[i]->getX(), |
| 146 |
< |
atoms[i]->getY(), |
| 147 |
< |
atoms[i]->getZ(), |
| 148 |
< |
atoms[i]->get_vx(), |
| 149 |
< |
atoms[i]->get_vy(), |
| 150 |
< |
atoms[i]->get_vz()); |
| 151 |
< |
strcpy( writeLine, tempBuffer ); |
| 169 |
> |
if (which_node == 0 ) { |
| 170 |
|
|
| 171 |
< |
if( atoms[i]->isDirectional() ){ |
| 172 |
< |
|
| 173 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
| 174 |
< |
dAtom->getQ( q ); |
| 157 |
< |
|
| 158 |
< |
sprintf( tempBuffer, |
| 159 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 160 |
< |
q[0], |
| 161 |
< |
q[1], |
| 162 |
< |
q[2], |
| 163 |
< |
q[3], |
| 164 |
< |
dAtom->getJx(), |
| 165 |
< |
dAtom->getJy(), |
| 166 |
< |
dAtom->getJz()); |
| 167 |
< |
strcat( writeLine, tempBuffer ); |
| 168 |
< |
} |
| 169 |
< |
else |
| 170 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 171 |
< |
|
| 172 |
< |
} else { |
| 173 |
< |
|
| 174 |
< |
std::cerr << "node 0: sending node " << which_node << " request for atom " << i << "\n"; |
| 175 |
< |
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG); |
| 176 |
< |
std::cerr << "node 0: sent!\n"; |
| 177 |
< |
MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 178 |
< |
TAKE_THIS_TAG, istatus); |
| 179 |
< |
std::cerr << "node 0: got this line: " << writeLine; |
| 180 |
< |
} |
| 181 |
< |
|
| 182 |
< |
outFile << writeLine; |
| 183 |
< |
outFile.flush(); |
| 184 |
< |
} |
| 185 |
< |
|
| 186 |
< |
// kill everyone off: |
| 187 |
< |
game_over = -1; |
| 188 |
< |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
| 189 |
< |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG); |
| 190 |
< |
} |
| 191 |
< |
|
| 192 |
< |
} else { |
| 193 |
< |
|
| 194 |
< |
done = 0; |
| 195 |
< |
while (!done) { |
| 196 |
< |
std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n"; |
| 197 |
< |
MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
| 198 |
< |
TAKE_THIS_TAG, istatus); |
| 199 |
< |
std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n"; |
| 200 |
< |
if (which_atom == -1) { |
| 201 |
< |
done=1; |
| 202 |
< |
continue; |
| 203 |
< |
} else { |
| 204 |
< |
local_index=-1; |
| 205 |
< |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
| 171 |
> |
haveError = 0; |
| 172 |
> |
which_atom = i; |
| 173 |
> |
local_index=-1; |
| 174 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
| 175 |
|
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 176 |
|
} |
| 177 |
|
if (local_index != -1) { |
| 202 |
|
dAtom->getJy(), |
| 203 |
|
dAtom->getJz()); |
| 204 |
|
strcat( writeLine, tempBuffer ); |
| 205 |
< |
} |
| 206 |
< |
else |
| 207 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 208 |
< |
std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine; |
| 209 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 210 |
< |
TAKE_THIS_TAG); |
| 211 |
< |
} else { |
| 212 |
< |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
| 213 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 214 |
< |
TAKE_THIS_TAG); |
| 215 |
< |
} |
| 205 |
> |
|
| 206 |
> |
} |
| 207 |
> |
else |
| 208 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 209 |
> |
} |
| 210 |
> |
else { |
| 211 |
> |
sprintf(painCave.errMsg, |
| 212 |
> |
"Atom %d not found on processor %d\n", |
| 213 |
> |
i, worldRank ); |
| 214 |
> |
haveError= 1; |
| 215 |
> |
simError(); |
| 216 |
> |
} |
| 217 |
> |
|
| 218 |
> |
if(haveError) nodeZeroError(); |
| 219 |
> |
|
| 220 |
|
} |
| 221 |
+ |
else { |
| 222 |
+ |
myStatus = 1; |
| 223 |
+ |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
| 224 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 225 |
+ |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
| 226 |
+ |
MPI_COMM_WORLD); |
| 227 |
+ |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 228 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
| 229 |
+ |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
| 230 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 231 |
+ |
|
| 232 |
+ |
if(!myStatus) nodeZeroError(); |
| 233 |
+ |
|
| 234 |
+ |
} |
| 235 |
+ |
|
| 236 |
+ |
outFile << writeLine; |
| 237 |
+ |
outFile.flush(); |
| 238 |
|
} |
| 239 |
+ |
|
| 240 |
+ |
// kill everyone off: |
| 241 |
+ |
myStatus = -1; |
| 242 |
+ |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
| 243 |
+ |
MPI_Send(&myStatus, 1, MPI_INT, j, |
| 244 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 245 |
+ |
} |
| 246 |
+ |
|
| 247 |
+ |
} else { |
| 248 |
+ |
|
| 249 |
+ |
done = 0; |
| 250 |
+ |
while (!done) { |
| 251 |
+ |
|
| 252 |
+ |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
| 253 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 254 |
+ |
|
| 255 |
+ |
if(!myStatus) anonymousNodeDie(); |
| 256 |
+ |
|
| 257 |
+ |
if(myStatus < 0) break; |
| 258 |
+ |
|
| 259 |
+ |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
| 260 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 261 |
+ |
|
| 262 |
+ |
myStatus = 1; |
| 263 |
+ |
local_index=-1; |
| 264 |
+ |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
| 265 |
+ |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 266 |
+ |
} |
| 267 |
+ |
if (local_index != -1) { |
| 268 |
+ |
//format the line |
| 269 |
+ |
sprintf( tempBuffer, |
| 270 |
+ |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 271 |
+ |
atoms[local_index]->getType(), |
| 272 |
+ |
atoms[local_index]->getX(), |
| 273 |
+ |
atoms[local_index]->getY(), |
| 274 |
+ |
atoms[local_index]->getZ(), |
| 275 |
+ |
atoms[local_index]->get_vx(), |
| 276 |
+ |
atoms[local_index]->get_vy(), |
| 277 |
+ |
atoms[local_index]->get_vz()); // check here. |
| 278 |
+ |
strcpy( writeLine, tempBuffer ); |
| 279 |
+ |
|
| 280 |
+ |
if( atoms[local_index]->isDirectional() ){ |
| 281 |
+ |
|
| 282 |
+ |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 283 |
+ |
dAtom->getQ( q ); |
| 284 |
+ |
|
| 285 |
+ |
sprintf( tempBuffer, |
| 286 |
+ |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 287 |
+ |
q[0], |
| 288 |
+ |
q[1], |
| 289 |
+ |
q[2], |
| 290 |
+ |
q[3], |
| 291 |
+ |
dAtom->getJx(), |
| 292 |
+ |
dAtom->getJy(), |
| 293 |
+ |
dAtom->getJz()); |
| 294 |
+ |
strcat( writeLine, tempBuffer ); |
| 295 |
+ |
} |
| 296 |
+ |
else{ |
| 297 |
+ |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 298 |
+ |
} |
| 299 |
+ |
} |
| 300 |
+ |
else { |
| 301 |
+ |
sprintf(painCave.errMsg, |
| 302 |
+ |
"Atom %d not found on processor %d\n", |
| 303 |
+ |
which_atom, worldRank ); |
| 304 |
+ |
myStatus = 0; |
| 305 |
+ |
simError(); |
| 306 |
+ |
|
| 307 |
+ |
strcpy( writeLine, "Hello, I'm an error.\n"); |
| 308 |
+ |
} |
| 309 |
+ |
|
| 310 |
+ |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 311 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
| 312 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
| 313 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 314 |
+ |
} |
| 315 |
|
} |
| 316 |
|
outFile.flush(); |
| 317 |
|
sprintf( checkPointMsg, |
| 318 |
|
"Sucessfully took a dump.\n"); |
| 319 |
|
MPIcheckPoint(); |
| 320 |
+ |
|
| 321 |
+ |
// last thing last, enable fatalities. |
| 322 |
+ |
painCave.isEventLoop = 0; |
| 323 |
+ |
|
| 324 |
|
#endif // is_mpi |
| 325 |
|
} |
| 326 |
|
|
| 327 |
< |
void DumpWriter::writeFinal(){ |
| 327 |
> |
void DumpWriter::writeFinal(double finalTime){ |
| 328 |
|
|
| 329 |
|
char finalName[500]; |
| 330 |
|
ofstream finalOut; |
| 370 |
|
|
| 371 |
|
finalOut << nAtoms << "\n"; |
| 372 |
|
|
| 373 |
< |
finalOut << entry_plug->box_x << "\t" |
| 374 |
< |
<< entry_plug->box_y << "\t" |
| 375 |
< |
<< entry_plug->box_z << "\n"; |
| 373 |
> |
finalOut << finalTime << "\t" |
| 374 |
> |
<< entry_plug->Hmat[0][0] << "\t" |
| 375 |
> |
<< entry_plug->Hmat[1][0] << "\t" |
| 376 |
> |
<< entry_plug->Hmat[2][0] << "\t" |
| 377 |
> |
|
| 378 |
> |
<< entry_plug->Hmat[0][1] << "\t" |
| 379 |
> |
<< entry_plug->Hmat[1][1] << "\t" |
| 380 |
> |
<< entry_plug->Hmat[2][1] << "\t" |
| 381 |
> |
|
| 382 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
| 383 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
| 384 |
> |
<< entry_plug->Hmat[2][2] << "\n"; |
| 385 |
|
|
| 386 |
|
for( i=0; i<nAtoms; i++ ){ |
| 387 |
|
|
| 422 |
|
|
| 423 |
|
#else // is_mpi |
| 424 |
|
|
| 425 |
< |
MPI::Status istatus; |
| 425 |
> |
// first thing first, suspend fatalities. |
| 426 |
> |
painCave.isEventLoop = 1; |
| 427 |
> |
|
| 428 |
> |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
| 429 |
> |
int haveError; |
| 430 |
> |
|
| 431 |
> |
MPI_Status istatus; |
| 432 |
|
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
| 433 |
|
|
| 434 |
|
// write out header and node 0's coordinates |
| 435 |
|
|
| 436 |
+ |
haveError = 0; |
| 437 |
|
if( worldRank == 0 ){ |
| 438 |
|
finalOut << mpiSim->getTotAtoms() << "\n"; |
| 439 |
|
|
| 440 |
< |
finalOut << entry_plug->box_x << "\t" |
| 441 |
< |
<< entry_plug->box_y << "\t" |
| 442 |
< |
<< entry_plug->box_z << "\n"; |
| 440 |
> |
finalOut << finalTime << "\t" |
| 441 |
> |
<< entry_plug->Hmat[0] << "\t" |
| 442 |
> |
<< entry_plug->Hmat[1] << "\t" |
| 443 |
> |
<< entry_plug->Hmat[2] << "\t" |
| 444 |
> |
|
| 445 |
> |
<< entry_plug->Hmat[3] << "\t" |
| 446 |
> |
<< entry_plug->Hmat[4] << "\t" |
| 447 |
> |
<< entry_plug->Hmat[5] << "\t" |
| 448 |
> |
|
| 449 |
> |
<< entry_plug->Hmat[6] << "\t" |
| 450 |
> |
<< entry_plug->Hmat[7] << "\t" |
| 451 |
> |
<< entry_plug->Hmat[8] << "\n"; |
| 452 |
|
|
| 453 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
| 454 |
|
// Get the Node number which has this molecule: |
| 456 |
|
which_node = AtomToProcMap[i]; |
| 457 |
|
|
| 458 |
|
if (which_node == mpiSim->getMyNode()) { |
| 459 |
< |
|
| 460 |
< |
sprintf( tempBuffer, |
| 461 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 462 |
< |
atoms[i]->getType(), |
| 463 |
< |
atoms[i]->getX(), |
| 369 |
< |
atoms[i]->getY(), |
| 370 |
< |
atoms[i]->getZ(), |
| 371 |
< |
atoms[i]->get_vx(), |
| 372 |
< |
atoms[i]->get_vy(), |
| 373 |
< |
atoms[i]->get_vz()); |
| 374 |
< |
strcpy( writeLine, tempBuffer ); |
| 375 |
< |
|
| 376 |
< |
if( atoms[i]->isDirectional() ){ |
| 377 |
< |
|
| 378 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
| 379 |
< |
dAtom->getQ( q ); |
| 380 |
< |
|
| 381 |
< |
sprintf( tempBuffer, |
| 382 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 383 |
< |
q[0], |
| 384 |
< |
q[1], |
| 385 |
< |
q[2], |
| 386 |
< |
q[3], |
| 387 |
< |
dAtom->getJx(), |
| 388 |
< |
dAtom->getJy(), |
| 389 |
< |
dAtom->getJz()); |
| 390 |
< |
strcat( writeLine, tempBuffer ); |
| 459 |
> |
|
| 460 |
> |
which_atom = i; |
| 461 |
> |
local_index=-1; |
| 462 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
| 463 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 464 |
|
} |
| 465 |
< |
else |
| 466 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 465 |
> |
if (local_index != -1) { |
| 466 |
> |
sprintf( tempBuffer, |
| 467 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 468 |
> |
atoms[local_index]->getType(), |
| 469 |
> |
atoms[local_index]->getX(), |
| 470 |
> |
atoms[local_index]->getY(), |
| 471 |
> |
atoms[local_index]->getZ(), |
| 472 |
> |
atoms[local_index]->get_vx(), |
| 473 |
> |
atoms[local_index]->get_vy(), |
| 474 |
> |
atoms[local_index]->get_vz()); |
| 475 |
> |
strcpy( writeLine, tempBuffer ); |
| 476 |
> |
|
| 477 |
> |
if( atoms[local_index]->isDirectional() ){ |
| 478 |
> |
|
| 479 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 480 |
> |
dAtom->getQ( q ); |
| 481 |
> |
|
| 482 |
> |
sprintf( tempBuffer, |
| 483 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 484 |
> |
q[0], |
| 485 |
> |
q[1], |
| 486 |
> |
q[2], |
| 487 |
> |
q[3], |
| 488 |
> |
dAtom->getJx(), |
| 489 |
> |
dAtom->getJy(), |
| 490 |
> |
dAtom->getJz()); |
| 491 |
> |
strcat( writeLine, tempBuffer ); |
| 492 |
> |
} |
| 493 |
> |
else |
| 494 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 495 |
> |
} |
| 496 |
> |
else { |
| 497 |
> |
sprintf(painCave.errMsg, |
| 498 |
> |
"Atom %d not found on processor %d\n", |
| 499 |
> |
i, worldRank ); |
| 500 |
> |
haveError= 1; |
| 501 |
> |
simError(); |
| 502 |
> |
} |
| 503 |
> |
|
| 504 |
> |
if(haveError) nodeZeroError(); |
| 505 |
> |
|
| 506 |
> |
} |
| 507 |
> |
else { |
| 508 |
|
|
| 509 |
< |
} else { |
| 510 |
< |
|
| 511 |
< |
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG); |
| 512 |
< |
MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 513 |
< |
TAKE_THIS_TAG, istatus); |
| 509 |
> |
myStatus = 1; |
| 510 |
> |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
| 511 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 512 |
> |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
| 513 |
> |
MPI_COMM_WORLD); |
| 514 |
> |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
| 515 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
| 516 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
| 517 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 518 |
> |
|
| 519 |
> |
if(!myStatus) nodeZeroError(); |
| 520 |
|
} |
| 521 |
|
|
| 522 |
|
finalOut << writeLine; |
| 523 |
|
} |
| 524 |
|
|
| 525 |
|
// kill everyone off: |
| 526 |
< |
game_over = -1; |
| 527 |
< |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
| 528 |
< |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG); |
| 526 |
> |
myStatus = -1; |
| 527 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
| 528 |
> |
MPI_Send(&myStatus, 1, MPI_INT, j, |
| 529 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 530 |
|
} |
| 531 |
|
|
| 532 |
|
} else { |
| 533 |
|
|
| 534 |
|
done = 0; |
| 535 |
|
while (!done) { |
| 415 |
– |
MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
| 416 |
– |
TAKE_THIS_TAG, istatus); |
| 536 |
|
|
| 537 |
< |
if (which_atom == -1) { |
| 538 |
< |
done=1; |
| 539 |
< |
continue; |
| 540 |
< |
} else { |
| 537 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
| 538 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 539 |
> |
|
| 540 |
> |
if(!myStatus) anonymousNodeDie(); |
| 541 |
> |
|
| 542 |
> |
if(myStatus < 0) break; |
| 543 |
> |
|
| 544 |
> |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
| 545 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
| 546 |
> |
|
| 547 |
> |
myStatus = 1; |
| 548 |
> |
local_index=-1; |
| 549 |
> |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
| 550 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 551 |
> |
} |
| 552 |
> |
if (local_index != -1) { |
| 553 |
|
|
| 554 |
< |
local_index=-1; |
| 555 |
< |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
| 556 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 557 |
< |
} |
| 558 |
< |
if (local_index != -1) { |
| 559 |
< |
|
| 560 |
< |
//format the line |
| 561 |
< |
sprintf( tempBuffer, |
| 562 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 563 |
< |
atoms[local_index]->getType(), |
| 564 |
< |
atoms[local_index]->getX(), |
| 565 |
< |
atoms[local_index]->getY(), |
| 566 |
< |
atoms[local_index]->getZ(), |
| 436 |
< |
atoms[local_index]->get_vx(), |
| 437 |
< |
atoms[local_index]->get_vy(), |
| 438 |
< |
atoms[local_index]->get_vz()); // check here. |
| 439 |
< |
strcpy( writeLine, tempBuffer ); |
| 554 |
> |
//format the line |
| 555 |
> |
sprintf( tempBuffer, |
| 556 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 557 |
> |
atoms[local_index]->getType(), |
| 558 |
> |
atoms[local_index]->getX(), |
| 559 |
> |
atoms[local_index]->getY(), |
| 560 |
> |
atoms[local_index]->getZ(), |
| 561 |
> |
atoms[local_index]->get_vx(), |
| 562 |
> |
atoms[local_index]->get_vy(), |
| 563 |
> |
atoms[local_index]->get_vz()); // check here. |
| 564 |
> |
strcpy( writeLine, tempBuffer ); |
| 565 |
> |
|
| 566 |
> |
if( atoms[local_index]->isDirectional() ){ |
| 567 |
|
|
| 568 |
< |
if( atoms[local_index]->isDirectional() ){ |
| 569 |
< |
|
| 570 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 571 |
< |
dAtom->getQ( q ); |
| 572 |
< |
|
| 573 |
< |
sprintf( tempBuffer, |
| 574 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 575 |
< |
q[0], |
| 576 |
< |
q[1], |
| 577 |
< |
q[2], |
| 578 |
< |
q[3], |
| 579 |
< |
dAtom->getJx(), |
| 580 |
< |
dAtom->getJy(), |
| 581 |
< |
dAtom->getJz()); |
| 582 |
< |
strcat( writeLine, tempBuffer ); |
| 583 |
< |
} |
| 584 |
< |
else |
| 585 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 586 |
< |
|
| 587 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 588 |
< |
TAKE_THIS_TAG); |
| 589 |
< |
} else { |
| 590 |
< |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
| 591 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 592 |
< |
TAKE_THIS_TAG); |
| 593 |
< |
} |
| 568 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 569 |
> |
dAtom->getQ( q ); |
| 570 |
> |
|
| 571 |
> |
sprintf( tempBuffer, |
| 572 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 573 |
> |
q[0], |
| 574 |
> |
q[1], |
| 575 |
> |
q[2], |
| 576 |
> |
q[3], |
| 577 |
> |
dAtom->getJx(), |
| 578 |
> |
dAtom->getJy(), |
| 579 |
> |
dAtom->getJz()); |
| 580 |
> |
strcat( writeLine, tempBuffer ); |
| 581 |
> |
} |
| 582 |
> |
else{ |
| 583 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 584 |
> |
} |
| 585 |
> |
} |
| 586 |
> |
else { |
| 587 |
> |
sprintf(painCave.errMsg, |
| 588 |
> |
"Atom %d not found on processor %d\n", |
| 589 |
> |
which_atom, worldRank ); |
| 590 |
> |
myStatus = 0; |
| 591 |
> |
simError(); |
| 592 |
> |
|
| 593 |
> |
strcpy( writeLine, "Hello, I'm an error.\n"); |
| 594 |
|
} |
| 595 |
+ |
|
| 596 |
+ |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 597 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
| 598 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
| 599 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 600 |
|
} |
| 601 |
|
} |
| 602 |
|
finalOut.flush(); |
| 603 |
|
sprintf( checkPointMsg, |
| 604 |
|
"Sucessfully took a dump.\n"); |
| 605 |
|
MPIcheckPoint(); |
| 606 |
< |
|
| 606 |
> |
|
| 607 |
|
if( worldRank == 0 ) finalOut.close(); |
| 608 |
|
#endif // is_mpi |
| 609 |
|
} |
| 610 |
+ |
|
| 611 |
+ |
|
| 612 |
+ |
|
| 613 |
+ |
#ifdef IS_MPI |
| 614 |
+ |
|
| 615 |
+ |
// a couple of functions to let us escape the write loop |
| 616 |
+ |
|
| 617 |
+ |
void dWrite::nodeZeroError( void ){ |
| 618 |
+ |
int j, myStatus; |
| 619 |
+ |
|
| 620 |
+ |
myStatus = 0; |
| 621 |
+ |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
| 622 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, j, |
| 623 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
| 624 |
+ |
} |
| 625 |
+ |
|
| 626 |
+ |
|
| 627 |
+ |
MPI_Finalize(); |
| 628 |
+ |
exit (0); |
| 629 |
+ |
|
| 630 |
+ |
} |
| 631 |
+ |
|
| 632 |
+ |
void dWrite::anonymousNodeDie( void ){ |
| 633 |
+ |
|
| 634 |
+ |
MPI_Finalize(); |
| 635 |
+ |
exit (0); |
| 636 |
+ |
} |
| 637 |
+ |
|
| 638 |
+ |
#endif //is_mpi |