| 76 |
|
#include "antlr/NoViableAltException.hpp" |
| 77 |
|
|
| 78 |
|
#ifdef IS_MPI |
| 79 |
+ |
#include "mpi.h" |
| 80 |
|
#include "math/ParallelRandNumGen.hpp" |
| 81 |
|
#endif |
| 82 |
|
|
| 83 |
|
namespace OpenMD { |
| 84 |
|
|
| 85 |
< |
Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int startOfMetaDataBlock ){ |
| 85 |
> |
Globals* SimCreator::parseFile(std::istream& rawMetaDataStream, const std::string& filename, int mdFileVersion, int startOfMetaDataBlock ){ |
| 86 |
|
Globals* simParams = NULL; |
| 87 |
|
try { |
| 88 |
|
|
| 93 |
|
const int masterNode = 0; |
| 94 |
|
int commStatus; |
| 95 |
|
if (worldRank == masterNode) { |
| 96 |
< |
#endif |
| 97 |
< |
|
| 96 |
> |
commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
| 97 |
> |
#endif |
| 98 |
|
SimplePreprocessor preprocessor; |
| 99 |
|
preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, ppStream); |
| 100 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
} else { |
| 110 |
+ |
|
| 111 |
+ |
commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
| 112 |
+ |
|
| 113 |
|
//get stream size |
| 114 |
|
commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); |
| 115 |
|
|
| 233 |
|
simError(); |
| 234 |
|
} |
| 235 |
|
|
| 236 |
+ |
simParams->setMDfileVersion(mdFileVersion); |
| 237 |
|
return simParams; |
| 238 |
|
} |
| 239 |
|
|
| 248 |
|
int metaDataBlockEnd = -1; |
| 249 |
|
int i; |
| 250 |
|
int mdOffset; |
| 251 |
+ |
int mdFileVersion; |
| 252 |
|
|
| 253 |
|
#ifdef IS_MPI |
| 254 |
|
const int masterNode = 0; |
| 282 |
|
painCave.isFatal = 1; |
| 283 |
|
simError(); |
| 284 |
|
} |
| 285 |
+ |
|
| 286 |
+ |
// found the correct opening string, now try to get the file |
| 287 |
+ |
// format version number. |
| 288 |
+ |
|
| 289 |
+ |
StringTokenizer tokenizer(line, "=<> \t\n\r"); |
| 290 |
+ |
std::string fileType = tokenizer.nextToken(); |
| 291 |
+ |
toUpper(fileType); |
| 292 |
+ |
|
| 293 |
+ |
mdFileVersion = 0; |
| 294 |
|
|
| 295 |
+ |
if (fileType == "OPENMD") { |
| 296 |
+ |
while (tokenizer.hasMoreTokens()) { |
| 297 |
+ |
std::string token(tokenizer.nextToken()); |
| 298 |
+ |
toUpper(token); |
| 299 |
+ |
if (token == "VERSION") { |
| 300 |
+ |
mdFileVersion = tokenizer.nextTokenAsInt(); |
| 301 |
+ |
break; |
| 302 |
+ |
} |
| 303 |
+ |
} |
| 304 |
+ |
} |
| 305 |
+ |
|
| 306 |
|
//scan through the input stream and find MetaData tag |
| 307 |
|
while(mdFile_.getline(buffer, bufferSize)) { |
| 308 |
|
++lineNo; |
| 358 |
|
std::stringstream rawMetaDataStream(mdRawData); |
| 359 |
|
|
| 360 |
|
//parse meta-data file |
| 361 |
< |
Globals* simParams = parseFile(rawMetaDataStream, mdFileName, metaDataBlockStart+1); |
| 361 |
> |
Globals* simParams = parseFile(rawMetaDataStream, mdFileName, mdFileVersion, |
| 362 |
> |
metaDataBlockStart + 1); |
| 363 |
|
|
| 364 |
|
//create the force field |
| 365 |
|
ForceField * ff = ForceFieldFactory::getInstance()->createForceField(simParams->getForceField()); |
| 396 |
|
} |
| 397 |
|
|
| 398 |
|
ff->parse(forcefieldFileName); |
| 372 |
– |
ff->setFortranForceOptions(); |
| 399 |
|
//create SimInfo |
| 400 |
|
SimInfo * info = new SimInfo(ff, simParams); |
| 401 |
|
|
| 413 |
|
//create the molecules |
| 414 |
|
createMolecules(info); |
| 415 |
|
|
| 390 |
– |
|
| 416 |
|
//allocate memory for DataStorage(circular reference, need to |
| 417 |
|
//break it) |
| 418 |
|
info->setSnapshotManager(new SimSnapshotManager(info)); |
| 438 |
|
|
| 439 |
|
if (loadInitCoords) |
| 440 |
|
loadCoordinates(info, mdFileName); |
| 416 |
– |
|
| 441 |
|
return info; |
| 442 |
|
} |
| 443 |
|
|
| 636 |
|
#endif |
| 637 |
|
|
| 638 |
|
stampId = info->getMoleculeStampId(i); |
| 639 |
< |
Molecule * mol = molCreator.createMolecule(info->getForceField(), info->getMoleculeStamp(stampId), |
| 640 |
< |
stampId, i, info->getLocalIndexManager()); |
| 639 |
> |
Molecule * mol = molCreator.createMolecule(info->getForceField(), |
| 640 |
> |
info->getMoleculeStamp(stampId), |
| 641 |
> |
stampId, i, |
| 642 |
> |
info->getLocalIndexManager()); |
| 643 |
|
|
| 644 |
|
info->addMolecule(mol); |
| 645 |
|
|
| 666 |
|
int beginRigidBodyIndex; |
| 667 |
|
int beginCutoffGroupIndex; |
| 668 |
|
int nGlobalAtoms = info->getNGlobalAtoms(); |
| 643 |
– |
|
| 644 |
– |
/**@todo fixme */ |
| 645 |
– |
#ifndef IS_MPI |
| 669 |
|
|
| 670 |
|
beginAtomIndex = 0; |
| 671 |
|
beginRigidBodyIndex = 0; |
| 672 |
|
beginCutoffGroupIndex = 0; |
| 673 |
< |
|
| 674 |
< |
#else |
| 652 |
< |
|
| 653 |
< |
int nproc; |
| 654 |
< |
int myNode; |
| 655 |
< |
|
| 656 |
< |
myNode = worldRank; |
| 657 |
< |
MPI_Comm_size(MPI_COMM_WORLD, &nproc); |
| 658 |
< |
|
| 659 |
< |
std::vector < int > tmpAtomsInProc(nproc, 0); |
| 660 |
< |
std::vector < int > tmpRigidBodiesInProc(nproc, 0); |
| 661 |
< |
std::vector < int > tmpCutoffGroupsInProc(nproc, 0); |
| 662 |
< |
std::vector < int > NumAtomsInProc(nproc, 0); |
| 663 |
< |
std::vector < int > NumRigidBodiesInProc(nproc, 0); |
| 664 |
< |
std::vector < int > NumCutoffGroupsInProc(nproc, 0); |
| 665 |
< |
|
| 666 |
< |
tmpAtomsInProc[myNode] = info->getNAtoms(); |
| 667 |
< |
tmpRigidBodiesInProc[myNode] = info->getNRigidBodies(); |
| 668 |
< |
tmpCutoffGroupsInProc[myNode] = info->getNCutoffGroups(); |
| 669 |
< |
|
| 670 |
< |
//do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups |
| 671 |
< |
MPI_Allreduce(&tmpAtomsInProc[0], &NumAtomsInProc[0], nproc, MPI_INT, |
| 672 |
< |
MPI_SUM, MPI_COMM_WORLD); |
| 673 |
< |
MPI_Allreduce(&tmpRigidBodiesInProc[0], &NumRigidBodiesInProc[0], nproc, |
| 674 |
< |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 675 |
< |
MPI_Allreduce(&tmpCutoffGroupsInProc[0], &NumCutoffGroupsInProc[0], nproc, |
| 676 |
< |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 677 |
< |
|
| 678 |
< |
beginAtomIndex = 0; |
| 679 |
< |
beginRigidBodyIndex = 0; |
| 680 |
< |
beginCutoffGroupIndex = 0; |
| 681 |
< |
|
| 682 |
< |
for(int i = 0; i < myNode; i++) { |
| 683 |
< |
beginAtomIndex += NumAtomsInProc[i]; |
| 684 |
< |
beginRigidBodyIndex += NumRigidBodiesInProc[i]; |
| 685 |
< |
beginCutoffGroupIndex += NumCutoffGroupsInProc[i]; |
| 686 |
< |
} |
| 687 |
< |
|
| 688 |
< |
#endif |
| 689 |
< |
|
| 690 |
< |
//rigidbody's index begins right after atom's |
| 691 |
< |
beginRigidBodyIndex += info->getNGlobalAtoms(); |
| 692 |
< |
|
| 693 |
< |
for(mol = info->beginMolecule(mi); mol != NULL; |
| 694 |
< |
mol = info->nextMolecule(mi)) { |
| 673 |
> |
|
| 674 |
> |
for(int i = 0; i < info->getNGlobalMolecules(); i++) { |
| 675 |
|
|
| 676 |
< |
//local index(index in DataStorge) of atom is important |
| 677 |
< |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 678 |
< |
atom->setGlobalIndex(beginAtomIndex++); |
| 676 |
> |
#ifdef IS_MPI |
| 677 |
> |
if (info->getMolToProc(i) == worldRank) { |
| 678 |
> |
#endif |
| 679 |
> |
// stuff to do if I own this molecule |
| 680 |
> |
mol = info->getMoleculeByGlobalIndex(i); |
| 681 |
> |
|
| 682 |
> |
//local index(index in DataStorge) of atom is important |
| 683 |
> |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 684 |
> |
atom->setGlobalIndex(beginAtomIndex++); |
| 685 |
> |
} |
| 686 |
> |
|
| 687 |
> |
for(rb = mol->beginRigidBody(ri); rb != NULL; |
| 688 |
> |
rb = mol->nextRigidBody(ri)) { |
| 689 |
> |
rb->setGlobalIndex(beginRigidBodyIndex++); |
| 690 |
> |
} |
| 691 |
> |
|
| 692 |
> |
//local index of cutoff group is trivial, it only depends on |
| 693 |
> |
//the order of travesing |
| 694 |
> |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
| 695 |
> |
cg = mol->nextCutoffGroup(ci)) { |
| 696 |
> |
cg->setGlobalIndex(beginCutoffGroupIndex++); |
| 697 |
> |
} |
| 698 |
> |
|
| 699 |
> |
#ifdef IS_MPI |
| 700 |
> |
} else { |
| 701 |
> |
|
| 702 |
> |
// stuff to do if I don't own this molecule |
| 703 |
> |
|
| 704 |
> |
int stampId = info->getMoleculeStampId(i); |
| 705 |
> |
MoleculeStamp* stamp = info->getMoleculeStamp(stampId); |
| 706 |
> |
|
| 707 |
> |
beginAtomIndex += stamp->getNAtoms(); |
| 708 |
> |
beginRigidBodyIndex += stamp->getNRigidBodies(); |
| 709 |
> |
beginCutoffGroupIndex += stamp->getNCutoffGroups() + stamp->getNFreeAtoms(); |
| 710 |
|
} |
| 711 |
< |
|
| 712 |
< |
for(rb = mol->beginRigidBody(ri); rb != NULL; |
| 713 |
< |
rb = mol->nextRigidBody(ri)) { |
| 714 |
< |
rb->setGlobalIndex(beginRigidBodyIndex++); |
| 704 |
< |
} |
| 705 |
< |
|
| 706 |
< |
//local index of cutoff group is trivial, it only depends on the order of travesing |
| 707 |
< |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
| 708 |
< |
cg = mol->nextCutoffGroup(ci)) { |
| 709 |
< |
cg->setGlobalIndex(beginCutoffGroupIndex++); |
| 710 |
< |
} |
| 711 |
< |
} |
| 712 |
< |
|
| 711 |
> |
#endif |
| 712 |
> |
|
| 713 |
> |
} //end for(int i=0) |
| 714 |
> |
|
| 715 |
|
//fill globalGroupMembership |
| 716 |
|
std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), 0); |
| 717 |
|
for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { |
| 723 |
|
|
| 724 |
|
} |
| 725 |
|
} |
| 726 |
< |
|
| 726 |
> |
|
| 727 |
|
#ifdef IS_MPI |
| 728 |
|
// Since the globalGroupMembership has been zero filled and we've only |
| 729 |
|
// poked values into the atoms we know, we can do an Allreduce |
| 793 |
|
globalIO++; |
| 794 |
|
} |
| 795 |
|
} |
| 796 |
< |
|
| 796 |
> |
|
| 797 |
|
info->setIOIndexToIntegrableObject(IOIndexToIntegrableObject); |
| 798 |
|
|
| 799 |
|
} |
| 800 |
|
|
| 801 |
|
void SimCreator::loadCoordinates(SimInfo* info, const std::string& mdFileName) { |
| 802 |
|
Globals* simParams; |
| 803 |
+ |
|
| 804 |
|
simParams = info->getSimParams(); |
| 805 |
|
|
| 803 |
– |
|
| 806 |
|
DumpReader reader(info, mdFileName); |
| 807 |
|
int nframes = reader.getNFrames(); |
| 808 |
< |
|
| 808 |
> |
|
| 809 |
|
if (nframes > 0) { |
| 810 |
|
reader.readFrame(nframes - 1); |
| 811 |
|
} else { |
| 816 |
|
painCave.isFatal = 1; |
| 817 |
|
simError(); |
| 818 |
|
} |
| 817 |
– |
|
| 819 |
|
//copy the current snapshot to previous snapshot |
| 820 |
|
info->getSnapshotManager()->advance(); |
| 821 |
|
} |