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()); |
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(); |
640 |
– |
|
641 |
– |
/**@todo fixme */ |
642 |
– |
#ifndef IS_MPI |
669 |
|
|
670 |
|
beginAtomIndex = 0; |
671 |
|
beginRigidBodyIndex = 0; |
672 |
|
beginCutoffGroupIndex = 0; |
673 |
< |
|
674 |
< |
#else |
649 |
< |
|
650 |
< |
int nproc; |
651 |
< |
int myNode; |
652 |
< |
|
653 |
< |
myNode = worldRank; |
654 |
< |
MPI_Comm_size(MPI_COMM_WORLD, &nproc); |
655 |
< |
|
656 |
< |
std::vector < int > tmpAtomsInProc(nproc, 0); |
657 |
< |
std::vector < int > tmpRigidBodiesInProc(nproc, 0); |
658 |
< |
std::vector < int > tmpCutoffGroupsInProc(nproc, 0); |
659 |
< |
std::vector < int > NumAtomsInProc(nproc, 0); |
660 |
< |
std::vector < int > NumRigidBodiesInProc(nproc, 0); |
661 |
< |
std::vector < int > NumCutoffGroupsInProc(nproc, 0); |
662 |
< |
|
663 |
< |
tmpAtomsInProc[myNode] = info->getNAtoms(); |
664 |
< |
tmpRigidBodiesInProc[myNode] = info->getNRigidBodies(); |
665 |
< |
tmpCutoffGroupsInProc[myNode] = info->getNCutoffGroups(); |
666 |
< |
|
667 |
< |
//do MPI_ALLREDUCE to exchange the total number of atoms, rigidbodies and cutoff groups |
668 |
< |
MPI_Allreduce(&tmpAtomsInProc[0], &NumAtomsInProc[0], nproc, MPI_INT, |
669 |
< |
MPI_SUM, MPI_COMM_WORLD); |
670 |
< |
MPI_Allreduce(&tmpRigidBodiesInProc[0], &NumRigidBodiesInProc[0], nproc, |
671 |
< |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
672 |
< |
MPI_Allreduce(&tmpCutoffGroupsInProc[0], &NumCutoffGroupsInProc[0], nproc, |
673 |
< |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
674 |
< |
|
675 |
< |
beginAtomIndex = 0; |
676 |
< |
beginRigidBodyIndex = 0; |
677 |
< |
beginCutoffGroupIndex = 0; |
678 |
< |
|
679 |
< |
for(int i = 0; i < myNode; i++) { |
680 |
< |
beginAtomIndex += NumAtomsInProc[i]; |
681 |
< |
beginRigidBodyIndex += NumRigidBodiesInProc[i]; |
682 |
< |
beginCutoffGroupIndex += NumCutoffGroupsInProc[i]; |
683 |
< |
} |
684 |
< |
|
685 |
< |
#endif |
686 |
< |
|
687 |
< |
//rigidbody's index begins right after atom's |
688 |
< |
beginRigidBodyIndex += info->getNGlobalAtoms(); |
689 |
< |
|
690 |
< |
for(mol = info->beginMolecule(mi); mol != NULL; |
691 |
< |
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++); |
701 |
< |
} |
702 |
< |
|
703 |
< |
//local index of cutoff group is trivial, it only depends on the order of travesing |
704 |
< |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
705 |
< |
cg = mol->nextCutoffGroup(ci)) { |
706 |
< |
cg->setGlobalIndex(beginCutoffGroupIndex++); |
707 |
< |
} |
708 |
< |
} |
709 |
< |
|
711 |
> |
#endif |
712 |
> |
|
713 |
> |
} //end for(int i=0) |
714 |
> |
|
715 |
|
//fill globalGroupMembership |
716 |
< |
std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), -1); |
716 |
> |
std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), 0); |
717 |
|
for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { |
718 |
|
for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
719 |
|
|
732 |
|
// docs said we could. |
733 |
|
std::vector<int> tmpGroupMembership(info->getNGlobalAtoms(), 0); |
734 |
|
MPI_Allreduce(&globalGroupMembership[0], &tmpGroupMembership[0], nGlobalAtoms, |
735 |
< |
MPI_INT, MPI_MAX, MPI_COMM_WORLD); |
735 |
> |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
736 |
|
info->setGlobalGroupMembership(tmpGroupMembership); |
732 |
– |
|
733 |
– |
cerr << "ggm:\n"; |
734 |
– |
for (int i = 0; i < tmpGroupMembership.size(); i++) |
735 |
– |
cerr << "i = " << i << "\t ggm(i) = " << tmpGroupMembership[i] << "\n"; |
736 |
– |
|
737 |
|
#else |
738 |
|
info->setGlobalGroupMembership(globalGroupMembership); |
739 |
|
#endif |
793 |
|
globalIO++; |
794 |
|
} |
795 |
|
} |
796 |
< |
|
796 |
> |
|
797 |
|
info->setIOIndexToIntegrableObject(IOIndexToIntegrableObject); |
798 |
|
|
799 |
|
} |