--- trunk/mdtools/md_code/DumpWriter.cpp 2002/12/16 21:42:14 214 +++ trunk/mdtools/md_code/DumpWriter.cpp 2003/02/03 21:15:59 261 @@ -1,24 +1,32 @@ #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 ){ + entry_plug = the_entry_plug; + #ifdef IS_MPI if(worldRank == 0 ){ #endif // is_mpi - entry_plug = the_entry_plug; + strcpy( outName, entry_plug->sampleName ); - std::cerr << "Opening " << outName << " for dumping.\n"; - outFile.open(outName, ios::out | ios::trunc ); if( !outFile ){ @@ -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; @@ -74,6 +86,7 @@ void DumpWriter::writeDump( double currentTime ){ for( i=0; igetType(), @@ -123,7 +136,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 +176,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 +211,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,22 +230,24 @@ void DumpWriter::writeDump( double currentTime ){ else if( worldRank == procIndex ){ - nodeAtomStart = entry_plug->mpiSim->getMyAtomStart(); - nodeAtomEnd = entry_plug->mpiSim->getMyAtomEnd(); - - mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,MPI_ANY_TAG, + nodeAtomsStart = mpiSim->getMyAtomStart(); + nodeAtomsEnd = mpiSim->getMyAtomEnd(); + + 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, + sendError = -1; + 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. for( i=0; igetType(), @@ -237,7 +256,7 @@ void DumpWriter::writeDump( double currentTime ){ atoms[i]->getZ(), atoms[i]->get_vx(), atoms[i]->get_vy(), - atoms[i]->get_vz()); + atoms[i]->get_vz()); // check here. strcpy( writeLine, tempBuffer ); if( atoms[i]->isDirectional() ){ @@ -259,14 +278,14 @@ 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, + 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 +330,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 +341,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; + 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 +469,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 +488,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 +534,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();