35 |
|
* |
36 |
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
< |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
|
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
99 |
|
#ifdef IS_MPI |
100 |
|
int streamSize; |
101 |
|
const int masterNode = 0; |
102 |
< |
int commStatus; |
102 |
> |
|
103 |
|
if (worldRank == masterNode) { |
104 |
< |
commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
104 |
> |
MPI::COMM_WORLD.Bcast(&mdFileVersion, 1, MPI::INT, masterNode); |
105 |
|
#endif |
106 |
|
SimplePreprocessor preprocessor; |
107 |
|
preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, ppStream); |
109 |
|
#ifdef IS_MPI |
110 |
|
//brocasting the stream size |
111 |
|
streamSize = ppStream.str().size() +1; |
112 |
< |
commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); |
113 |
< |
|
114 |
< |
commStatus = MPI_Bcast(static_cast<void*>(const_cast<char*>(ppStream.str().c_str())), streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); |
115 |
< |
|
116 |
< |
|
112 |
> |
MPI::COMM_WORLD.Bcast(&streamSize, 1, MPI::LONG, masterNode); |
113 |
> |
MPI::COMM_WORLD.Bcast(static_cast<void*>(const_cast<char*>(ppStream.str().c_str())), streamSize, MPI::CHAR, masterNode); |
114 |
> |
|
115 |
|
} else { |
116 |
< |
|
119 |
< |
commStatus = MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
116 |
> |
MPI::COMM_WORLD.Bcast(&mdFileVersion, 1, MPI::INT, masterNode); |
117 |
|
|
118 |
|
//get stream size |
119 |
< |
commStatus = MPI_Bcast(&streamSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); |
119 |
> |
MPI::COMM_WORLD.Bcast(&streamSize, 1, MPI::LONG, masterNode); |
120 |
|
|
121 |
|
char* buf = new char[streamSize]; |
122 |
|
assert(buf); |
123 |
|
|
124 |
|
//receive file content |
125 |
< |
commStatus = MPI_Bcast(buf, streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); |
125 |
> |
MPI::COMM_WORLD.Bcast(buf, streamSize, MPI::CHAR, masterNode); |
126 |
|
|
127 |
|
ppStream.str(buf); |
128 |
|
delete [] buf; |
132 |
– |
|
129 |
|
} |
130 |
|
#endif |
131 |
|
// Create a scanner that reads from the input stream |
510 |
|
|
511 |
|
#ifdef IS_MPI |
512 |
|
void SimCreator::divideMolecules(SimInfo *info) { |
517 |
– |
RealType numerator; |
518 |
– |
RealType denominator; |
519 |
– |
RealType precast; |
520 |
– |
RealType x; |
521 |
– |
RealType y; |
513 |
|
RealType a; |
523 |
– |
int old_atoms; |
524 |
– |
int add_atoms; |
525 |
– |
int new_atoms; |
526 |
– |
int nTarget; |
527 |
– |
int done; |
528 |
– |
int i; |
529 |
– |
int j; |
530 |
– |
int loops; |
531 |
– |
int which_proc; |
514 |
|
int nProcessors; |
515 |
|
std::vector<int> atomsPerProc; |
516 |
|
int nGlobalMols = info->getNGlobalMolecules(); |
517 |
< |
std::vector<int> molToProcMap(nGlobalMols, -1); // default to an error condition: |
517 |
> |
std::vector<int> molToProcMap(nGlobalMols, -1); // default to an |
518 |
> |
// error |
519 |
> |
// condition: |
520 |
|
|
521 |
|
nProcessors = MPI::COMM_WORLD.Get_size(); |
522 |
|
|
527 |
|
"\tthe number of molecules. This will not result in a \n" |
528 |
|
"\tusable division of atoms for force decomposition.\n" |
529 |
|
"\tEither try a smaller number of processors, or run the\n" |
530 |
< |
"\tsingle-processor version of OpenMD.\n", nProcessors, nGlobalMols); |
530 |
> |
"\tsingle-processor version of OpenMD.\n", nProcessors, |
531 |
> |
nGlobalMols); |
532 |
|
|
533 |
|
painCave.isFatal = 1; |
534 |
|
simError(); |
535 |
|
} |
536 |
|
|
552 |
– |
int seedValue; |
537 |
|
Globals * simParams = info->getSimParams(); |
538 |
< |
SeqRandNumGen* myRandom; //divide labor does not need Parallel random number generator |
538 |
> |
SeqRandNumGen* myRandom; //divide labor does not need Parallel |
539 |
> |
//random number generator |
540 |
|
if (simParams->haveSeed()) { |
541 |
< |
seedValue = simParams->getSeed(); |
541 |
> |
int seedValue = simParams->getSeed(); |
542 |
|
myRandom = new SeqRandNumGen(seedValue); |
543 |
|
}else { |
544 |
|
myRandom = new SeqRandNumGen(); |
551 |
|
atomsPerProc.insert(atomsPerProc.end(), nProcessors, 0); |
552 |
|
|
553 |
|
if (worldRank == 0) { |
554 |
< |
numerator = info->getNGlobalAtoms(); |
555 |
< |
denominator = nProcessors; |
556 |
< |
precast = numerator / denominator; |
557 |
< |
nTarget = (int)(precast + 0.5); |
554 |
> |
RealType numerator = info->getNGlobalAtoms(); |
555 |
> |
RealType denominator = nProcessors; |
556 |
> |
RealType precast = numerator / denominator; |
557 |
> |
int nTarget = (int)(precast + 0.5); |
558 |
|
|
559 |
< |
for(i = 0; i < nGlobalMols; i++) { |
559 |
> |
for(int i = 0; i < nGlobalMols; i++) { |
560 |
|
|
561 |
< |
done = 0; |
562 |
< |
loops = 0; |
561 |
> |
int done = 0; |
562 |
> |
int loops = 0; |
563 |
|
|
564 |
|
while (!done) { |
565 |
|
loops++; |
566 |
|
|
567 |
|
// Pick a processor at random |
568 |
|
|
569 |
< |
which_proc = (int) (myRandom->rand() * nProcessors); |
569 |
> |
int which_proc = (int) (myRandom->rand() * nProcessors); |
570 |
|
|
571 |
|
//get the molecule stamp first |
572 |
|
int stampId = info->getMoleculeStampId(i); |
573 |
|
MoleculeStamp * moleculeStamp = info->getMoleculeStamp(stampId); |
574 |
|
|
575 |
|
// How many atoms does this processor have so far? |
576 |
< |
old_atoms = atomsPerProc[which_proc]; |
577 |
< |
add_atoms = moleculeStamp->getNAtoms(); |
578 |
< |
new_atoms = old_atoms + add_atoms; |
576 |
> |
int old_atoms = atomsPerProc[which_proc]; |
577 |
> |
int add_atoms = moleculeStamp->getNAtoms(); |
578 |
> |
int new_atoms = old_atoms + add_atoms; |
579 |
|
|
580 |
|
// If we've been through this loop too many times, we need |
581 |
|
// to just give up and assign the molecule to this processor |
619 |
|
// Pacc(x) = exp(- a * x) |
620 |
|
// where a = penalty / (average atoms per molecule) |
621 |
|
|
622 |
< |
x = (RealType)(new_atoms - nTarget); |
623 |
< |
y = myRandom->rand(); |
622 |
> |
RealType x = (RealType)(new_atoms - nTarget); |
623 |
> |
RealType y = myRandom->rand(); |
624 |
|
|
625 |
|
if (y < exp(- a * x)) { |
626 |
|
molToProcMap[i] = which_proc; |
781 |
|
} |
782 |
|
} |
783 |
|
|
784 |
< |
if (simParams->getOutputElectricField()) { |
784 |
> |
if (simParams->getOutputElectricField() | simParams->haveElectricField()) { |
785 |
|
storageLayout |= DataStorage::dslElectricField; |
786 |
|
} |
787 |
|
|
791 |
|
storageLayout |= DataStorage::dslFlucQForce; |
792 |
|
} |
793 |
|
|
794 |
+ |
info->setStorageLayout(storageLayout); |
795 |
+ |
|
796 |
|
return storageLayout; |
797 |
|
} |
798 |
|
|
955 |
|
} |
956 |
|
|
957 |
|
void SimCreator::loadCoordinates(SimInfo* info, const std::string& mdFileName) { |
971 |
– |
Globals* simParams; |
972 |
– |
|
973 |
– |
simParams = info->getSimParams(); |
958 |
|
|
959 |
|
DumpReader reader(info, mdFileName); |
960 |
|
int nframes = reader.getNFrames(); |
961 |
< |
|
961 |
> |
|
962 |
|
if (nframes > 0) { |
963 |
|
reader.readFrame(nframes - 1); |
964 |
|
} else { |