--- trunk/src/io/DumpWriter.cpp 2005/03/03 14:40:20 395 +++ trunk/src/io/DumpWriter.cpp 2006/05/19 21:26:41 966 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -43,91 +43,169 @@ #include "primitives/Molecule.hpp" #include "utils/simError.h" #include "io/basic_teebuf.hpp" +#include "io/gzstream.hpp" +#include "io/Globals.hpp" + #ifdef IS_MPI #include #endif //is_mpi namespace oopse { -DumpWriter::DumpWriter(SimInfo* info) - : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ + DumpWriter::DumpWriter(SimInfo* info) + : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ + + Globals* simParams = info->getSimParams(); + needCompression_ = simParams->getCompressDumpFile(); + needForceVector_ = simParams->getOutputForceVector(); + createDumpFile_ = true; +#ifdef HAVE_LIBZ + if (needCompression_) { + filename_ += ".gz"; + eorFilename_ += ".gz"; + } +#endif + #ifdef IS_MPI - if (worldRank == 0) { + if (worldRank == 0) { #endif // is_mpi - dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); + + dumpFile_ = createOStream(filename_); if (!dumpFile_) { - sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", - filename_.c_str()); - painCave.isFatal = 1; - simError(); + sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", + filename_.c_str()); + painCave.isFatal = 1; + simError(); } #ifdef IS_MPI - } + } - sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); - MPIcheckPoint(); + sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); + MPIcheckPoint(); #endif // is_mpi -} + } -DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) - : info_(info), filename_(filename){ + DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) + : info_(info), filename_(filename){ + + Globals* simParams = info->getSimParams(); + eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; + + needCompression_ = simParams->getCompressDumpFile(); + needForceVector_ = simParams->getOutputForceVector(); + createDumpFile_ = true; +#ifdef HAVE_LIBZ + if (needCompression_) { + filename_ += ".gz"; + eorFilename_ += ".gz"; + } +#endif + #ifdef IS_MPI - if (worldRank == 0) { + if (worldRank == 0) { #endif // is_mpi - eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; - dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); + + dumpFile_ = createOStream(filename_); if (!dumpFile_) { - sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", - filename_.c_str()); - painCave.isFatal = 1; - simError(); + sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", + filename_.c_str()); + painCave.isFatal = 1; + simError(); } #ifdef IS_MPI - } + } + sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); + MPIcheckPoint(); + +#endif // is_mpi + + } + + DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile) + : info_(info), filename_(filename){ + + Globals* simParams = info->getSimParams(); + eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; + + needCompression_ = simParams->getCompressDumpFile(); + needForceVector_ = simParams->getOutputForceVector(); + +#ifdef HAVE_LIBZ + if (needCompression_) { + filename_ += ".gz"; + eorFilename_ += ".gz"; + } +#endif + +#ifdef IS_MPI + + if (worldRank == 0) { +#endif // is_mpi + + createDumpFile_ = writeDumpFile; + if (createDumpFile_) { + dumpFile_ = createOStream(filename_); + + if (!dumpFile_) { + sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", + filename_.c_str()); + painCave.isFatal = 1; + simError(); + } + } +#ifdef IS_MPI + + } + sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); MPIcheckPoint(); - + #endif // is_mpi + + } + + + + + -} + DumpWriter::~DumpWriter() { -DumpWriter::~DumpWriter() { - #ifdef IS_MPI if (worldRank == 0) { #endif // is_mpi - - dumpFile_.close(); - + if (createDumpFile_){ + delete dumpFile_; + } #ifdef IS_MPI } #endif // is_mpi -} + } -void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) { + void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) { - double currentTime; + RealType currentTime; Mat3x3d hmat; - double chi; - double integralOfChiDt; + RealType chi; + RealType integralOfChiDt; Mat3x3d eta; currentTime = s->getTime(); @@ -137,22 +215,22 @@ void DumpWriter::writeCommentLine(std::ostream& os, Sn eta = s->getEta(); os << currentTime << ";\t" - << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t" - << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t" - << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t"; + << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t" + << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t" + << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t"; //write out additional parameters, such as chi and eta - os << chi << "\t" << integralOfChiDt << "\t;"; + os << chi << "\t" << integralOfChiDt << ";\t"; os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t" - << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" - << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; + << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" + << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; os << "\n"; -} + } -void DumpWriter::writeFrame(std::ostream& os) { + void DumpWriter::writeFrame(std::ostream& os) { const int BUFFERSIZE = 2000; const int MINIBUFFERSIZE = 100; @@ -163,6 +241,8 @@ void DumpWriter::writeFrame(std::ostream& os) { Vector3d ji; Vector3d pos; Vector3d vel; + Vector3d frc; + Vector3d trq; Molecule* mol; StuntDouble* integrableObject; @@ -181,35 +261,46 @@ void DumpWriter::writeFrame(std::ostream& os) { for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { - for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { + for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; + integrableObject = mol->nextIntegrableObject(ii)) { - pos = integrableObject->getPos(); - vel = integrableObject->getVel(); + pos = integrableObject->getPos(); + vel = integrableObject->getVel(); - sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - integrableObject->getType().c_str(), - pos[0], pos[1], pos[2], - vel[0], vel[1], vel[2]); + sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + integrableObject->getType().c_str(), + pos[0], pos[1], pos[2], + vel[0], vel[1], vel[2]); - strcpy(writeLine, tempBuffer); + strcpy(writeLine, tempBuffer); - if (integrableObject->isDirectional()) { - q = integrableObject->getQ(); - ji = integrableObject->getJ(); + if (integrableObject->isDirectional()) { + q = integrableObject->getQ(); + ji = integrableObject->getJ(); - sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", - q[0], q[1], q[2], q[3], - ji[0], ji[1], ji[2]); - strcat(writeLine, tempBuffer); - } else { - strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); - } + sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + q[0], q[1], q[2], q[3], + ji[0], ji[1], ji[2]); + strcat(writeLine, tempBuffer); + } else { + strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); + } - os << writeLine; + if (needForceVector_) { + frc = integrableObject->getFrc(); + trq = integrableObject->getTrq(); + + sprintf(tempBuffer, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + frc[0], frc[1], frc[2], + trq[0], trq[1], trq[2]); + strcat(writeLine, tempBuffer); + } + + strcat(writeLine, "\n"); + os << writeLine; - } + } } os.flush(); @@ -256,7 +347,7 @@ void DumpWriter::writeFrame(std::ostream& os) { int myPotato; int nProc; int which_node; - double atomData[13]; + RealType atomData[19]; int isDirectional; char MPIatomTypeString[MINIBUFFERSIZE]; int msgLen; // the length of message actually recieved at master nodes @@ -271,352 +362,438 @@ void DumpWriter::writeFrame(std::ostream& os) { MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); if (flag) { - MAXTAG = *tagub; + MAXTAG = *tagub; } else { - MAXTAG = 32767; + MAXTAG = 32767; } if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file - // Node 0 needs a list of the magic potatoes for each processor; + // Node 0 needs a list of the magic potatoes for each processor; - MPI_Comm_size(MPI_COMM_WORLD, &nProc); - potatoes = new int[nProc]; + MPI_Comm_size(MPI_COMM_WORLD, &nProc); + potatoes = new int[nProc]; - //write out the comment lines - for(int i = 0; i < nProc; i++) { - potatoes[i] = 0; - } + //write out the comment lines + for(int i = 0; i < nProc; i++) { + potatoes[i] = 0; + } - os << nTotObjects << "\n"; - writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); + os << nTotObjects << "\n"; + writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); - for(int i = 0; i < info_->getNGlobalMolecules(); i++) { + for(int i = 0; i < info_->getNGlobalMolecules(); i++) { - // Get the Node number which has this atom; + // Get the Node number which has this atom; - which_node = info_->getMolToProc(i); - - if (which_node != masterNode) { //current molecule is in slave node - if (potatoes[which_node] + 1 >= MAXTAG) { - // The potato was going to exceed the maximum value, - // so wrap this processor potato back to 0: + which_node = info_->getMolToProc(i); - potatoes[which_node] = 0; - MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, - MPI_COMM_WORLD); - } + if (which_node != masterNode) { //current molecule is in slave node + if (potatoes[which_node] + 1 >= MAXTAG) { + // The potato was going to exceed the maximum value, + // so wrap this processor potato back to 0: - myPotato = potatoes[which_node]; + potatoes[which_node] = 0; + MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, + MPI_COMM_WORLD); + } - //recieve the number of integrableObject in current molecule - MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, - MPI_COMM_WORLD, &istatus); - myPotato++; + myPotato = potatoes[which_node]; - for(int l = 0; l < nCurObj; l++) { - if (potatoes[which_node] + 2 >= MAXTAG) { - // The potato was going to exceed the maximum value, - // so wrap this processor potato back to 0: + //recieve the number of integrableObject in current molecule + MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, + MPI_COMM_WORLD, &istatus); + myPotato++; - potatoes[which_node] = 0; - MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, - 0, MPI_COMM_WORLD); - } + for(int l = 0; l < nCurObj; l++) { + if (potatoes[which_node] + 2 >= MAXTAG) { + // The potato was going to exceed the maximum value, + // so wrap this processor potato back to 0: - MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, - which_node, myPotato, MPI_COMM_WORLD, - &istatus); + potatoes[which_node] = 0; + MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, + 0, MPI_COMM_WORLD); + } - myPotato++; + MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, + which_node, myPotato, MPI_COMM_WORLD, + &istatus); - MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, - MPI_COMM_WORLD, &istatus); - myPotato++; + myPotato++; - MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); + MPI_Recv(atomData, 19, MPI_REALTYPE, which_node, myPotato, + MPI_COMM_WORLD, &istatus); + myPotato++; - if (msgLen == 13) - isDirectional = 1; - else - isDirectional = 0; + MPI_Get_count(&istatus, MPI_REALTYPE, &msgLen); - // If we've survived to here, format the line: + if (msgLen == 13 || msgLen == 19) + isDirectional = 1; + else + isDirectional = 0; - if (!isDirectional) { - sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - MPIatomTypeString, atomData[0], - atomData[1], atomData[2], - atomData[3], atomData[4], - atomData[5]); + // If we've survived to here, format the line: - strcat(writeLine, - "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); - } else { - sprintf(writeLine, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", - MPIatomTypeString, - atomData[0], - atomData[1], - atomData[2], - atomData[3], - atomData[4], - atomData[5], - atomData[6], - atomData[7], - atomData[8], - atomData[9], - atomData[10], - atomData[11], - atomData[12]); - } + if (!isDirectional) { + sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + MPIatomTypeString, atomData[0], + atomData[1], atomData[2], + atomData[3], atomData[4], + atomData[5]); - os << writeLine; + strcat(writeLine, + "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); + } else { + sprintf(writeLine, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + MPIatomTypeString, + atomData[0], + atomData[1], + atomData[2], + atomData[3], + atomData[4], + atomData[5], + atomData[6], + atomData[7], + atomData[8], + atomData[9], + atomData[10], + atomData[11], + atomData[12]); + } + + if (needForceVector_) { + if (!isDirectional) { + sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + atomData[6], + atomData[7], + atomData[8], + atomData[9], + atomData[10], + atomData[11]); + } else { + sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + atomData[13], + atomData[14], + atomData[15], + atomData[16], + atomData[17], + atomData[18]); + } + } - } // end for(int l =0) + os << writeLine << "\n"; - potatoes[which_node] = myPotato; - } else { //master node has current molecule + } // end for(int l =0) - mol = info_->getMoleculeByGlobalIndex(i); + potatoes[which_node] = myPotato; + } else { //master node has current molecule - if (mol == NULL) { - sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); - painCave.isFatal = 1; - simError(); - } + mol = info_->getMoleculeByGlobalIndex(i); + + if (mol == NULL) { + sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); + painCave.isFatal = 1; + simError(); + } - for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { + for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; + integrableObject = mol->nextIntegrableObject(ii)) { - pos = integrableObject->getPos(); - vel = integrableObject->getVel(); + pos = integrableObject->getPos(); + vel = integrableObject->getVel(); - atomData[0] = pos[0]; - atomData[1] = pos[1]; - atomData[2] = pos[2]; + atomData[0] = pos[0]; + atomData[1] = pos[1]; + atomData[2] = pos[2]; - atomData[3] = vel[0]; - atomData[4] = vel[1]; - atomData[5] = vel[2]; + atomData[3] = vel[0]; + atomData[4] = vel[1]; + atomData[5] = vel[2]; - isDirectional = 0; + isDirectional = 0; - if (integrableObject->isDirectional()) { - isDirectional = 1; + if (integrableObject->isDirectional()) { + isDirectional = 1; - q = integrableObject->getQ(); - ji = integrableObject->getJ(); + q = integrableObject->getQ(); + ji = integrableObject->getJ(); - for(int j = 0; j < 6; j++) { - atomData[j] = atomData[j]; - } + for(int j = 0; j < 6; j++) { + atomData[j] = atomData[j]; + } - atomData[6] = q[0]; - atomData[7] = q[1]; - atomData[8] = q[2]; - atomData[9] = q[3]; + atomData[6] = q[0]; + atomData[7] = q[1]; + atomData[8] = q[2]; + atomData[9] = q[3]; - atomData[10] = ji[0]; - atomData[11] = ji[1]; - atomData[12] = ji[2]; - } + atomData[10] = ji[0]; + atomData[11] = ji[1]; + atomData[12] = ji[2]; + } - // If we've survived to here, format the line: + if (needForceVector_) { + frc = integrableObject->getFrc(); + trq = integrableObject->getTrq(); - if (!isDirectional) { - sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", - integrableObject->getType().c_str(), atomData[0], - atomData[1], atomData[2], - atomData[3], atomData[4], - atomData[5]); + if (!isDirectional) { + atomData[6] = frc[0]; + atomData[7] = frc[1]; + atomData[8] = frc[2]; + atomData[9] = trq[0]; + atomData[10] = trq[1]; + atomData[11] = trq[2]; + } else { + atomData[13] = frc[0]; + atomData[14] = frc[1]; + atomData[15] = frc[2]; + atomData[16] = trq[0]; + atomData[17] = trq[1]; + atomData[18] = trq[2]; + } + } - strcat(writeLine, - "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); - } else { - sprintf(writeLine, - "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", - integrableObject->getType().c_str(), - atomData[0], - atomData[1], - atomData[2], - atomData[3], - atomData[4], - atomData[5], - atomData[6], - atomData[7], - atomData[8], - atomData[9], - atomData[10], - atomData[11], - atomData[12]); - } + // If we've survived to here, format the line: + if (!isDirectional) { + sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", + integrableObject->getType().c_str(), atomData[0], + atomData[1], atomData[2], + atomData[3], atomData[4], + atomData[5]); - os << writeLine; + strcat(writeLine, + "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"); + } else { + sprintf(writeLine, + "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + integrableObject->getType().c_str(), + atomData[0], + atomData[1], + atomData[2], + atomData[3], + atomData[4], + atomData[5], + atomData[6], + atomData[7], + atomData[8], + atomData[9], + atomData[10], + atomData[11], + atomData[12]); + } - } //end for(iter = integrableObject.begin()) - } - } //end for(i = 0; i < mpiSim->getNmol()) + if (needForceVector_) { + if (!isDirectional) { + sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + atomData[6], + atomData[7], + atomData[8], + atomData[9], + atomData[10], + atomData[11]); + } else { + sprintf(writeLine, "\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf", + atomData[13], + atomData[14], + atomData[15], + atomData[16], + atomData[17], + atomData[18]); + } + } - os.flush(); + os << writeLine << "\n"; + + } //end for(iter = integrableObject.begin()) + } + } //end for(i = 0; i < mpiSim->getNmol()) + + os.flush(); - sprintf(checkPointMsg, "Sucessfully took a dump.\n"); - MPIcheckPoint(); + sprintf(checkPointMsg, "Sucessfully took a dump.\n"); + MPIcheckPoint(); - delete [] potatoes; + delete [] potatoes; } else { - // worldRank != 0, so I'm a remote node. + // worldRank != 0, so I'm a remote node. - // Set my magic potato to 0: + // Set my magic potato to 0: - myPotato = 0; + myPotato = 0; - for(int i = 0; i < info_->getNGlobalMolecules(); i++) { + for(int i = 0; i < info_->getNGlobalMolecules(); i++) { - // Am I the node which has this integrableObject? - int whichNode = info_->getMolToProc(i); - if (whichNode == worldRank) { - if (myPotato + 1 >= MAXTAG) { + // Am I the node which has this integrableObject? + int whichNode = info_->getMolToProc(i); + if (whichNode == worldRank) { + if (myPotato + 1 >= MAXTAG) { - // The potato was going to exceed the maximum value, - // so wrap this processor potato back to 0 (and block until - // node 0 says we can go: + // The potato was going to exceed the maximum value, + // so wrap this processor potato back to 0 (and block until + // node 0 says we can go: - MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, - &istatus); - } + MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, + &istatus); + } - mol = info_->getMoleculeByGlobalIndex(i); + mol = info_->getMoleculeByGlobalIndex(i); - nCurObj = mol->getNIntegrableObjects(); + nCurObj = mol->getNIntegrableObjects(); - MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); - myPotato++; + MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); + myPotato++; - for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { + for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; + integrableObject = mol->nextIntegrableObject(ii)) { - if (myPotato + 2 >= MAXTAG) { + if (myPotato + 2 >= MAXTAG) { - // The potato was going to exceed the maximum value, - // so wrap this processor potato back to 0 (and block until - // node 0 says we can go: + // The potato was going to exceed the maximum value, + // so wrap this processor potato back to 0 (and block until + // node 0 says we can go: - MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, - &istatus); - } + MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, + &istatus); + } - pos = integrableObject->getPos(); - vel = integrableObject->getVel(); + pos = integrableObject->getPos(); + vel = integrableObject->getVel(); - atomData[0] = pos[0]; - atomData[1] = pos[1]; - atomData[2] = pos[2]; + atomData[0] = pos[0]; + atomData[1] = pos[1]; + atomData[2] = pos[2]; - atomData[3] = vel[0]; - atomData[4] = vel[1]; - atomData[5] = vel[2]; + atomData[3] = vel[0]; + atomData[4] = vel[1]; + atomData[5] = vel[2]; - isDirectional = 0; + isDirectional = 0; - if (integrableObject->isDirectional()) { - isDirectional = 1; + if (integrableObject->isDirectional()) { + isDirectional = 1; - q = integrableObject->getQ(); - ji = integrableObject->getJ(); + q = integrableObject->getQ(); + ji = integrableObject->getJ(); - atomData[6] = q[0]; - atomData[7] = q[1]; - atomData[8] = q[2]; - atomData[9] = q[3]; + atomData[6] = q[0]; + atomData[7] = q[1]; + atomData[8] = q[2]; + atomData[9] = q[3]; - atomData[10] = ji[0]; - atomData[11] = ji[1]; - atomData[12] = ji[2]; - } + atomData[10] = ji[0]; + atomData[11] = ji[1]; + atomData[12] = ji[2]; + } - strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE); + if (needForceVector_) { + frc = integrableObject->getFrc(); + trq = integrableObject->getTrq(); + + if (!isDirectional) { + atomData[6] = frc[0]; + atomData[7] = frc[1]; + atomData[8] = frc[2]; + + atomData[9] = trq[0]; + atomData[10] = trq[1]; + atomData[11] = trq[2]; + } else { + atomData[13] = frc[0]; + atomData[14] = frc[1]; + atomData[15] = frc[2]; + + atomData[16] = trq[0]; + atomData[17] = trq[1]; + atomData[18] = trq[2]; + } + } - // null terminate the std::string before sending (just in case): - MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; + strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE); - MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, - myPotato, MPI_COMM_WORLD); + // null terminate the std::string before sending (just in case): + MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; - myPotato++; + MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, + myPotato, MPI_COMM_WORLD); - if (isDirectional) { - MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato, - MPI_COMM_WORLD); - } else { - MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato, - MPI_COMM_WORLD); - } + myPotato++; - myPotato++; - } + if (isDirectional && needForceVector_) { + MPI_Send(atomData, 19, MPI_REALTYPE, 0, myPotato, + MPI_COMM_WORLD); + } else if (isDirectional) { + MPI_Send(atomData, 13, MPI_REALTYPE, 0, myPotato, + MPI_COMM_WORLD); + } else if (needForceVector_) { + MPI_Send(atomData, 12, MPI_REALTYPE, 0, myPotato, + MPI_COMM_WORLD); + } else { + MPI_Send(atomData, 6, MPI_REALTYPE, 0, myPotato, + MPI_COMM_WORLD); + } + + myPotato++; + } - } + } - } - sprintf(checkPointMsg, "Sucessfully took a dump.\n"); - MPIcheckPoint(); + } + sprintf(checkPointMsg, "Sucessfully took a dump.\n"); + MPIcheckPoint(); } #endif // is_mpi -} + } -void DumpWriter::writeDump() { - writeFrame(dumpFile_); + void DumpWriter::writeDump() { + writeFrame(*dumpFile_); + } -} - -void DumpWriter::writeEor() { - std::ofstream eorStream; + void DumpWriter::writeEor() { + std::ostream* eorStream; #ifdef IS_MPI if (worldRank == 0) { #endif // is_mpi - eorStream.open(eorFilename_.c_str()); - if (!eorStream.is_open()) { - sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", - eorFilename_.c_str()); - painCave.isFatal = 1; - simError(); - } + eorStream = createOStream(eorFilename_); #ifdef IS_MPI } #endif // is_mpi - writeFrame(eorStream); -} + writeFrame(*eorStream); +#ifdef IS_MPI + if (worldRank == 0) { +#endif // is_mpi + delete eorStream; -void DumpWriter::writeDumpAndEor() { - std::ofstream eorStream; +#ifdef IS_MPI + } +#endif // is_mpi + + } + + + void DumpWriter::writeDumpAndEor() { std::vector buffers; + std::ostream* eorStream; #ifdef IS_MPI if (worldRank == 0) { #endif // is_mpi - buffers.push_back(dumpFile_.rdbuf()); + buffers.push_back(dumpFile_->rdbuf()); - eorStream.open(eorFilename_.c_str()); - if (!eorStream.is_open()) { - sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", - eorFilename_.c_str()); - painCave.isFatal = 1; - simError(); - } + eorStream = createOStream(eorFilename_); - buffers.push_back(eorStream.rdbuf()); + buffers.push_back(eorStream->rdbuf()); #ifdef IS_MPI } @@ -626,9 +803,31 @@ void DumpWriter::writeDumpAndEor() { std::ostream os(&tbuf); writeFrame(os); + +#ifdef IS_MPI + if (worldRank == 0) { +#endif // is_mpi + delete eorStream; + +#ifdef IS_MPI + } +#endif // is_mpi -} + } +std::ostream* DumpWriter::createOStream(const std::string& filename) { + std::ostream* newOStream; +#ifdef HAVE_LIBZ + if (needCompression_) { + newOStream = new ogzstream(filename.c_str()); + } else { + newOStream = new std::ofstream(filename.c_str()); + } +#else + newOStream = new std::ofstream(filename.c_str()); +#endif + return newOStream; +} }//end namespace oopse