--- trunk/OOPSE/libmdtools/DumpWriter.cpp 2003/03/27 01:49:45 417 +++ trunk/OOPSE/libmdtools/DumpWriter.cpp 2003/03/28 19:30:59 434 @@ -6,7 +6,7 @@ #include #include #include "mpiSimulation.hpp" -#define TAKE_THIS_TAG 0 +#define TAKE_THIS_TAG 1 #endif //is_mpi #include "ReadWrite.hpp" @@ -65,7 +65,7 @@ void DumpWriter::writeDump( double currentTime ){ char tempBuffer[BUFFERSIZE]; char writeLine[BUFFERSIZE]; - int i, j, which_node, done, game_over, which_atom; + int i, j, which_node, done, game_over, which_atom, local_index; double q[4]; DirectionalAtom* dAtom; int nAtoms = entry_plug->n_atoms; @@ -132,15 +132,14 @@ void DumpWriter::writeDump( double currentTime ){ << entry_plug->box_x << "\t" << entry_plug->box_y << "\t" << entry_plug->box_z << "\n"; - + outFile.flush(); for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { // Get the Node number which has this atom; which_node = AtomToProcMap[i]; if (which_node == mpiSim->getMyNode()) { - - sprintf( tempBuffer, + sprintf( tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", atoms[i]->getType(), atoms[i]->getX(), @@ -172,12 +171,16 @@ 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); + 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: @@ -190,47 +193,57 @@ void DumpWriter::writeDump( double currentTime ){ done = 0; while (!done) { + std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n"; MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, - TAKE_THIS_TAG, istatus); - + 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); + } } } } @@ -254,7 +267,7 @@ void DumpWriter::writeFinal(){ DirectionalAtom* dAtom; int nAtoms = entry_plug->n_atoms; Atom** atoms = entry_plug->atoms; - int i, j, which_node, done, game_over, which_atom; + int i, j, which_node, done, game_over, which_atom, local_index; #ifdef IS_MPI @@ -407,42 +420,53 @@ void DumpWriter::writeFinal(){ 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");