| 47 |
|
* @version 1.0 |
| 48 |
|
*/ |
| 49 |
|
|
| 50 |
+ |
#ifdef IS_MPI |
| 51 |
+ |
#include <mpi.h> |
| 52 |
+ |
#endif |
| 53 |
|
#include <algorithm> |
| 54 |
|
#include <set> |
| 55 |
|
#include <map> |
| 64 |
|
#include "io/ForceFieldOptions.hpp" |
| 65 |
|
#include "brains/ForceField.hpp" |
| 66 |
|
#include "nonbonded/SwitchingFunction.hpp" |
| 64 |
– |
#ifdef IS_MPI |
| 65 |
– |
#include <mpi.h> |
| 66 |
– |
#endif |
| 67 |
|
|
| 68 |
|
using namespace std; |
| 69 |
|
namespace OpenMD { |
| 72 |
|
forceField_(ff), simParams_(simParams), |
| 73 |
|
ndf_(0), fdf_local(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0), |
| 74 |
|
nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0), |
| 75 |
< |
nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), nGlobalFluctuatingCharges_(0), |
| 76 |
< |
nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nInversions_(0), |
| 75 |
> |
nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), |
| 76 |
> |
nGlobalFluctuatingCharges_(0), nGlobalBonds_(0), nGlobalBends_(0), |
| 77 |
> |
nGlobalTorsions_(0), nGlobalInversions_(0), nGlobalConstraints_(0), |
| 78 |
> |
nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nInversions_(0), |
| 79 |
|
nRigidBodies_(0), nIntegrableObjects_(0), nCutoffGroups_(0), |
| 80 |
< |
nConstraints_(0), nFluctuatingCharges_(0), sman_(NULL), topologyDone_(false), |
| 81 |
< |
calcBoxDipole_(false), useAtomicVirial_(true) { |
| 80 |
> |
nConstraints_(0), nFluctuatingCharges_(0), sman_(NULL), |
| 81 |
> |
topologyDone_(false), calcBoxDipole_(false), useAtomicVirial_(true), |
| 82 |
> |
hasNGlobalConstraints_(false) { |
| 83 |
|
|
| 84 |
|
MoleculeStamp* molStamp; |
| 85 |
|
int nMolWithSameStamp; |
| 106 |
|
addMoleculeStamp(molStamp, nMolWithSameStamp); |
| 107 |
|
|
| 108 |
|
//calculate atoms in molecules |
| 109 |
< |
nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp; |
| 109 |
> |
nGlobalAtoms_ += molStamp->getNAtoms() * nMolWithSameStamp; |
| 110 |
> |
nGlobalBonds_ += molStamp->getNBonds() * nMolWithSameStamp; |
| 111 |
> |
nGlobalBends_ += molStamp->getNBends() * nMolWithSameStamp; |
| 112 |
> |
nGlobalTorsions_ += molStamp->getNTorsions() * nMolWithSameStamp; |
| 113 |
> |
nGlobalInversions_ += molStamp->getNInversions() * nMolWithSameStamp; |
| 114 |
|
|
| 115 |
|
//calculate atoms in cutoff groups |
| 116 |
|
int nAtomsInGroups = 0; |
| 282 |
|
ndf_local -= nConstraints_; |
| 283 |
|
|
| 284 |
|
#ifdef IS_MPI |
| 285 |
< |
MPI::COMM_WORLD.Allreduce(&ndf_local, &ndf_, 1, MPI::INT,MPI::SUM); |
| 286 |
< |
MPI::COMM_WORLD.Allreduce(&nfq_local, &nGlobalFluctuatingCharges_, 1, |
| 287 |
< |
MPI::INT, MPI::SUM); |
| 285 |
> |
MPI_Allreduce(&ndf_local, &ndf_, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 286 |
> |
MPI_Allreduce(&nfq_local, &nGlobalFluctuatingCharges_, 1, |
| 287 |
> |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 288 |
|
#else |
| 289 |
|
ndf_ = ndf_local; |
| 290 |
|
nGlobalFluctuatingCharges_ = nfq_local; |
| 298 |
|
|
| 299 |
|
int SimInfo::getFdf() { |
| 300 |
|
#ifdef IS_MPI |
| 301 |
< |
MPI::COMM_WORLD.Allreduce(&fdf_local, &fdf_, 1, MPI::INT, MPI::SUM); |
| 301 |
> |
MPI_Allreduce(&fdf_local, &fdf_, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 302 |
|
#else |
| 303 |
|
fdf_ = fdf_local; |
| 304 |
|
#endif |
| 354 |
|
} |
| 355 |
|
|
| 356 |
|
#ifdef IS_MPI |
| 357 |
< |
MPI::COMM_WORLD.Allreduce(&ndfRaw_local, &ndfRaw_, 1, MPI::INT, MPI::SUM); |
| 357 |
> |
MPI_Allreduce(&ndfRaw_local, &ndfRaw_, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 358 |
|
#else |
| 359 |
|
ndfRaw_ = ndfRaw_local; |
| 360 |
|
#endif |
| 365 |
|
|
| 366 |
|
ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_; |
| 367 |
|
|
| 361 |
– |
|
| 368 |
|
#ifdef IS_MPI |
| 369 |
< |
MPI::COMM_WORLD.Allreduce(&ndfTrans_local, &ndfTrans_, 1, |
| 370 |
< |
MPI::INT, MPI::SUM); |
| 369 |
> |
MPI_Allreduce(&ndfTrans_local, &ndfTrans_, 1, MPI_INT, MPI_SUM, |
| 370 |
> |
MPI_COMM_WORLD); |
| 371 |
|
#else |
| 372 |
|
ndfTrans_ = ndfTrans_local; |
| 373 |
|
#endif |
| 374 |
|
|
| 375 |
|
ndfTrans_ = ndfTrans_ - 3 - nZconstraint_; |
| 370 |
– |
|
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
void SimInfo::addInteractionPairs(Molecule* mol) { |
| 423 |
|
atomGroups.insert(map<int, set<int> >::value_type(sd->getGlobalIndex(), oneAtomSet)); |
| 424 |
|
} |
| 425 |
|
} |
| 426 |
+ |
|
| 427 |
|
|
| 428 |
|
for (bond= mol->beginBond(bondIter); bond != NULL; |
| 429 |
|
bond = mol->nextBond(bondIter)) { |
| 709 |
|
*/ |
| 710 |
|
void SimInfo::update() { |
| 711 |
|
setupSimVariables(); |
| 712 |
+ |
calcNConstraints(); |
| 713 |
|
calcNdf(); |
| 714 |
|
calcNdfRaw(); |
| 715 |
|
calcNdfTrans(); |
| 749 |
|
// count_local holds the number of found types on this processor |
| 750 |
|
int count_local = foundTypes.size(); |
| 751 |
|
|
| 752 |
< |
int nproc = MPI::COMM_WORLD.Get_size(); |
| 752 |
> |
int nproc; |
| 753 |
> |
MPI_Comm_size( MPI_COMM_WORLD, &nproc); |
| 754 |
|
|
| 755 |
|
// we need arrays to hold the counts and displacement vectors for |
| 756 |
|
// all processors |
| 758 |
|
vector<int> disps(nproc, 0); |
| 759 |
|
|
| 760 |
|
// fill the counts array |
| 761 |
< |
MPI::COMM_WORLD.Allgather(&count_local, 1, MPI::INT, &counts[0], |
| 762 |
< |
1, MPI::INT); |
| 761 |
> |
MPI_Allgather(&count_local, 1, MPI_INT, &counts[0], |
| 762 |
> |
1, MPI_INT, MPI_COMM_WORLD); |
| 763 |
|
|
| 764 |
|
// use the processor counts to compute the displacement array |
| 765 |
|
disps[0] = 0; |
| 773 |
|
vector<int> ftGlobal(totalCount); |
| 774 |
|
|
| 775 |
|
// now spray out the foundTypes to all the other processors: |
| 776 |
< |
MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT, |
| 777 |
< |
&ftGlobal[0], &counts[0], &disps[0], |
| 778 |
< |
MPI::INT); |
| 776 |
> |
MPI_Allgatherv(&foundTypes[0], count_local, MPI_INT, |
| 777 |
> |
&ftGlobal[0], &counts[0], &disps[0], |
| 778 |
> |
MPI_INT, MPI_COMM_WORLD); |
| 779 |
|
|
| 780 |
|
vector<int>::iterator j; |
| 781 |
|
|
| 839 |
|
} |
| 840 |
|
|
| 841 |
|
#ifdef IS_MPI |
| 842 |
< |
bool temp; |
| 842 |
> |
int temp; |
| 843 |
> |
|
| 844 |
|
temp = usesDirectional; |
| 845 |
< |
MPI::COMM_WORLD.Allreduce(&temp, &usesDirectionalAtoms_, 1, MPI::BOOL, |
| 846 |
< |
MPI::LOR); |
| 838 |
< |
|
| 839 |
< |
temp = usesMetallic; |
| 840 |
< |
MPI::COMM_WORLD.Allreduce(&temp, &usesMetallicAtoms_, 1, MPI::BOOL, |
| 841 |
< |
MPI::LOR); |
| 845 |
> |
MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 846 |
> |
usesDirectionalAtoms_ = (temp == 0) ? false : true; |
| 847 |
|
|
| 848 |
+ |
temp = usesMetallic; |
| 849 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 850 |
+ |
usesMetallicAtoms_ = (temp == 0) ? false : true; |
| 851 |
+ |
|
| 852 |
|
temp = usesElectrostatic; |
| 853 |
< |
MPI::COMM_WORLD.Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI::BOOL, |
| 854 |
< |
MPI::LOR); |
| 853 |
> |
MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 854 |
> |
usesElectrostaticAtoms_ = (temp == 0) ? false : true; |
| 855 |
|
|
| 856 |
|
temp = usesFluctuatingCharges; |
| 857 |
< |
MPI::COMM_WORLD.Allreduce(&temp, &usesFluctuatingCharges_, 1, MPI::BOOL, |
| 858 |
< |
MPI::LOR); |
| 857 |
> |
MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 858 |
> |
usesFluctuatingCharges_ = (temp == 0) ? false : true; |
| 859 |
|
#else |
| 860 |
|
|
| 861 |
|
usesDirectionalAtoms_ = usesDirectional; |
| 947 |
|
} |
| 948 |
|
} |
| 949 |
|
|
| 950 |
< |
// Build the identArray_ |
| 950 |
> |
// Build the identArray_ and regions_ |
| 951 |
|
|
| 952 |
|
identArray_.clear(); |
| 953 |
< |
identArray_.reserve(getNAtoms()); |
| 954 |
< |
for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
| 953 |
> |
identArray_.reserve(getNAtoms()); |
| 954 |
> |
regions_.clear(); |
| 955 |
> |
regions_.reserve(getNAtoms()); |
| 956 |
> |
|
| 957 |
> |
for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
| 958 |
> |
int reg = mol->getRegion(); |
| 959 |
|
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 960 |
|
identArray_.push_back(atom->getIdent()); |
| 961 |
+ |
regions_.push_back(reg); |
| 962 |
|
} |
| 963 |
|
} |
| 964 |
< |
|
| 964 |
> |
|
| 965 |
|
topologyDone_ = true; |
| 966 |
|
} |
| 967 |
|
|
| 996 |
|
delete sman_; |
| 997 |
|
sman_ = sman; |
| 998 |
|
|
| 985 |
– |
Molecule* mol; |
| 986 |
– |
RigidBody* rb; |
| 987 |
– |
Atom* atom; |
| 988 |
– |
CutoffGroup* cg; |
| 999 |
|
SimInfo::MoleculeIterator mi; |
| 1000 |
+ |
Molecule::AtomIterator ai; |
| 1001 |
|
Molecule::RigidBodyIterator rbIter; |
| 991 |
– |
Molecule::AtomIterator atomIter; |
| 1002 |
|
Molecule::CutoffGroupIterator cgIter; |
| 1003 |
+ |
Molecule::BondIterator bondIter; |
| 1004 |
+ |
Molecule::BendIterator bendIter; |
| 1005 |
+ |
Molecule::TorsionIterator torsionIter; |
| 1006 |
+ |
Molecule::InversionIterator inversionIter; |
| 1007 |
|
|
| 1008 |
+ |
Molecule* mol; |
| 1009 |
+ |
Atom* atom; |
| 1010 |
+ |
RigidBody* rb; |
| 1011 |
+ |
CutoffGroup* cg; |
| 1012 |
+ |
Bond* bond; |
| 1013 |
+ |
Bend* bend; |
| 1014 |
+ |
Torsion* torsion; |
| 1015 |
+ |
Inversion* inversion; |
| 1016 |
+ |
|
| 1017 |
|
for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
| 1018 |
|
|
| 1019 |
< |
for (atom = mol->beginAtom(atomIter); atom != NULL; |
| 1020 |
< |
atom = mol->nextAtom(atomIter)) { |
| 1019 |
> |
for (atom = mol->beginAtom(ai); atom != NULL; |
| 1020 |
> |
atom = mol->nextAtom(ai)) { |
| 1021 |
|
atom->setSnapshotManager(sman_); |
| 1022 |
< |
} |
| 1000 |
< |
|
| 1022 |
> |
} |
| 1023 |
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 1024 |
|
rb = mol->nextRigidBody(rbIter)) { |
| 1025 |
|
rb->setSnapshotManager(sman_); |
| 1026 |
|
} |
| 1005 |
– |
|
| 1027 |
|
for (cg = mol->beginCutoffGroup(cgIter); cg != NULL; |
| 1028 |
|
cg = mol->nextCutoffGroup(cgIter)) { |
| 1029 |
|
cg->setSnapshotManager(sman_); |
| 1030 |
|
} |
| 1031 |
< |
} |
| 1032 |
< |
|
| 1031 |
> |
for (bond = mol->beginBond(bondIter); bond != NULL; |
| 1032 |
> |
bond = mol->nextBond(bondIter)) { |
| 1033 |
> |
bond->setSnapshotManager(sman_); |
| 1034 |
> |
} |
| 1035 |
> |
for (bend = mol->beginBend(bendIter); bend != NULL; |
| 1036 |
> |
bend = mol->nextBend(bendIter)) { |
| 1037 |
> |
bend->setSnapshotManager(sman_); |
| 1038 |
> |
} |
| 1039 |
> |
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; |
| 1040 |
> |
torsion = mol->nextTorsion(torsionIter)) { |
| 1041 |
> |
torsion->setSnapshotManager(sman_); |
| 1042 |
> |
} |
| 1043 |
> |
for (inversion = mol->beginInversion(inversionIter); inversion != NULL; |
| 1044 |
> |
inversion = mol->nextInversion(inversionIter)) { |
| 1045 |
> |
inversion->setSnapshotManager(sman_); |
| 1046 |
> |
} |
| 1047 |
> |
} |
| 1048 |
|
} |
| 1049 |
|
|
| 1050 |
|
|
| 1070 |
|
IOIndexToIntegrableObject= v; |
| 1071 |
|
} |
| 1072 |
|
|
| 1073 |
< |
int SimInfo::getNGlobalConstraints() { |
| 1038 |
< |
int nGlobalConstraints; |
| 1073 |
> |
void SimInfo::calcNConstraints() { |
| 1074 |
|
#ifdef IS_MPI |
| 1075 |
< |
MPI::COMM_WORLD.Allreduce(&nConstraints_, &nGlobalConstraints, 1, |
| 1076 |
< |
MPI::INT, MPI::SUM); |
| 1075 |
> |
MPI_Allreduce(&nConstraints_, &nGlobalConstraints_, 1, |
| 1076 |
> |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 1077 |
|
#else |
| 1078 |
< |
nGlobalConstraints = nConstraints_; |
| 1078 |
> |
nGlobalConstraints_ = nConstraints_; |
| 1079 |
|
#endif |
| 1045 |
– |
return nGlobalConstraints; |
| 1080 |
|
} |
| 1081 |
|
|
| 1082 |
|
}//end namespace OpenMD |