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

Comparing trunk/src/brains/SimInfo.cpp (file contents):
Revision 1930 by gezelter, Mon Aug 19 13:51:04 2013 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 47 | Line 47
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>
# Line 61 | Line 64
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 {
70    
71    SimInfo::SimInfo(ForceField* ff, Globals* simParams) :
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),
73 >    nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nInversions_(0),
74      nRigidBodies_(0), nIntegrableObjects_(0), nCutoffGroups_(0),
75 <    nConstraints_(0), nFluctuatingCharges_(0), sman_(NULL), topologyDone_(false),
76 <    calcBoxDipole_(false), useAtomicVirial_(true) {    
75 >    nConstraints_(0), nFluctuatingCharges_(0),    
76 >    nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0),
77 >    nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
78 >    nGlobalFluctuatingCharges_(0), nGlobalBonds_(0), nGlobalBends_(0),
79 >    nGlobalTorsions_(0), nGlobalInversions_(0), nGlobalConstraints_(0),
80 >    hasNGlobalConstraints_(false),
81 >    ndf_(0), fdf_local(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
82 >    sman_(NULL), topologyDone_(false), calcBoxDipole_(false),
83 >    calcBoxQuadrupole_(false), useAtomicVirial_(true) {    
84      
85      MoleculeStamp* molStamp;
86      int nMolWithSameStamp;
# Line 103 | Line 107 | namespace OpenMD {
107        addMoleculeStamp(molStamp, nMolWithSameStamp);
108        
109        //calculate atoms in molecules
110 <      nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp;  
110 >      nGlobalAtoms_ += molStamp->getNAtoms() * nMolWithSameStamp;
111 >      nGlobalBonds_ += molStamp->getNBonds() * nMolWithSameStamp;
112 >      nGlobalBends_ += molStamp->getNBends() * nMolWithSameStamp;
113 >      nGlobalTorsions_ += molStamp->getNTorsions() * nMolWithSameStamp;
114 >      nGlobalInversions_ += molStamp->getNInversions() * nMolWithSameStamp;
115        
116        //calculate atoms in cutoff groups
117        int nAtomsInGroups = 0;
# Line 275 | Line 283 | namespace OpenMD {
283      ndf_local -= nConstraints_;
284  
285   #ifdef IS_MPI
286 <    MPI::COMM_WORLD.Allreduce(&ndf_local, &ndf_, 1, MPI::INT,MPI::SUM);
287 <    MPI::COMM_WORLD.Allreduce(&nfq_local, &nGlobalFluctuatingCharges_, 1,
288 <                              MPI::INT, MPI::SUM);
286 >    MPI_Allreduce(&ndf_local, &ndf_, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
287 >    MPI_Allreduce(&nfq_local, &nGlobalFluctuatingCharges_, 1,
288 >      MPI_INT, MPI_SUM, MPI_COMM_WORLD);
289   #else
290      ndf_ = ndf_local;
291      nGlobalFluctuatingCharges_ = nfq_local;
# Line 291 | Line 299 | namespace OpenMD {
299  
300    int SimInfo::getFdf() {
301   #ifdef IS_MPI
302 <    MPI::COMM_WORLD.Allreduce(&fdf_local, &fdf_, 1, MPI::INT, MPI::SUM);
302 >    MPI_Allreduce(&fdf_local, &fdf_, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
303   #else
304      fdf_ = fdf_local;
305   #endif
# Line 347 | Line 355 | namespace OpenMD {
355      }
356      
357   #ifdef IS_MPI
358 <    MPI::COMM_WORLD.Allreduce(&ndfRaw_local, &ndfRaw_, 1, MPI::INT, MPI::SUM);
358 >    MPI_Allreduce(&ndfRaw_local, &ndfRaw_, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
359   #else
360      ndfRaw_ = ndfRaw_local;
361   #endif
# Line 358 | Line 366 | namespace OpenMD {
366  
367      ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
368  
361
369   #ifdef IS_MPI
370 <    MPI::COMM_WORLD.Allreduce(&ndfTrans_local, &ndfTrans_, 1,
371 <                              MPI::INT, MPI::SUM);
370 >    MPI_Allreduce(&ndfTrans_local, &ndfTrans_, 1, MPI_INT, MPI_SUM,
371 >                  MPI_COMM_WORLD);
372   #else
373      ndfTrans_ = ndfTrans_local;
374   #endif
375  
376      ndfTrans_ = ndfTrans_ - 3 - nZconstraint_;
370
377    }
378  
379    void SimInfo::addInteractionPairs(Molecule* mol) {
380      ForceFieldOptions& options_ = forceField_->getForceFieldOptions();
375    vector<Atom*>::iterator atomIter;
381      vector<Bond*>::iterator bondIter;
382      vector<Bend*>::iterator bendIter;
383      vector<Torsion*>::iterator torsionIter;
384      vector<Inversion*>::iterator inversionIter;
380    Atom* atom;
385      Bond* bond;
386      Bend* bend;
387      Torsion* torsion;
# Line 706 | Line 710 | namespace OpenMD {
710     */
711    void SimInfo::update() {  
712      setupSimVariables();
713 +    calcNConstraints();
714      calcNdf();
715      calcNdfRaw();
716      calcNdfTrans();
# Line 745 | Line 750 | namespace OpenMD {
750      // count_local holds the number of found types on this processor
751      int count_local = foundTypes.size();
752  
753 <    int nproc = MPI::COMM_WORLD.Get_size();
753 >    int nproc;
754 >    MPI_Comm_size( MPI_COMM_WORLD, &nproc);
755  
756      // we need arrays to hold the counts and displacement vectors for
757      // all processors
# Line 753 | Line 759 | namespace OpenMD {
759      vector<int> disps(nproc, 0);
760  
761      // fill the counts array
762 <    MPI::COMM_WORLD.Allgather(&count_local, 1, MPI::INT, &counts[0],
763 <                              1, MPI::INT);
762 >    MPI_Allgather(&count_local, 1, MPI_INT, &counts[0],
763 >                  1, MPI_INT, MPI_COMM_WORLD);
764    
765      // use the processor counts to compute the displacement array
766      disps[0] = 0;    
# Line 768 | Line 774 | namespace OpenMD {
774      vector<int> ftGlobal(totalCount);
775      
776      // now spray out the foundTypes to all the other processors:    
777 <    MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT,
778 <                               &ftGlobal[0], &counts[0], &disps[0],
779 <                               MPI::INT);
777 >    MPI_Allgatherv(&foundTypes[0], count_local, MPI_INT,
778 >                   &ftGlobal[0], &counts[0], &disps[0],
779 >                   MPI_INT, MPI_COMM_WORLD);
780  
781      vector<int>::iterator j;
782  
# Line 817 | Line 823 | namespace OpenMD {
823        if ( simParams_->getAccumulateBoxDipole() ) {
824          calcBoxDipole_ = true;      
825        }
826 +    // we only call setAccumulateBoxQuadrupole if the accumulateBoxQuadrupole
827 +    // parameter is true
828 +    calcBoxQuadrupole_ = false;
829 +    if ( simParams_->haveAccumulateBoxQuadrupole() )
830 +      if ( simParams_->getAccumulateBoxQuadrupole() ) {
831 +        calcBoxQuadrupole_ = true;      
832 +      }
833      
834      set<AtomType*>::iterator i;
835      set<AtomType*> atomTypes;
# Line 834 | Line 847 | namespace OpenMD {
847      }
848  
849   #ifdef IS_MPI
850 <    bool temp;
850 >    int temp;
851 >
852      temp = usesDirectional;
853 <    MPI::COMM_WORLD.Allreduce(&temp, &usesDirectionalAtoms_, 1, MPI::BOOL,
854 <                              MPI::LOR);
841 <        
842 <    temp = usesMetallic;
843 <    MPI::COMM_WORLD.Allreduce(&temp, &usesMetallicAtoms_, 1, MPI::BOOL,
844 <                              MPI::LOR);
853 >    MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT,  MPI_LOR, MPI_COMM_WORLD);
854 >    usesDirectionalAtoms_ = (temp == 0) ? false : true;
855      
856 +    temp = usesMetallic;
857 +    MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT,  MPI_LOR, MPI_COMM_WORLD);
858 +    usesMetallicAtoms_ = (temp == 0) ? false : true;
859 +
860      temp = usesElectrostatic;
861 <    MPI::COMM_WORLD.Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI::BOOL,
862 <                              MPI::LOR);
861 >    MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT,  MPI_LOR, MPI_COMM_WORLD);
862 >    usesElectrostaticAtoms_ = (temp == 0) ? false : true;
863  
864      temp = usesFluctuatingCharges;
865 <    MPI::COMM_WORLD.Allreduce(&temp, &usesFluctuatingCharges_, 1, MPI::BOOL,
866 <                              MPI::LOR);
865 >    MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT,  MPI_LOR, MPI_COMM_WORLD);
866 >    usesFluctuatingCharges_ = (temp == 0) ? false : true;
867   #else
868  
869      usesDirectionalAtoms_ = usesDirectional;
# Line 990 | Line 1004 | namespace OpenMD {
1004      delete sman_;
1005      sman_ = sman;
1006  
993    Molecule* mol;
994    RigidBody* rb;
995    Atom* atom;
996    CutoffGroup* cg;
1007      SimInfo::MoleculeIterator mi;
1008 +    Molecule::AtomIterator ai;
1009      Molecule::RigidBodyIterator rbIter;
999    Molecule::AtomIterator atomIter;
1010      Molecule::CutoffGroupIterator cgIter;
1011 +    Molecule::BondIterator bondIter;
1012 +    Molecule::BendIterator bendIter;
1013 +    Molecule::TorsionIterator torsionIter;
1014 +    Molecule::InversionIterator inversionIter;
1015  
1016 +    Molecule* mol;
1017 +    Atom* atom;
1018 +    RigidBody* rb;
1019 +    CutoffGroup* cg;
1020 +    Bond* bond;
1021 +    Bend* bend;
1022 +    Torsion* torsion;
1023 +    Inversion* inversion;    
1024 +
1025      for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
1026          
1027 <      for (atom = mol->beginAtom(atomIter); atom != NULL;
1028 <           atom = mol->nextAtom(atomIter)) {
1027 >      for (atom = mol->beginAtom(ai); atom != NULL;
1028 >           atom = mol->nextAtom(ai)) {
1029          atom->setSnapshotManager(sman_);
1030 <      }
1008 <        
1030 >      }        
1031        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
1032             rb = mol->nextRigidBody(rbIter)) {
1033          rb->setSnapshotManager(sman_);
1034        }
1013
1035        for (cg = mol->beginCutoffGroup(cgIter); cg != NULL;
1036             cg = mol->nextCutoffGroup(cgIter)) {
1037          cg->setSnapshotManager(sman_);
1038        }
1039 <    }    
1040 <    
1039 >      for (bond = mol->beginBond(bondIter); bond != NULL;
1040 >           bond = mol->nextBond(bondIter)) {
1041 >        bond->setSnapshotManager(sman_);
1042 >      }
1043 >      for (bend = mol->beginBend(bendIter); bend != NULL;
1044 >           bend = mol->nextBend(bendIter)) {
1045 >        bend->setSnapshotManager(sman_);
1046 >      }
1047 >      for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
1048 >           torsion = mol->nextTorsion(torsionIter)) {
1049 >        torsion->setSnapshotManager(sman_);
1050 >      }
1051 >      for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
1052 >           inversion = mol->nextInversion(inversionIter)) {
1053 >        inversion->setSnapshotManager(sman_);
1054 >      }
1055 >    }
1056    }
1057  
1058  
# Line 1042 | Line 1078 | namespace OpenMD {
1078      IOIndexToIntegrableObject= v;
1079    }
1080  
1081 <  int SimInfo::getNGlobalConstraints() {
1046 <    int nGlobalConstraints;
1081 >  void SimInfo::calcNConstraints() {
1082   #ifdef IS_MPI
1083 <    MPI::COMM_WORLD.Allreduce(&nConstraints_, &nGlobalConstraints, 1,
1084 <                              MPI::INT, MPI::SUM);
1083 >    MPI_Allreduce(&nConstraints_, &nGlobalConstraints_, 1,  
1084 >                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
1085   #else
1086 <    nGlobalConstraints =  nConstraints_;
1086 >    nGlobalConstraints_ =  nConstraints_;
1087   #endif
1053    return nGlobalConstraints;
1088    }
1089  
1090   }//end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines