--- trunk/mdtools/md_code/DumpWriter.cpp 2002/12/19 21:59:51 215 +++ trunk/mdtools/md_code/DumpWriter.cpp 2003/01/31 21:04:27 260 @@ -5,6 +5,7 @@ #ifdef IS_MPI #include #include "mpiSimulation.hpp" +#define TAKE_THIS_TAG 0 #endif //is_mpi #include "ReadWrite.hpp" @@ -41,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 } @@ -60,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; @@ -130,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" @@ -170,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 " @@ -201,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++; } @@ -220,18 +229,28 @@ 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. for( i=0; i%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 @@ -318,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 @@ -329,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 " @@ -458,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++; @@ -477,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. @@ -523,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();