46 |
|
* @date 11/03/2004 |
47 |
|
* @version 1.0 |
48 |
|
*/ |
49 |
+ |
|
50 |
+ |
#ifdef IS_MPI |
51 |
+ |
#include "mpi.h" |
52 |
+ |
#include "math/ParallelRandNumGen.hpp" |
53 |
+ |
#endif |
54 |
+ |
|
55 |
|
#include <exception> |
56 |
|
#include <iostream> |
57 |
|
#include <sstream> |
64 |
|
#include "brains/ForceField.hpp" |
65 |
|
#include "utils/simError.h" |
66 |
|
#include "utils/StringUtils.hpp" |
67 |
+ |
#include "utils/Revision.hpp" |
68 |
|
#include "math/SeqRandNumGen.hpp" |
69 |
|
#include "mdParser/MDLexer.hpp" |
70 |
|
#include "mdParser/MDParser.hpp" |
90 |
|
#include "types/FixedChargeAdapter.hpp" |
91 |
|
#include "types/FluctuatingChargeAdapter.hpp" |
92 |
|
|
86 |
– |
#ifdef IS_MPI |
87 |
– |
#include "mpi.h" |
88 |
– |
#include "math/ParallelRandNumGen.hpp" |
89 |
– |
#endif |
93 |
|
|
94 |
|
namespace OpenMD { |
95 |
|
|
104 |
|
const int masterNode = 0; |
105 |
|
|
106 |
|
if (worldRank == masterNode) { |
107 |
< |
MPI::COMM_WORLD.Bcast(&mdFileVersion, 1, MPI::INT, masterNode); |
107 |
> |
MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
108 |
|
#endif |
109 |
|
SimplePreprocessor preprocessor; |
110 |
< |
preprocessor.preprocess(rawMetaDataStream, filename, startOfMetaDataBlock, ppStream); |
110 |
> |
preprocessor.preprocess(rawMetaDataStream, filename, |
111 |
> |
startOfMetaDataBlock, ppStream); |
112 |
|
|
113 |
|
#ifdef IS_MPI |
114 |
< |
//brocasting the stream size |
114 |
> |
//broadcasting the stream size |
115 |
|
streamSize = ppStream.str().size() +1; |
116 |
< |
MPI::COMM_WORLD.Bcast(&streamSize, 1, MPI::LONG, masterNode); |
117 |
< |
MPI::COMM_WORLD.Bcast(static_cast<void*>(const_cast<char*>(ppStream.str().c_str())), streamSize, MPI::CHAR, masterNode); |
118 |
< |
|
116 |
> |
MPI_Bcast(&streamSize, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
117 |
> |
MPI_Bcast(static_cast<void*>(const_cast<char*>(ppStream.str().c_str())), |
118 |
> |
streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); |
119 |
|
} else { |
116 |
– |
MPI::COMM_WORLD.Bcast(&mdFileVersion, 1, MPI::INT, masterNode); |
120 |
|
|
121 |
< |
//get stream size |
119 |
< |
MPI::COMM_WORLD.Bcast(&streamSize, 1, MPI::LONG, masterNode); |
121 |
> |
MPI_Bcast(&mdFileVersion, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
122 |
|
|
123 |
+ |
//get stream size |
124 |
+ |
MPI_Bcast(&streamSize, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
125 |
|
char* buf = new char[streamSize]; |
126 |
|
assert(buf); |
127 |
|
|
128 |
|
//receive file content |
129 |
< |
MPI::COMM_WORLD.Bcast(buf, streamSize, MPI::CHAR, masterNode); |
130 |
< |
|
129 |
> |
MPI_Bcast(buf, streamSize, MPI_CHAR, masterNode, MPI_COMM_WORLD); |
130 |
> |
|
131 |
|
ppStream.str(buf); |
132 |
|
delete [] buf; |
133 |
|
} |
151 |
|
parser.initializeASTFactory(factory); |
152 |
|
parser.setASTFactory(&factory); |
153 |
|
parser.mdfile(); |
150 |
– |
|
154 |
|
// Create a tree parser that reads information into Globals |
155 |
|
MDTreeParser treeParser; |
156 |
|
treeParser.initializeASTFactory(factory); |
264 |
|
version.append("."); |
265 |
|
version.append(OPENMD_VERSION_MINOR); |
266 |
|
|
267 |
< |
std::string svnrev; |
267 |
> |
std::string svnrev(g_REVISION, strnlen(g_REVISION, 20)); |
268 |
|
//convert a macro from compiler to a string in c++ |
269 |
< |
STR_DEFINE(svnrev, SVN_REV ); |
269 |
> |
// STR_DEFINE(svnrev, SVN_REV ); |
270 |
|
version.append(" Revision: "); |
271 |
|
// If there's no SVN revision, just call this the RELEASE revision. |
272 |
|
if (!svnrev.empty()) { |
521 |
|
// error |
522 |
|
// condition: |
523 |
|
|
524 |
< |
nProcessors = MPI::COMM_WORLD.Get_size(); |
524 |
> |
MPI_Comm_size( MPI_COMM_WORLD, &nProcessors); |
525 |
|
|
526 |
|
if (nProcessors > nGlobalMols) { |
527 |
|
sprintf(painCave.errMsg, |
640 |
|
delete myRandom; |
641 |
|
|
642 |
|
// Spray out this nonsense to all other processors: |
643 |
< |
MPI::COMM_WORLD.Bcast(&molToProcMap[0], nGlobalMols, MPI::INT, 0); |
643 |
> |
MPI_Bcast(&molToProcMap[0], nGlobalMols, MPI_INT, 0, MPI_COMM_WORLD); |
644 |
> |
|
645 |
|
} else { |
646 |
|
|
647 |
|
// Listen to your marching orders from processor 0: |
648 |
< |
MPI::COMM_WORLD.Bcast(&molToProcMap[0], nGlobalMols, MPI::INT, 0); |
648 |
> |
MPI_Bcast(&molToProcMap[0], nGlobalMols, MPI_INT, 0, MPI_COMM_WORLD); |
649 |
|
|
650 |
|
} |
651 |
|
|
805 |
|
Molecule::AtomIterator ai; |
806 |
|
Molecule::RigidBodyIterator ri; |
807 |
|
Molecule::CutoffGroupIterator ci; |
808 |
+ |
Molecule::BondIterator boi; |
809 |
+ |
Molecule::BendIterator bei; |
810 |
+ |
Molecule::TorsionIterator ti; |
811 |
+ |
Molecule::InversionIterator ii; |
812 |
|
Molecule::IntegrableObjectIterator ioi; |
813 |
< |
Molecule * mol; |
814 |
< |
Atom * atom; |
815 |
< |
RigidBody * rb; |
816 |
< |
CutoffGroup * cg; |
813 |
> |
Molecule* mol; |
814 |
> |
Atom* atom; |
815 |
> |
RigidBody* rb; |
816 |
> |
CutoffGroup* cg; |
817 |
> |
Bond* bond; |
818 |
> |
Bend* bend; |
819 |
> |
Torsion* torsion; |
820 |
> |
Inversion* inversion; |
821 |
|
int beginAtomIndex; |
822 |
|
int beginRigidBodyIndex; |
823 |
|
int beginCutoffGroupIndex; |
824 |
+ |
int beginBondIndex; |
825 |
+ |
int beginBendIndex; |
826 |
+ |
int beginTorsionIndex; |
827 |
+ |
int beginInversionIndex; |
828 |
|
int nGlobalAtoms = info->getNGlobalAtoms(); |
829 |
|
int nGlobalRigidBodies = info->getNGlobalRigidBodies(); |
830 |
|
|
831 |
|
beginAtomIndex = 0; |
832 |
< |
//rigidbody's index begins right after atom's |
832 |
> |
// The rigid body indices begin immediately after the atom indices: |
833 |
|
beginRigidBodyIndex = info->getNGlobalAtoms(); |
834 |
|
beginCutoffGroupIndex = 0; |
835 |
< |
|
835 |
> |
beginBondIndex = 0; |
836 |
> |
beginBendIndex = 0; |
837 |
> |
beginTorsionIndex = 0; |
838 |
> |
beginInversionIndex = 0; |
839 |
> |
|
840 |
|
for(int i = 0; i < info->getNGlobalMolecules(); i++) { |
841 |
|
|
842 |
|
#ifdef IS_MPI |
845 |
|
// stuff to do if I own this molecule |
846 |
|
mol = info->getMoleculeByGlobalIndex(i); |
847 |
|
|
848 |
< |
//local index(index in DataStorge) of atom is important |
849 |
< |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
848 |
> |
// The local index(index in DataStorge) of the atom is important: |
849 |
> |
for(atom = mol->beginAtom(ai); atom != NULL; |
850 |
> |
atom = mol->nextAtom(ai)) { |
851 |
|
atom->setGlobalIndex(beginAtomIndex++); |
852 |
|
} |
853 |
|
|
856 |
|
rb->setGlobalIndex(beginRigidBodyIndex++); |
857 |
|
} |
858 |
|
|
859 |
< |
//local index of cutoff group is trivial, it only depends on |
860 |
< |
//the order of travesing |
859 |
> |
// The local index of other objects only depends on the order |
860 |
> |
// of traversal: |
861 |
|
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
862 |
|
cg = mol->nextCutoffGroup(ci)) { |
863 |
|
cg->setGlobalIndex(beginCutoffGroupIndex++); |
864 |
|
} |
865 |
+ |
for(bond = mol->beginBond(boi); bond != NULL; |
866 |
+ |
bond = mol->nextBond(boi)) { |
867 |
+ |
bond->setGlobalIndex(beginBondIndex++); |
868 |
+ |
} |
869 |
+ |
for(bend = mol->beginBend(bei); bend != NULL; |
870 |
+ |
bend = mol->nextBend(bei)) { |
871 |
+ |
bend->setGlobalIndex(beginBendIndex++); |
872 |
+ |
} |
873 |
+ |
for(torsion = mol->beginTorsion(ti); torsion != NULL; |
874 |
+ |
torsion = mol->nextTorsion(ti)) { |
875 |
+ |
torsion->setGlobalIndex(beginTorsionIndex++); |
876 |
+ |
} |
877 |
+ |
for(inversion = mol->beginInversion(ii); inversion != NULL; |
878 |
+ |
inversion = mol->nextInversion(ii)) { |
879 |
+ |
inversion->setGlobalIndex(beginInversionIndex++); |
880 |
+ |
} |
881 |
|
|
882 |
|
#ifdef IS_MPI |
883 |
|
} else { |
890 |
|
beginAtomIndex += stamp->getNAtoms(); |
891 |
|
beginRigidBodyIndex += stamp->getNRigidBodies(); |
892 |
|
beginCutoffGroupIndex += stamp->getNCutoffGroups() + stamp->getNFreeAtoms(); |
893 |
+ |
beginBondIndex += stamp->getNBonds(); |
894 |
+ |
beginBendIndex += stamp->getNBends(); |
895 |
+ |
beginTorsionIndex += stamp->getNTorsions(); |
896 |
+ |
beginInversionIndex += stamp->getNInversions(); |
897 |
|
} |
898 |
|
#endif |
899 |
|
|
901 |
|
|
902 |
|
//fill globalGroupMembership |
903 |
|
std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), 0); |
904 |
< |
for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { |
905 |
< |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
906 |
< |
|
904 |
> |
for(mol = info->beginMolecule(mi); mol != NULL; |
905 |
> |
mol = info->nextMolecule(mi)) { |
906 |
> |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; |
907 |
> |
cg = mol->nextCutoffGroup(ci)) { |
908 |
|
for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
909 |
|
globalGroupMembership[atom->getGlobalIndex()] = cg->getGlobalIndex(); |
910 |
|
} |
919 |
|
// This would be prettier if we could use MPI_IN_PLACE like the MPI-2 |
920 |
|
// docs said we could. |
921 |
|
std::vector<int> tmpGroupMembership(info->getNGlobalAtoms(), 0); |
922 |
< |
MPI::COMM_WORLD.Allreduce(&globalGroupMembership[0], |
923 |
< |
&tmpGroupMembership[0], nGlobalAtoms, |
924 |
< |
MPI::INT, MPI::SUM); |
922 |
> |
MPI_Allreduce(&globalGroupMembership[0], |
923 |
> |
&tmpGroupMembership[0], nGlobalAtoms, |
924 |
> |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
925 |
> |
|
926 |
|
info->setGlobalGroupMembership(tmpGroupMembership); |
927 |
|
#else |
928 |
|
info->setGlobalGroupMembership(globalGroupMembership); |
946 |
|
#ifdef IS_MPI |
947 |
|
std::vector<int> tmpMolMembership(info->getNGlobalAtoms() + |
948 |
|
info->getNGlobalRigidBodies(), 0); |
949 |
< |
MPI::COMM_WORLD.Allreduce(&globalMolMembership[0], &tmpMolMembership[0], |
950 |
< |
nGlobalAtoms + nGlobalRigidBodies, |
951 |
< |
MPI::INT, MPI::SUM); |
949 |
> |
MPI_Allreduce(&globalMolMembership[0], &tmpMolMembership[0], |
950 |
> |
nGlobalAtoms + nGlobalRigidBodies, |
951 |
> |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
952 |
|
|
953 |
|
info->setGlobalMolMembership(tmpMolMembership); |
954 |
|
#else |
966 |
|
|
967 |
|
#ifdef IS_MPI |
968 |
|
std::vector<int> numIntegrableObjectsPerMol(info->getNGlobalMolecules(), 0); |
969 |
< |
MPI::COMM_WORLD.Allreduce(&nIOPerMol[0], &numIntegrableObjectsPerMol[0], |
970 |
< |
info->getNGlobalMolecules(), MPI::INT, MPI::SUM); |
969 |
> |
MPI_Allreduce(&nIOPerMol[0], &numIntegrableObjectsPerMol[0], |
970 |
> |
info->getNGlobalMolecules(), MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
971 |
|
#else |
972 |
|
std::vector<int> numIntegrableObjectsPerMol = nIOPerMol; |
973 |
|
#endif |