--- trunk/mdtools/md_code/DumpWriter.cpp 2002/12/16 21:42:14 214 +++ trunk/mdtools/md_code/DumpWriter.cpp 2003/01/31 21:04:27 260 @@ -1,12 +1,20 @@ #include #include #include + +#ifdef IS_MPI #include +#include "mpiSimulation.hpp" +#define TAKE_THIS_TAG 0 +#endif //is_mpi #include "ReadWrite.hpp" #include "simError.h" + + + DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ #ifdef IS_MPI @@ -34,6 +42,10 @@ DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ #ifdef IS_MPI } + + sprintf( checkPointMsg, + "Sucessfully opened output file for dumping.\n"); + MPIcheckPoint(); #endif // is_mpi } @@ -53,7 +65,7 @@ void DumpWriter::writeDump( double currentTime ){ void DumpWriter::writeDump( double currentTime ){ const int BUFFERSIZE = 2000; - char tempBuffer[500]; + char tempBuffer[BUFFERSIZE]; char writeLine[BUFFERSIZE]; int i; @@ -123,7 +135,7 @@ void DumpWriter::writeDump( double currentTime ){ // write out header and node 0's coordinates if( worldRank == 0 ){ - outFile << entry_plug->mpiSim->getTotAtoms() << "\n"; + outFile << mpiSim->getTotAtoms() << "\n"; outFile << currentTime << "\t" << entry_plug->box_x << "\t" @@ -163,29 +175,33 @@ void DumpWriter::writeDump( double currentTime ){ else strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); - outfile << writeLine; + outFile << writeLine; masterIndex++; } outFile.flush(); } + + sprintf( checkPointMsg, + "Sucessfully wrote node 0's dump configuration.\n"); + MPIcheckPoint(); - for (procIndex = 1; procIndex < entry_plug->mpiSim->getNumberProcessors(); + for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); procIndex++){ if( worldRank == 0 ){ - + mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex, - MPI_ANY_TAG,MPI_COMM_WORLD,istatus); - + TAKE_THIS_TAG,MPI_COMM_WORLD,istatus); + mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex, - MPI_ANY_TAG,MPI_COMM_WORLD, istatus); - + TAKE_THIS_TAG,MPI_COMM_WORLD, istatus); + // Make sure where node 0 is writing to, matches where the // receiving node expects it to be. - + if (masterIndex != nodeAtomsStart){ sendError = 1; - mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG, + mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, MPI_COMM_WORLD); sprintf(painCave.errMsg, "DumpWriter error: atoms start index (%d) for " @@ -194,18 +210,18 @@ void DumpWriter::writeDump( double currentTime ){ painCave.isFatal = 1; simError(); } - + sendError = 0; - mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG, + mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, MPI_COMM_WORLD); - + // recieve the nodes writeLines - - for ( i = nodeAtomStart; i <= nodeAtomEnd, i++){ - - mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,procIndex, - MPI_ANY_TAG,MPI_COMM_WORLD,istatus ); - + + for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ + + mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex, + TAKE_THIS_TAG,MPI_COMM_WORLD,istatus ); + outFile << writeLine; masterIndex++; } @@ -213,17 +229,27 @@ void DumpWriter::writeDump( double currentTime ){ else if( worldRank == procIndex ){ - nodeAtomStart = entry_plug->mpiSim->getMyAtomStart(); - nodeAtomEnd = entry_plug->mpiSim->getMyAtomEnd(); + nodeAtomsStart = mpiSim->getMyAtomStart(); + nodeAtomsEnd = mpiSim->getMyAtomEnd(); - mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,MPI_ANY_TAG, + fprintf( stderr, + "node %d: myatomStart-> %d; myatomEnd-> %d\n", + worldRank, nodeAtomsStart, nodeAtomsEnd ); + + mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG, MPI_COMM_WORLD); - mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,MPI_ANY_TAG, + mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG, MPI_COMM_WORLD); - mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,MPI_ANY_TAG, + fprintf( stderr, "node %d: sent off the start and end\n", worldRank ); + + sendError = -1; + mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG, MPI_COMM_WORLD, istatus); - if (sendError) mpiCheckpoint(); + + fprintf( stderr, "node %d: value of sendError is %d\n", worldRank, sendError ); + + if (sendError) MPIcheckPoint(); // send current node's configuration line by line. @@ -259,14 +285,17 @@ void DumpWriter::writeDump( double currentTime ){ else strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); - mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,MPI_ANY_TAG, + fprintf( stderr, + "node %d: I'm sending the line:\n->%s\n", worldRank, writeLine ); + + mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG, MPI_COMM_WORLD); } } sprintf(checkPointMsg,"Node %d sent dump configuration.", procIndex); - mpiCheckPoint(); + MPIcheckPoint(); } #endif // is_mpi @@ -311,8 +340,8 @@ void DumpWriter::writeFinal(){ #ifdef IS_MPI } - sprintf(checkPointMsg,"Opened file for final configuration\n",procIndex); - mpiCheckPoint(); + sprintf(checkPointMsg,"Opened file for final configuration\n"); + MPIcheckPoint(); #endif //is_mpi @@ -322,10 +351,9 @@ void DumpWriter::writeFinal(){ finalOut << nAtoms << "\n"; - finalOut << currentTime << "\t" - << entry_plug->box_x << "\t" - << entry_plug->box_y << "\t" - << entry_plug->box_z << "\n"; + finalOut << entry_plug->box_x << "\t" + << entry_plug->box_y << "\t" + << entry_plug->box_z << "\n"; for( i=0; impiSim->getTotAtoms() << "\n"; + finalOut << mpiSim->getTotAtoms() << "\n"; - finalOut << currentTime << "\t" - << entry_plug->box_x << "\t" - << entry_plug->box_y << "\t" - << entry_plug->box_z << "\n"; - + finalOut << entry_plug->box_x << "\t" + << entry_plug->box_y << "\t" + << entry_plug->box_z << "\n"; + masterIndex = 0; + + std::cerr << "about to write node 0 aztoms. nAtoms = " << nAtoms << "\n"; + for( i=0; impiSim->getNumberProcessors(); + for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); procIndex++){ if( worldRank == 0 ){ mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex, - MPI_ANY_TAG,MPI_COMM_WORLD,istatus); + TAKE_THIS_TAG,MPI_COMM_WORLD,istatus); mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex, - MPI_ANY_TAG,MPI_COMM_WORLD, istatus); + TAKE_THIS_TAG,MPI_COMM_WORLD, istatus); // Make sure where node 0 is writing to, matches where the // receiving node expects it to be. if (masterIndex != nodeAtomsStart){ sendError = 1; - mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG, + mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, MPI_COMM_WORLD); sprintf(painCave.errMsg, "DumpWriter error: atoms start index (%d) for " @@ -451,15 +481,15 @@ void DumpWriter::writeFinal(){ } sendError = 0; - mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG, + mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, MPI_COMM_WORLD); // recieve the nodes writeLines - for ( i = nodeAtomStart; i <= nodeAtomEnd, i++){ + for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ - mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,procIndex, - MPI_ANY_TAG,MPI_COMM_WORLD,istatus ); + mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex, + TAKE_THIS_TAG,MPI_COMM_WORLD,istatus ); finalOut << writeLine; masterIndex++; @@ -470,17 +500,17 @@ void DumpWriter::writeFinal(){ else if( worldRank == procIndex ){ - nodeAtomStart = entry_plug->mpiSim->getMyAtomStart(); - nodeAtomEnd = entry_plug->mpiSim->getMyAtomEnd(); + nodeAtomsStart = mpiSim->getMyAtomStart(); + nodeAtomsEnd = mpiSim->getMyAtomEnd(); - mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,MPI_ANY_TAG, + mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG, MPI_COMM_WORLD); - mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,MPI_ANY_TAG, + mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG, MPI_COMM_WORLD); - mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,MPI_ANY_TAG, + mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG, MPI_COMM_WORLD, istatus); - if (sendError) mpiCheckpoint(); + if (sendError) MPIcheckPoint(); // send current node's configuration line by line. @@ -516,14 +546,14 @@ void DumpWriter::writeFinal(){ else strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); - mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,MPI_ANY_TAG, + mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG, MPI_COMM_WORLD); } } sprintf(checkPointMsg,"Node %d sent dump configuration.", procIndex); - mpiCheckPoint(); + MPIcheckPoint(); } if( worldRank == 0 ) finalOut.close();