| 6 |
|
#include <mpi.h> |
| 7 |
|
#include <mpi++.h> |
| 8 |
|
#include "mpiSimulation.hpp" |
| 9 |
< |
#define TAKE_THIS_TAG 0 |
| 9 |
> |
#define TAKE_THIS_TAG 1 |
| 10 |
|
#endif //is_mpi |
| 11 |
|
|
| 12 |
|
#include "ReadWrite.hpp" |
| 65 |
|
char tempBuffer[BUFFERSIZE]; |
| 66 |
|
char writeLine[BUFFERSIZE]; |
| 67 |
|
|
| 68 |
< |
int i, j, which_node, done, game_over, which_atom; |
| 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; |
| 132 |
|
<< entry_plug->box_x << "\t" |
| 133 |
|
<< entry_plug->box_y << "\t" |
| 134 |
|
<< entry_plug->box_z << "\n"; |
| 135 |
< |
|
| 135 |
> |
outFile.flush(); |
| 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 == mpiSim->getMyNode()) { |
| 142 |
< |
|
| 143 |
< |
sprintf( tempBuffer, |
| 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(), |
| 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: |
| 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 |
< |
|
| 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 |
< |
|
| 205 |
< |
//format the line |
| 206 |
< |
sprintf( tempBuffer, |
| 207 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 208 |
< |
atoms[which_atom]->getType(), |
| 209 |
< |
atoms[which_atom]->getX(), |
| 210 |
< |
atoms[which_atom]->getY(), |
| 211 |
< |
atoms[which_atom]->getZ(), |
| 212 |
< |
atoms[which_atom]->get_vx(), |
| 213 |
< |
atoms[which_atom]->get_vy(), |
| 214 |
< |
atoms[which_atom]->get_vz()); // check here. |
| 215 |
< |
strcpy( writeLine, tempBuffer ); |
| 204 |
> |
local_index=-1; |
| 205 |
> |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
| 206 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 207 |
> |
} |
| 208 |
> |
if (local_index != -1) { |
| 209 |
> |
//format the line |
| 210 |
> |
sprintf( tempBuffer, |
| 211 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 212 |
> |
atoms[local_index]->getType(), |
| 213 |
> |
atoms[local_index]->getX(), |
| 214 |
> |
atoms[local_index]->getY(), |
| 215 |
> |
atoms[local_index]->getZ(), |
| 216 |
> |
atoms[local_index]->get_vx(), |
| 217 |
> |
atoms[local_index]->get_vy(), |
| 218 |
> |
atoms[local_index]->get_vz()); // check here. |
| 219 |
> |
strcpy( writeLine, tempBuffer ); |
| 220 |
|
|
| 221 |
< |
if( atoms[which_atom]->isDirectional() ){ |
| 222 |
< |
|
| 223 |
< |
dAtom = (DirectionalAtom *)atoms[which_atom]; |
| 224 |
< |
dAtom->getQ( q ); |
| 225 |
< |
|
| 226 |
< |
sprintf( tempBuffer, |
| 227 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 228 |
< |
q[0], |
| 229 |
< |
q[1], |
| 230 |
< |
q[2], |
| 231 |
< |
q[3], |
| 232 |
< |
dAtom->getJx(), |
| 233 |
< |
dAtom->getJy(), |
| 234 |
< |
dAtom->getJz()); |
| 235 |
< |
strcat( writeLine, tempBuffer ); |
| 236 |
< |
} |
| 237 |
< |
else |
| 238 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 239 |
< |
|
| 240 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 241 |
< |
TAKE_THIS_TAG); |
| 221 |
> |
if( atoms[local_index]->isDirectional() ){ |
| 222 |
> |
|
| 223 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 224 |
> |
dAtom->getQ( q ); |
| 225 |
> |
|
| 226 |
> |
sprintf( tempBuffer, |
| 227 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 228 |
> |
q[0], |
| 229 |
> |
q[1], |
| 230 |
> |
q[2], |
| 231 |
> |
q[3], |
| 232 |
> |
dAtom->getJx(), |
| 233 |
> |
dAtom->getJy(), |
| 234 |
> |
dAtom->getJz()); |
| 235 |
> |
strcat( writeLine, tempBuffer ); |
| 236 |
> |
} |
| 237 |
> |
else |
| 238 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 239 |
> |
std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine; |
| 240 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 241 |
> |
TAKE_THIS_TAG); |
| 242 |
> |
} else { |
| 243 |
> |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
| 244 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 245 |
> |
TAKE_THIS_TAG); |
| 246 |
> |
} |
| 247 |
|
} |
| 248 |
|
} |
| 249 |
|
} |
| 267 |
|
DirectionalAtom* dAtom; |
| 268 |
|
int nAtoms = entry_plug->n_atoms; |
| 269 |
|
Atom** atoms = entry_plug->atoms; |
| 270 |
< |
int i, j, which_node, done, game_over, which_atom; |
| 270 |
> |
int i, j, which_node, done, game_over, which_atom, local_index; |
| 271 |
|
|
| 272 |
|
|
| 273 |
|
#ifdef IS_MPI |
| 420 |
|
continue; |
| 421 |
|
} else { |
| 422 |
|
|
| 423 |
< |
//format the line |
| 424 |
< |
sprintf( tempBuffer, |
| 425 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 426 |
< |
atoms[which_atom]->getType(), |
| 427 |
< |
atoms[which_atom]->getX(), |
| 428 |
< |
atoms[which_atom]->getY(), |
| 429 |
< |
atoms[which_atom]->getZ(), |
| 430 |
< |
atoms[which_atom]->get_vx(), |
| 431 |
< |
atoms[which_atom]->get_vy(), |
| 432 |
< |
atoms[which_atom]->get_vz()); // check here. |
| 433 |
< |
strcpy( writeLine, tempBuffer ); |
| 423 |
> |
local_index=-1; |
| 424 |
> |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
| 425 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
| 426 |
> |
} |
| 427 |
> |
if (local_index != -1) { |
| 428 |
> |
|
| 429 |
> |
//format the line |
| 430 |
> |
sprintf( tempBuffer, |
| 431 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
| 432 |
> |
atoms[local_index]->getType(), |
| 433 |
> |
atoms[local_index]->getX(), |
| 434 |
> |
atoms[local_index]->getY(), |
| 435 |
> |
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 ); |
| 440 |
|
|
| 441 |
< |
if( atoms[which_atom]->isDirectional() ){ |
| 441 |
> |
if( atoms[local_index]->isDirectional() ){ |
| 442 |
> |
|
| 443 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
| 444 |
> |
dAtom->getQ( q ); |
| 445 |
|
|
| 446 |
< |
dAtom = (DirectionalAtom *)atoms[which_atom]; |
| 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 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 464 |
< |
TAKE_THIS_TAG); |
| 446 |
> |
sprintf( tempBuffer, |
| 447 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
| 448 |
> |
q[0], |
| 449 |
> |
q[1], |
| 450 |
> |
q[2], |
| 451 |
> |
q[3], |
| 452 |
> |
dAtom->getJx(), |
| 453 |
> |
dAtom->getJy(), |
| 454 |
> |
dAtom->getJz()); |
| 455 |
> |
strcat( writeLine, tempBuffer ); |
| 456 |
> |
} |
| 457 |
> |
else |
| 458 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
| 459 |
> |
|
| 460 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 461 |
> |
TAKE_THIS_TAG); |
| 462 |
> |
} else { |
| 463 |
> |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
| 464 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
| 465 |
> |
TAKE_THIS_TAG); |
| 466 |
> |
} |
| 467 |
|
} |
| 468 |
|
} |
| 469 |
< |
} |
| 469 |
> |
} |
| 470 |
|
finalOut.flush(); |
| 471 |
|
sprintf( checkPointMsg, |
| 472 |
|
"Sucessfully took a dump.\n"); |