--- trunk/OOPSE/libmdtools/DumpWriter.cpp 2004/01/07 19:26:12 905 +++ trunk/OOPSE/libmdtools/DumpWriter.cpp 2004/01/08 17:40:56 907 @@ -7,12 +7,9 @@ #ifdef IS_MPI #include #include "mpiSimulation.hpp" -#define TAKE_THIS_TAG_CHAR 15 -#define TAKE_THIS_TAG_INT 20 namespace dWrite{ - void nodeZeroError( void ); - void anonymousNodeDie( void ); + void DieDieDie( void ); } using namespace dWrite; @@ -69,12 +66,23 @@ void DumpWriter::writeDump( double currentTime ){ void DumpWriter::writeDump( double currentTime ){ const int BUFFERSIZE = 2000; + const int MINIBUFFERSIZE = 10; + char tempBuffer[BUFFERSIZE]; char writeLine[BUFFERSIZE]; int i; #ifdef IS_MPI int j, which_node, done, which_atom, local_index; + double atomTransData[6]; + double atomOrientData[7]; + int isDirectional; + char* atomTypeString; + int me; + int atomTypeTag; + int atomIsDirectionalTag; + int atomTransDataTag; + int atomOrientDataTag; #else //is_mpi int nAtoms = entry_plug->n_atoms; #endif //is_mpi @@ -84,7 +92,6 @@ void DumpWriter::writeDump( double currentTime ){ Atom** atoms = entry_plug->atoms; double pos[3], vel[3]; - // write current frame to the eor file this->writeFinal( currentTime ); @@ -185,52 +192,74 @@ void DumpWriter::writeDump( double currentTime ){ which_node = AtomToProcMap[i]; - if (which_node == 0 ) { + if (which_node != 0) { + + atomTypeTag = 4*i; + atomIsDirectionalTag = 4*i + 1; + atomTransDataTag = 4*i + 2; + atomOrientDataTag = 4*i + 3; + MPI_Recv(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, + atomTypeTag, MPI_COMM_WORLD, &istatus); + + MPI_Recv(&isDirectional, 1, MPI_INT, which_node, + atomIsDirectionalTag, MPI_COMM_WORLD, &istatus); + + MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node, + atomTransDataTag, MPI_COMM_WORLD, &istatus); + + if (isDirectional) { + + MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node, + atomOrientDataTag, MPI_COMM_WORLD, &istatus); + + } + + } else { + haveError = 0; which_atom = i; local_index=-1; + for (j=0; (jgetMyNlocal()) && (local_index < 0); j++) { if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; } + if (local_index != -1) { - //format the line + atomTypeString = atoms[local_index]->getType(); + atoms[local_index]->getPos(pos); atoms[local_index]->getVel(vel); - sprintf( tempBuffer, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atoms[local_index]->getType(), - pos[0], - pos[1], - pos[2], - vel[0], - vel[1], - vel[2]); // check here. - strcpy( writeLine, tempBuffer ); + atomTransData[0] = pos[0]; + atomTransData[1] = pos[1]; + atomTransData[2] = pos[2]; + atomTransData[3] = vel[0]; + atomTransData[4] = vel[1]; + atomTransData[5] = vel[2]; + + isDirectional = 0; + if( atoms[local_index]->isDirectional() ){ + isDirectional = 1; + dAtom = (DirectionalAtom *)atoms[local_index]; dAtom->getQ( q ); + + atomOrientData[0] = q[0]; + atomOrientData[1] = q[1]; + atomOrientData[2] = q[2]; + atomOrientData[3] = q[3]; - 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 ); + atomOrientData[4] = dAtom->getJx(); + atomOrientData[5] = dAtom->getJy(); + atomOrientData[6] = dAtom->getJz(); + } - } - else - strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); - } - else { + } else { sprintf(painCave.errMsg, "Atom %d not found on processor %d\n", i, worldRank ); @@ -238,114 +267,137 @@ void DumpWriter::writeDump( double currentTime ){ simError(); } - if(haveError) nodeZeroError(); + if(haveError) DieDieDie(); + + // If we've survived to here, format the line: + + sprintf( tempBuffer, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + atomTypeString, + atomTransData[0], + atomTransData[1], + atomTransData[2], + atomTransData[3], + atomTransData[4], + atomTransData[5]); - } - else { - myStatus = 1; - MPI_Send(&myStatus, 1, MPI_INT, which_node, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, - MPI_COMM_WORLD); - MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, - TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); - MPI_Recv(&myStatus, 1, MPI_INT, which_node, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + strcpy( writeLine, tempBuffer ); - if(!myStatus) nodeZeroError(); + if (isDirectional) { - } + sprintf( tempBuffer, + "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + atomOrientData[0], + atomOrientData[1], + atomOrientData[2], + atomOrientData[3], + atomOrientData[4], + atomOrientData[5], + atomOrientData[6]); + strcat( writeLine, tempBuffer ); - outFile << writeLine; - outFile.flush(); - } + } else { + strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); + } - // kill everyone off: - myStatus = -1; - for (j = 1; j < mpiSim->getNumberProcessors(); j++) { - MPI_Send(&myStatus, 1, MPI_INT, j, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); + outFile << writeLine; + outFile.flush(); + } } + outFile.flush(); + sprintf( checkPointMsg, + "Sucessfully took a dump.\n"); + MPIcheckPoint(); + } else { - done = 0; - while (!done) { + // worldRank != 0, so I'm a remote node. + + for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { + + // Am I the node which has this atom? + + if (AtomToProcMap[i] == worldRank) { - MPI_Recv(&myStatus, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + local_index=-1; + for (j=0; (jgetMyNlocal()) && (local_index < 0); j++) { + if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; + } + if (local_index != -1) { + + atomTypeString = atoms[local_index]->getType(); - if(!myStatus) anonymousNodeDie(); - - if(myStatus < 0) break; + atoms[local_index]->getPos(pos); + atoms[local_index]->getVel(vel); - MPI_Recv(&which_atom, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + atomTransData[0] = pos[0]; + atomTransData[1] = pos[1]; + atomTransData[2] = pos[2]; - myStatus = 1; - local_index=-1; - for (j=0; (jgetMyNlocal()) && (local_index < 0); j++) { - if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; - } - if (local_index != -1) { - //format the line + atomTransData[3] = vel[0]; + atomTransData[4] = vel[1]; + atomTransData[5] = vel[2]; + + isDirectional = 0; - atoms[local_index]->getPos(pos); - atoms[local_index]->getVel(vel); + if( atoms[local_index]->isDirectional() ){ - sprintf( tempBuffer, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atoms[local_index]->getType(), - pos[0], - pos[1], - pos[2], - vel[0], - vel[1], - vel[2]); // check here. - strcpy( writeLine, tempBuffer ); + isDirectional = 1; + + dAtom = (DirectionalAtom *)atoms[local_index]; + dAtom->getQ( q ); + + atomOrientData[0] = q[0]; + atomOrientData[1] = q[1]; + atomOrientData[2] = q[2]; + atomOrientData[3] = q[3]; - if( atoms[local_index]->isDirectional() ){ + atomOrientData[4] = dAtom->getJx(); + atomOrientData[5] = dAtom->getJy(); + atomOrientData[6] = dAtom->getJz(); + } - 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 { + sprintf(painCave.errMsg, + "Atom %d not found on processor %d\n", + i, worldRank ); + haveError= 1; + simError(); } - else{ - strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); - } - } - else { - sprintf(painCave.errMsg, - "Atom %d not found on processor %d\n", - which_atom, worldRank ); - myStatus = 0; - simError(); - strcpy( writeLine, "Hello, I'm an error.\n"); - } + // I've survived this far, so send off the data! - MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, - TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); - MPI_Send( &myStatus, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); + atomTypeTag = 4*i; + atomIsDirectionalTag = 4*i + 1; + atomTransDataTag = 4*i + 2; + atomOrientDataTag = 4*i + 3; + + MPI_Send(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, + atomTypeTag, MPI_COMM_WORLD); + + MPI_Send(&isDirectional, 1, MPI_INT, 0, + atomIsDirectionalTag, MPI_COMM_WORLD); + + MPI_Send(atomTransData, 6, MPI_DOUBLE, 0, + atomTransDataTag, MPI_COMM_WORLD); + + if (isDirectional) { + + MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0, + atomOrientDataTag, MPI_COMM_WORLD); + + } + + } } - } - outFile.flush(); - sprintf( checkPointMsg, - "Sucessfully took a dump.\n"); - MPIcheckPoint(); - // last thing last, enable fatalities. + sprintf( checkPointMsg, + "Sucessfully took a dump.\n"); + MPIcheckPoint(); + + } + painCave.isEventLoop = 0; #endif // is_mpi @@ -357,6 +409,7 @@ void DumpWriter::writeFinal(double finalTime){ ofstream finalOut; const int BUFFERSIZE = 2000; + const int MINIBUFFERSIZE = 10; char tempBuffer[BUFFERSIZE]; char writeLine[BUFFERSIZE]; @@ -366,6 +419,14 @@ void DumpWriter::writeFinal(double finalTime){ int i; #ifdef IS_MPI int j, which_node, done, which_atom, local_index; + double atomTransData[6]; + double atomOrientData[7]; + int isDirectional; + char* atomTypeString; + int atomTypeTag; + int atomIsDirectionalTag; + int atomTransDataTag; + int atomOrientDataTag; #else //is_mpi int nAtoms = entry_plug->n_atoms; #endif //is_mpi @@ -472,75 +533,98 @@ void DumpWriter::writeFinal(double finalTime){ // write out header and node 0's coordinates - haveError = 0; if( worldRank == 0 ){ finalOut << mpiSim->getTotAtoms() << "\n"; finalOut << finalTime << ";\t" - << entry_plug->Hmat[0][0] << "\t" - << entry_plug->Hmat[1][0] << "\t" - << entry_plug->Hmat[2][0] << ";\t" + << entry_plug->Hmat[0][0] << "\t" + << entry_plug->Hmat[1][0] << "\t" + << entry_plug->Hmat[2][0] << ";\t" - << entry_plug->Hmat[0][1] << "\t" - << entry_plug->Hmat[1][1] << "\t" - << entry_plug->Hmat[2][1] << ";\t" + << entry_plug->Hmat[0][1] << "\t" + << entry_plug->Hmat[1][1] << "\t" + << entry_plug->Hmat[2][1] << ";\t" - << entry_plug->Hmat[0][2] << "\t" - << entry_plug->Hmat[1][2] << "\t" - << entry_plug->Hmat[2][2] << ";"; + << entry_plug->Hmat[0][2] << "\t" + << entry_plug->Hmat[1][2] << "\t" + << entry_plug->Hmat[2][2] << ";"; - //write out additional parameters, such as chi and eta finalOut << entry_plug->the_integrator->getAdditionalParameters(); finalOut << endl; - + finalOut.flush(); for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { - // Get the Node number which has this molecule: + // Get the Node number which has this atom; which_node = AtomToProcMap[i]; - if (which_node == mpiSim->getMyNode()) { + if (which_node != 0) { + + atomTypeTag = 4*i; + atomIsDirectionalTag = 4*i + 1; + atomTransDataTag = 4*i + 2; + atomOrientDataTag = 4*i + 3; + MPI_Recv(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, + atomTypeTag, MPI_COMM_WORLD, &istatus); + + MPI_Recv(&isDirectional, 1, MPI_INT, which_node, + atomIsDirectionalTag, MPI_COMM_WORLD, &istatus); + + MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node, + atomTransDataTag, MPI_COMM_WORLD, &istatus); + + if (isDirectional) { + + MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node, + atomOrientDataTag, MPI_COMM_WORLD, &istatus); + + } + + } else { + + haveError = 0; which_atom = i; local_index=-1; + for (j=0; (jgetMyNlocal()) && (local_index < 0); j++) { if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; } + if (local_index != -1) { + atomTypeString = atoms[local_index]->getType(); + atoms[local_index]->getPos(pos); atoms[local_index]->getVel(vel); - sprintf( tempBuffer, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atoms[local_index]->getType(), - pos[0], - pos[1], - pos[2], - vel[0], - vel[1], - vel[2]); - strcpy( writeLine, tempBuffer ); + atomTransData[0] = pos[0]; + atomTransData[1] = pos[1]; + atomTransData[2] = pos[2]; - if( atoms[local_index]->isDirectional() ){ + atomTransData[3] = vel[0]; + atomTransData[4] = vel[1]; + atomTransData[5] = vel[2]; + + isDirectional = 0; - dAtom = (DirectionalAtom *)atoms[local_index]; - dAtom->getQ( q ); + if( atoms[local_index]->isDirectional() ){ - 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" ); - } - else { + isDirectional = 1; + + dAtom = (DirectionalAtom *)atoms[local_index]; + dAtom->getQ( q ); + + atomOrientData[0] = q[0]; + atomOrientData[1] = q[1]; + atomOrientData[2] = q[2]; + atomOrientData[3] = q[3]; + + atomOrientData[4] = dAtom->getJx(); + atomOrientData[5] = dAtom->getJy(); + atomOrientData[6] = dAtom->getJz(); + } + + } else { sprintf(painCave.errMsg, "Atom %d not found on processor %d\n", i, worldRank ); @@ -548,111 +632,138 @@ void DumpWriter::writeFinal(double finalTime){ simError(); } - if(haveError) nodeZeroError(); + if(haveError) DieDieDie(); + + // If we've survived to here, format the line: + + sprintf( tempBuffer, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + atomTypeString, + atomTransData[0], + atomTransData[1], + atomTransData[2], + atomTransData[3], + atomTransData[4], + atomTransData[5]); - } - else { + strcpy( writeLine, tempBuffer ); - myStatus = 1; - MPI_Send(&myStatus, 1, MPI_INT, which_node, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, - MPI_COMM_WORLD); - MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, - TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); - MPI_Recv(&myStatus, 1, MPI_INT, which_node, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + if (isDirectional) { - if(!myStatus) nodeZeroError(); - } + sprintf( tempBuffer, + "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", + atomOrientData[0], + atomOrientData[1], + atomOrientData[2], + atomOrientData[3], + atomOrientData[4], + atomOrientData[5], + atomOrientData[6]); + strcat( writeLine, tempBuffer ); - finalOut << writeLine; - } + } else { + strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); + } - // kill everyone off: - myStatus = -1; - for (j = 1; j < mpiSim->getNumberProcessors(); j++) { - MPI_Send(&myStatus, 1, MPI_INT, j, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); + finalOut << writeLine; + finalOut.flush(); + } } + finalOut.flush(); + sprintf( checkPointMsg, + "Sucessfully took a dump.\n"); + MPIcheckPoint(); + } else { - done = 0; - while (!done) { + // worldRank != 0, so I'm a remote node. + + for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { + + // Am I the node which has this atom? + + if (AtomToProcMap[i] == worldRank) { - MPI_Recv(&myStatus, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + local_index=-1; + for (j=0; (jgetMyNlocal()) && (local_index < 0); j++) { + if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; + } + if (local_index != -1) { + + atomTypeString = atoms[local_index]->getType(); - if(!myStatus) anonymousNodeDie(); + atoms[local_index]->getPos(pos); + atoms[local_index]->getVel(vel); - if(myStatus < 0) break; + atomTransData[0] = pos[0]; + atomTransData[1] = pos[1]; + atomTransData[2] = pos[2]; - MPI_Recv(&which_atom, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + atomTransData[3] = vel[0]; + atomTransData[4] = vel[1]; + atomTransData[5] = vel[2]; + + isDirectional = 0; - myStatus = 1; - local_index=-1; - for (j=0; j < mpiSim->getMyNlocal(); j++) { - if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; - } - if (local_index != -1) { + if( atoms[local_index]->isDirectional() ){ - atoms[local_index]->getPos(pos); - atoms[local_index]->getVel(vel); + isDirectional = 1; + + dAtom = (DirectionalAtom *)atoms[local_index]; + dAtom->getQ( q ); + + atomOrientData[0] = q[0]; + atomOrientData[1] = q[1]; + atomOrientData[2] = q[2]; + atomOrientData[3] = q[3]; - //format the line - sprintf( tempBuffer, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - atoms[local_index]->getType(), - pos[0], - pos[1], - pos[2], - vel[0], - vel[1], - vel[2]); // check here. - strcpy( writeLine, tempBuffer ); + atomOrientData[4] = dAtom->getJx(); + atomOrientData[5] = dAtom->getJy(); + atomOrientData[6] = dAtom->getJz(); + } - if( atoms[local_index]->isDirectional() ){ + } else { + sprintf(painCave.errMsg, + "Atom %d not found on processor %d\n", + i, worldRank ); + haveError= 1; + simError(); + } - dAtom = (DirectionalAtom *)atoms[local_index]; - dAtom->getQ( q ); + // I've survived this far, so send off the data! - 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" ); - } - } - else { - sprintf(painCave.errMsg, - "Atom %d not found on processor %d\n", - which_atom, worldRank ); - myStatus = 0; - simError(); + atomTypeTag = 4*i; + atomIsDirectionalTag = 4*i + 1; + atomTransDataTag = 4*i + 2; + atomOrientDataTag = 4*i + 3; - strcpy( writeLine, "Hello, I'm an error.\n"); - } + MPI_Send(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, + atomTypeTag, MPI_COMM_WORLD); + + MPI_Send(&isDirectional, 1, MPI_INT, 0, + atomIsDirectionalTag, MPI_COMM_WORLD); + + MPI_Send(atomTransData, 6, MPI_DOUBLE, 0, + atomTransDataTag, MPI_COMM_WORLD); - MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, - TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); - MPI_Send( &myStatus, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); + if (isDirectional) { + + MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0, + atomOrientDataTag, MPI_COMM_WORLD); + + } + + } } + + sprintf( checkPointMsg, + "Sucessfully wrote final file.\n"); + MPIcheckPoint(); + } - finalOut.flush(); - sprintf( checkPointMsg, - "Sucessfully took a dump.\n"); - MPIcheckPoint(); + + painCave.isEventLoop = 0; if( worldRank == 0 ) finalOut.close(); #endif // is_mpi @@ -664,25 +775,10 @@ void dWrite::nodeZeroError( void ){ // a couple of functions to let us escape the write loop -void dWrite::nodeZeroError( void ){ - int j, myStatus; +void dWrite::DieDieDie( void ){ - myStatus = 0; - for (j = 0; j < mpiSim->getNumberProcessors(); j++) { - MPI_Send( &myStatus, 1, MPI_INT, j, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - } - - MPI_Finalize(); exit (0); - } -void dWrite::anonymousNodeDie( void ){ - - MPI_Finalize(); - exit (0); -} - #endif //is_mpi