--- trunk/OOPSE/libmdtools/DumpWriter.cpp 2003/03/26 22:24:49 415 +++ trunk/OOPSE/libmdtools/DumpWriter.cpp 2003/03/28 19:30:59 434 @@ -4,15 +4,14 @@ #ifdef IS_MPI #include +#include #include "mpiSimulation.hpp" -#define TAKE_THIS_TAG 0 +#define TAKE_THIS_TAG 1 #endif //is_mpi #include "ReadWrite.hpp" #include "simError.h" -#define GAME_OVER -1 - DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ entry_plug = the_entry_plug; @@ -66,7 +65,7 @@ void DumpWriter::writeDump( double currentTime ){ char tempBuffer[BUFFERSIZE]; char writeLine[BUFFERSIZE]; - int i; + int i, j, which_node, done, game_over, which_atom, local_index; double q[4]; DirectionalAtom* dAtom; int nAtoms = entry_plug->n_atoms; @@ -120,9 +119,10 @@ void DumpWriter::writeDump( double currentTime ){ outFile.flush(); #else // is_mpi + + MPI::Status istatus; + int *AtomToProcMap = mpiSim->getAtomToProcMap(); - MPI_Status istatus[MPI_STATUS_SIZE]; - // write out header and node 0's coordinates if( worldRank == 0 ){ @@ -132,15 +132,14 @@ void DumpWriter::writeDump( double currentTime ){ << entry_plug->box_x << "\t" << entry_plug->box_y << "\t" << entry_plug->box_z << "\n"; - - for (i = 0 ; i < mpiPlug->nAtomsGlobal; i++ ) { - // Get the Node number which has this molecule: + outFile.flush(); + for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { + // Get the Node number which has this atom; which_node = AtomToProcMap[i]; - if (which_node == mpiPlug->myNode) { - - sprintf( tempBuffer, + if (which_node == mpiSim->getMyNode()) { + sprintf( tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", atoms[i]->getType(), atoms[i]->getX(), @@ -172,64 +171,79 @@ void DumpWriter::writeDump( double currentTime ){ } else { + std::cerr << "node 0: sending node " << which_node << " request for atom " << i << "\n"; MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG); - MPI::COMM_WORLD.Receive(writeLine, BUFFERSIZE, MPI_CHAR, which_node, + std::cerr << "node 0: sent!\n"; + MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, TAKE_THIS_TAG, istatus); + std::cerr << "node 0: got this line: " << writeLine; } outFile << writeLine; + outFile.flush(); } // kill everyone off: - for (j = 0; j < mpiPlug->numberProcessors; j++) { - MPI::COMM_WORLD.Send(GAME_OVER, 1, MPI_INT, j, TAKE_THIS_TAG); + game_over = -1; + for (j = 0; j < mpiSim->getNumberProcessors(); j++) { + MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG); } } else { done = 0; while (!done) { - MPI::COMM_WORLD.Receive(&which_atom, 1, MPI_INT, 0, - TAKE_THIS_TAG, istatus); - - if (which_atom == GAME_OVER) { + std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n"; + MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, + TAKE_THIS_TAG, istatus); + std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n"; + if (which_atom == -1) { done=1; continue; } else { - - //format the line - sprintf( tempBuffer, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atoms[which_atom]->getType(), - atoms[which_atom]->getX(), - atoms[which_atom]->getY(), - atoms[which_atom]->getZ(), - atoms[which_atom]->get_vx(), - atoms[which_atom]->get_vy(), - atoms[which_atom]->get_vz()); // check here. - strcpy( writeLine, tempBuffer ); + local_index=-1; + for (j=0; j < mpiSim->getMyNlocal(); j++) { + if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; + } + if (local_index != -1) { + //format the line + sprintf( tempBuffer, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + atoms[local_index]->getType(), + atoms[local_index]->getX(), + atoms[local_index]->getY(), + atoms[local_index]->getZ(), + atoms[local_index]->get_vx(), + atoms[local_index]->get_vy(), + atoms[local_index]->get_vz()); // check here. + strcpy( writeLine, tempBuffer ); - if( atoms[which_atom]->isDirectional() ){ - - dAtom = (DirectionalAtom *)atoms[which_atom]; - dAtom->getQ( q ); - - sprintf( tempBuffer, - "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", - q[0], - q[1], - q[2], - q[3], - dAtom->getJx(), - dAtom->getJy(), - dAtom->getJz()); - strcat( writeLine, tempBuffer ); - } - else - strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); - - MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, - TAKE_THIS_TAG); + if( atoms[local_index]->isDirectional() ){ + + dAtom = (DirectionalAtom *)atoms[local_index]; + dAtom->getQ( q ); + + sprintf( tempBuffer, + "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + q[0], + q[1], + q[2], + q[3], + dAtom->getJx(), + dAtom->getJy(), + dAtom->getJz()); + strcat( writeLine, tempBuffer ); + } + else + strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); + std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine; + MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, + TAKE_THIS_TAG); + } else { + strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); + MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, + TAKE_THIS_TAG); + } } } } @@ -241,10 +255,21 @@ void DumpWriter::writeFinal(){ } void DumpWriter::writeFinal(){ - + char finalName[500]; ofstream finalOut; + + const int BUFFERSIZE = 2000; + char tempBuffer[BUFFERSIZE]; + char writeLine[BUFFERSIZE]; + + double q[4]; + DirectionalAtom* dAtom; + int nAtoms = entry_plug->n_atoms; + Atom** atoms = entry_plug->atoms; + int i, j, which_node, done, game_over, which_atom, local_index; + #ifdef IS_MPI if(worldRank == 0 ){ #endif // is_mpi @@ -278,7 +303,7 @@ void DumpWriter::writeFinal(){ finalOut << entry_plug->box_x << "\t" << entry_plug->box_y << "\t" << entry_plug->box_z << "\n"; - + for( i=0; igetAtomToProcMap(); + // write out header and node 0's coordinates if( worldRank == 0 ){ @@ -329,12 +355,12 @@ void DumpWriter::writeFinal(){ << entry_plug->box_y << "\t" << entry_plug->box_z << "\n"; - for (i = 0 ; i < mpiPlug->nAtomsGlobal; i++ ) { + for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { // Get the Node number which has this molecule: which_node = AtomToProcMap[i]; - if (which_node == mpiPlug->myNode) { + if (which_node == mpiSim->getMyNode()) { sprintf( tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", @@ -369,7 +395,7 @@ void DumpWriter::writeFinal(){ } else { MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG); - MPI::COMM_WORLD.Receive(writeLine, BUFFERSIZE, MPI_CHAR, which_node, + MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, TAKE_THIS_TAG, istatus); } @@ -377,58 +403,70 @@ void DumpWriter::writeFinal(){ } // kill everyone off: - for (j = 0; j < mpiPlug->numberProcessors; j++) { - MPI::COMM_WORLD.Send(GAME_OVER, 1, MPI_INT, j, TAKE_THIS_TAG); + game_over = -1; + for (j = 0; j < mpiSim->getNumberProcessors(); j++) { + MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG); } } else { done = 0; while (!done) { - MPI::COMM_WORLD.Receive(&which_atom, 1, MPI_INT, 0, - TAKE_THIS_TAG, istatus); + MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, + TAKE_THIS_TAG, istatus); - if (which_atom == GAME_OVER) { + if (which_atom == -1) { done=1; continue; } else { - //format the line - sprintf( tempBuffer, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atoms[which_atom]->getType(), - atoms[which_atom]->getX(), - atoms[which_atom]->getY(), - atoms[which_atom]->getZ(), - atoms[which_atom]->get_vx(), - atoms[which_atom]->get_vy(), - atoms[which_atom]->get_vz()); // check here. - strcpy( writeLine, tempBuffer ); + local_index=-1; + for (j=0; j < mpiSim->getMyNlocal(); j++) { + if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; + } + if (local_index != -1) { + + //format the line + sprintf( tempBuffer, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + atoms[local_index]->getType(), + atoms[local_index]->getX(), + atoms[local_index]->getY(), + atoms[local_index]->getZ(), + atoms[local_index]->get_vx(), + atoms[local_index]->get_vy(), + atoms[local_index]->get_vz()); // check here. + strcpy( writeLine, tempBuffer ); - if( atoms[which_atom]->isDirectional() ){ + if( atoms[local_index]->isDirectional() ){ + + dAtom = (DirectionalAtom *)atoms[local_index]; + dAtom->getQ( q ); - dAtom = (DirectionalAtom *)atoms[which_atom]; - dAtom->getQ( q ); - - sprintf( tempBuffer, - "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", - q[0], - q[1], - q[2], - q[3], - dAtom->getJx(), - dAtom->getJy(), - dAtom->getJz()); - strcat( writeLine, tempBuffer ); - } - else - strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); - - MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, - TAKE_THIS_TAG); + sprintf( tempBuffer, + "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + q[0], + q[1], + q[2], + q[3], + dAtom->getJx(), + dAtom->getJy(), + dAtom->getJz()); + strcat( writeLine, tempBuffer ); + } + else + strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); + + MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, + TAKE_THIS_TAG); + } else { + strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); + MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, + TAKE_THIS_TAG); + } } } - } + } finalOut.flush(); sprintf( checkPointMsg, "Sucessfully took a dump.\n");