ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/brains/SimCreator.cpp
(Generate patch)

Comparing trunk/src/brains/SimCreator.cpp (file contents):
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC vs.
Revision 2047 by gezelter, Thu Dec 11 16:16:43 2014 UTC

# Line 1 | Line 1
1   /*
2 < * copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
2 > * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
5   * non-exclusive, royalty free, license to use, modify and
# Line 46 | Line 46
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>
# Line 58 | Line 64
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"
# Line 83 | Line 90
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    
# Line 101 | Line 104 | namespace OpenMD {
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,
111 <                                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 {
117        MPI::COMM_WORLD.Bcast(&mdFileVersion, 1, MPI::INT, masterNode);
120  
121 <        //get stream size
120 <        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        }
# Line 148 | Line 151 | namespace OpenMD {
151        parser.initializeASTFactory(factory);
152        parser.setASTFactory(&factory);
153        parser.mdfile();
151
154        // Create a tree parser that reads information into Globals
155        MDTreeParser treeParser;
156        treeParser.initializeASTFactory(factory);
# Line 226 | Line 228 | namespace OpenMD {
228      catch (OpenMDException& e) {
229        sprintf(painCave.errMsg,
230                "%s\n",
231 <              e.getMessage().c_str());
231 >              e.what());
232        painCave.isFatal = 1;
233        simError();
234      }
# Line 262 | Line 264 | namespace OpenMD {
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()) {
# Line 519 | Line 521 | namespace OpenMD {
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,
# Line 638 | Line 640 | namespace OpenMD {
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      
# Line 782 | Line 785 | namespace OpenMD {
785        }
786      }
787  
788 <    if (simParams->getOutputElectricField() | simParams->haveElectricField()) {
788 >    if (simParams->getOutputElectricField() |
789 >        simParams->haveElectricField() | simParams->haveUniformField() |
790 >        simParams->haveUniformGradientStrength() |
791 >        simParams->haveUniformGradientDirection1() |
792 >        simParams->haveUniformGradientDirection2() ) {
793        storageLayout |= DataStorage::dslElectricField;
794      }
795  
796 +    if (simParams->getOutputSitePotential() ) {
797 +      storageLayout |= DataStorage::dslSitePotential;
798 +    }
799 +
800      if (simParams->getOutputFluctuatingCharges()) {
801        storageLayout |= DataStorage::dslFlucQPosition;
802        storageLayout |= DataStorage::dslFlucQVelocity;
# Line 802 | Line 813 | namespace OpenMD {
813      Molecule::AtomIterator ai;
814      Molecule::RigidBodyIterator ri;
815      Molecule::CutoffGroupIterator ci;
816 +    Molecule::BondIterator boi;
817 +    Molecule::BendIterator bei;
818 +    Molecule::TorsionIterator ti;
819 +    Molecule::InversionIterator ii;
820      Molecule::IntegrableObjectIterator  ioi;
821 <    Molecule * mol;
822 <    Atom * atom;
823 <    RigidBody * rb;
824 <    CutoffGroup * cg;
821 >    Molecule* mol;
822 >    Atom* atom;
823 >    RigidBody* rb;
824 >    CutoffGroup* cg;
825 >    Bond* bond;
826 >    Bend* bend;
827 >    Torsion* torsion;
828 >    Inversion* inversion;
829      int beginAtomIndex;
830      int beginRigidBodyIndex;
831      int beginCutoffGroupIndex;
832 +    int beginBondIndex;
833 +    int beginBendIndex;
834 +    int beginTorsionIndex;
835 +    int beginInversionIndex;
836      int nGlobalAtoms = info->getNGlobalAtoms();
837      int nGlobalRigidBodies = info->getNGlobalRigidBodies();
838      
839      beginAtomIndex = 0;
840 <    //rigidbody's index begins right after atom's
840 >    // The rigid body indices begin immediately after the atom indices:
841      beginRigidBodyIndex = info->getNGlobalAtoms();
842      beginCutoffGroupIndex = 0;
843 <
843 >    beginBondIndex = 0;
844 >    beginBendIndex = 0;
845 >    beginTorsionIndex = 0;
846 >    beginInversionIndex = 0;
847 >  
848      for(int i = 0; i < info->getNGlobalMolecules(); i++) {
849        
850   #ifdef IS_MPI      
# Line 826 | Line 853 | namespace OpenMD {
853          // stuff to do if I own this molecule
854          mol = info->getMoleculeByGlobalIndex(i);
855  
856 <        //local index(index in DataStorge) of atom is important
857 <        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
856 >        // The local index(index in DataStorge) of the atom is important:
857 >        for(atom = mol->beginAtom(ai); atom != NULL;
858 >            atom = mol->nextAtom(ai)) {
859            atom->setGlobalIndex(beginAtomIndex++);
860          }
861          
# Line 836 | Line 864 | namespace OpenMD {
864            rb->setGlobalIndex(beginRigidBodyIndex++);
865          }
866          
867 <        //local index of cutoff group is trivial, it only depends on
868 <        //the order of travesing
867 >        // The local index of other objects only depends on the order
868 >        // of traversal:
869          for(cg = mol->beginCutoffGroup(ci); cg != NULL;
870              cg = mol->nextCutoffGroup(ci)) {
871            cg->setGlobalIndex(beginCutoffGroupIndex++);
872          }        
873 +        for(bond = mol->beginBond(boi); bond != NULL;
874 +            bond = mol->nextBond(boi)) {
875 +          bond->setGlobalIndex(beginBondIndex++);
876 +        }        
877 +        for(bend = mol->beginBend(bei); bend != NULL;
878 +            bend = mol->nextBend(bei)) {
879 +          bend->setGlobalIndex(beginBendIndex++);
880 +        }        
881 +        for(torsion = mol->beginTorsion(ti); torsion != NULL;
882 +            torsion = mol->nextTorsion(ti)) {
883 +          torsion->setGlobalIndex(beginTorsionIndex++);
884 +        }        
885 +        for(inversion = mol->beginInversion(ii); inversion != NULL;
886 +            inversion = mol->nextInversion(ii)) {
887 +          inversion->setGlobalIndex(beginInversionIndex++);
888 +        }        
889          
890   #ifdef IS_MPI        
891        }  else {
# Line 854 | Line 898 | namespace OpenMD {
898          beginAtomIndex += stamp->getNAtoms();
899          beginRigidBodyIndex += stamp->getNRigidBodies();
900          beginCutoffGroupIndex += stamp->getNCutoffGroups() + stamp->getNFreeAtoms();
901 +        beginBondIndex += stamp->getNBonds();
902 +        beginBendIndex += stamp->getNBends();
903 +        beginTorsionIndex += stamp->getNTorsions();
904 +        beginInversionIndex += stamp->getNInversions();
905        }
906   #endif          
907  
# Line 861 | Line 909 | namespace OpenMD {
909  
910      //fill globalGroupMembership
911      std::vector<int> globalGroupMembership(info->getNGlobalAtoms(), 0);
912 <    for(mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {        
913 <      for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
914 <        
912 >    for(mol = info->beginMolecule(mi); mol != NULL;
913 >        mol = info->nextMolecule(mi)) {        
914 >      for (cg = mol->beginCutoffGroup(ci); cg != NULL;
915 >           cg = mol->nextCutoffGroup(ci)) {        
916          for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
917            globalGroupMembership[atom->getGlobalIndex()] = cg->getGlobalIndex();
918          }
# Line 878 | Line 927 | namespace OpenMD {
927      // This would be prettier if we could use MPI_IN_PLACE like the MPI-2
928      // docs said we could.
929      std::vector<int> tmpGroupMembership(info->getNGlobalAtoms(), 0);
930 <    MPI::COMM_WORLD.Allreduce(&globalGroupMembership[0],
931 <                              &tmpGroupMembership[0], nGlobalAtoms,
932 <                              MPI::INT, MPI::SUM);
930 >    MPI_Allreduce(&globalGroupMembership[0],
931 >                  &tmpGroupMembership[0], nGlobalAtoms,
932 >                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
933 >
934      info->setGlobalGroupMembership(tmpGroupMembership);
935   #else
936      info->setGlobalGroupMembership(globalGroupMembership);
# Line 904 | Line 954 | namespace OpenMD {
954   #ifdef IS_MPI
955      std::vector<int> tmpMolMembership(info->getNGlobalAtoms() +
956                                        info->getNGlobalRigidBodies(), 0);
957 <    MPI::COMM_WORLD.Allreduce(&globalMolMembership[0], &tmpMolMembership[0],
958 <                              nGlobalAtoms + nGlobalRigidBodies,
959 <                              MPI::INT, MPI::SUM);
957 >    MPI_Allreduce(&globalMolMembership[0], &tmpMolMembership[0],
958 >                  nGlobalAtoms + nGlobalRigidBodies,
959 >                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
960      
961      info->setGlobalMolMembership(tmpMolMembership);
962   #else
# Line 924 | Line 974 | namespace OpenMD {
974      
975   #ifdef IS_MPI
976      std::vector<int> numIntegrableObjectsPerMol(info->getNGlobalMolecules(), 0);
977 <    MPI::COMM_WORLD.Allreduce(&nIOPerMol[0], &numIntegrableObjectsPerMol[0],
978 <                              info->getNGlobalMolecules(), MPI::INT, MPI::SUM);
977 >    MPI_Allreduce(&nIOPerMol[0], &numIntegrableObjectsPerMol[0],
978 >      info->getNGlobalMolecules(), MPI_INT, MPI_SUM, MPI_COMM_WORLD);
979   #else
980      std::vector<int> numIntegrableObjectsPerMol = nIOPerMol;
981   #endif    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines