--- trunk/src/brains/SimCreator.cpp 2012/08/30 17:18:22 1790 +++ trunk/src/brains/SimCreator.cpp 2012/11/08 14:23:43 1810 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. + * copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a * non-exclusive, royalty free, license to use, modify and @@ -100,33 +100,33 @@ namespace OpenMD { #ifdef IS_MPI int streamSize; const int masterNode = 0; - int commStatus; + if (worldRank == masterNode) { - commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(&mdFileVersion, 1, MPI::INT, masterNode); #endif SimplePreprocessor preprocessor; - preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, ppStream); + preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, + ppStream); #ifdef IS_MPI //brocasting the stream size streamSize = ppStream.str().size() +1; - commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); - - commStatus = MPI_Bcast(static_cast(const_cast(ppStream.str().c_str())), streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); - + MPI::COMM_WORLD.Bcast(&streamSize, 1, MPI::LONG, masterNode); + MPI::COMM_WORLD.Bcast(static_cast(const_cast(ppStream.str().c_str())), + streamSize, MPI::CHAR, masterNode); } else { - commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(&mdFileVersion, 1, MPI::INT, masterNode); //get stream size - commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(&streamSize, 1, MPI::LONG, masterNode); char* buf = new char[streamSize]; assert(buf); //receive file content - commStatus = MPI_Bcast(buf, streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(buf, streamSize, MPI::CHAR, masterNode); ppStream.str(buf); delete [] buf; @@ -255,11 +255,28 @@ namespace OpenMD { std::string mdRawData; int metaDataBlockStart = -1; int metaDataBlockEnd = -1; - int i; + int i, j; streamoff mdOffset(0); int mdFileVersion; + // Create a string for embedding the version information in the MetaData + std::string version; + version.assign("## Last run using OpenMD Version: "); + version.append(OPENMD_VERSION_MAJOR); + version.append("."); + version.append(OPENMD_VERSION_MINOR); + std::string svnrev; + //convert a macro from compiler to a string in c++ + STR_DEFINE(svnrev, SVN_REV ); + version.append(" Revision: "); + // If there's no SVN revision, just call this the RELEASE revision. + if (!svnrev.empty()) { + version.append(svnrev); + } else { + version.append("RELEASE"); + } + #ifdef IS_MPI const int masterNode = 0; if (worldRank == masterNode) { @@ -354,12 +371,23 @@ namespace OpenMD { mdRawData.clear(); + bool foundVersion = false; + for (int i = 0; i < metaDataBlockEnd - metaDataBlockStart - 1; ++i) { mdFile_.getline(buffer, bufferSize); - mdRawData += buffer; + std::string line = trimLeftCopy(buffer); + j = CaseInsensitiveFind(line, "## Last run using OpenMD Version"); + if (static_cast(j) != string::npos) { + foundVersion = true; + mdRawData += version; + } else { + mdRawData += buffer; + } mdRawData += "\n"; } - + + if (!foundVersion) mdRawData += version + "\n"; + mdFile_.close(); #ifdef IS_MPI @@ -499,7 +527,6 @@ namespace OpenMD { int nTarget; int done; int i; - int j; int loops; int which_proc; int nProcessors; @@ -507,7 +534,7 @@ namespace OpenMD { int nGlobalMols = info->getNGlobalMolecules(); std::vector molToProcMap(nGlobalMols, -1); // default to an error condition: - MPI_Comm_size(MPI_COMM_WORLD, &nProcessors); + nProcessors = MPI::COMM_WORLD.Get_size(); if (nProcessors > nGlobalMols) { sprintf(painCave.errMsg, @@ -545,6 +572,7 @@ namespace OpenMD { nTarget = (int)(precast + 0.5); for(i = 0; i < nGlobalMols; i++) { + done = 0; loops = 0; @@ -569,13 +597,15 @@ namespace OpenMD { // and be done with it. if (loops > 100) { + sprintf(painCave.errMsg, - "I've tried 100 times to assign molecule %d to a " - " processor, but can't find a good spot.\n" - "I'm assigning it at random to processor %d.\n", + "There have been 100 attempts to assign molecule %d to an\n" + "\tunderworked processor, but there's no good place to\n" + "\tleave it. OpenMD is assigning it at random to processor %d.\n", i, which_proc); - + painCave.isFatal = 0; + painCave.severity = OPENMD_INFO; simError(); molToProcMap[i] = which_proc; @@ -620,15 +650,14 @@ namespace OpenMD { } delete myRandom; - + // Spray out this nonsense to all other processors: - - MPI_Bcast(&molToProcMap[0], nGlobalMols, MPI_INT, 0, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(&molToProcMap[0], nGlobalMols, MPI::INT, 0); } else { // Listen to your marching orders from processor 0: - - MPI_Bcast(&molToProcMap[0], nGlobalMols, MPI_INT, 0, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(&molToProcMap[0], nGlobalMols, MPI::INT, 0); + } info->setMolToProcMap(molToProcMap); @@ -786,6 +815,7 @@ namespace OpenMD { int beginRigidBodyIndex; int beginCutoffGroupIndex; int nGlobalAtoms = info->getNGlobalAtoms(); + int nGlobalRigidBodies = info->getNGlobalRigidBodies(); beginAtomIndex = 0; //rigidbody's index begins right after atom's @@ -852,28 +882,36 @@ namespace OpenMD { // This would be prettier if we could use MPI_IN_PLACE like the MPI-2 // docs said we could. std::vector tmpGroupMembership(info->getNGlobalAtoms(), 0); - MPI_Allreduce(&globalGroupMembership[0], &tmpGroupMembership[0], nGlobalAtoms, - MPI_INT, MPI_SUM, MPI_COMM_WORLD); + MPI::COMM_WORLD.Allreduce(&globalGroupMembership[0], + &tmpGroupMembership[0], nGlobalAtoms, + MPI::INT, MPI::SUM); info->setGlobalGroupMembership(tmpGroupMembership); #else info->setGlobalGroupMembership(globalGroupMembership); #endif //fill molMembership - std::vector globalMolMembership(info->getNGlobalAtoms(), 0); + std::vector globalMolMembership(info->getNGlobalAtoms() + + info->getNGlobalRigidBodies(), 0); - for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { + for(mol = info->beginMolecule(mi); mol != NULL; + mol = info->nextMolecule(mi)) { for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { globalMolMembership[atom->getGlobalIndex()] = mol->getGlobalIndex(); } + for (rb = mol->beginRigidBody(ri); rb != NULL; + rb = mol->nextRigidBody(ri)) { + globalMolMembership[rb->getGlobalIndex()] = mol->getGlobalIndex(); + } } #ifdef IS_MPI - std::vector tmpMolMembership(info->getNGlobalAtoms(), 0); + std::vector tmpMolMembership(info->getNGlobalAtoms() + + info->getNGlobalRigidBodies(), 0); + MPI::COMM_WORLD.Allreduce(&globalMolMembership[0], &tmpMolMembership[0], + nGlobalAtoms + nGlobalRigidBodies, + MPI::INT, MPI::SUM); - MPI_Allreduce(&globalMolMembership[0], &tmpMolMembership[0], nGlobalAtoms, - MPI_INT, MPI_SUM, MPI_COMM_WORLD); - info->setGlobalMolMembership(tmpMolMembership); #else info->setGlobalMolMembership(globalMolMembership); @@ -883,14 +921,15 @@ namespace OpenMD { // here the molecules are listed by their global indices. std::vector nIOPerMol(info->getNGlobalMolecules(), 0); - for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { + for (mol = info->beginMolecule(mi); mol != NULL; + mol = info->nextMolecule(mi)) { nIOPerMol[mol->getGlobalIndex()] = mol->getNIntegrableObjects(); } #ifdef IS_MPI std::vector numIntegrableObjectsPerMol(info->getNGlobalMolecules(), 0); - MPI_Allreduce(&nIOPerMol[0], &numIntegrableObjectsPerMol[0], - info->getNGlobalMolecules(), MPI_INT, MPI_SUM, MPI_COMM_WORLD); + MPI::COMM_WORLD.Allreduce(&nIOPerMol[0], &numIntegrableObjectsPerMol[0], + info->getNGlobalMolecules(), MPI::INT, MPI::SUM); #else std::vector numIntegrableObjectsPerMol = nIOPerMol; #endif @@ -904,7 +943,8 @@ namespace OpenMD { } std::vector IOIndexToIntegrableObject(info->getNGlobalIntegrableObjects(), (StuntDouble*)NULL); - for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { + for (mol = info->beginMolecule(mi); mol != NULL; + mol = info->nextMolecule(mi)) { int myGlobalIndex = mol->getGlobalIndex(); int globalIO = startingIOIndexForMol[myGlobalIndex]; for (StuntDouble* sd = mol->beginIntegrableObject(ioi); sd != NULL; @@ -920,10 +960,7 @@ namespace OpenMD { } void SimCreator::loadCoordinates(SimInfo* info, const std::string& mdFileName) { - Globals* simParams; - simParams = info->getSimParams(); - DumpReader reader(info, mdFileName); int nframes = reader.getNFrames();