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 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC vs.
Revision 1983 by gezelter, Tue Apr 15 20:36:19 2014 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 {
# Line 72 | Line 72 | 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;
# Line 91 | Line 94 | namespace OpenMD {
94      for (vector<Component*>::iterator i = components.begin();
95           i !=components.end(); ++i) {
96        molStamp = (*i)->getMoleculeStamp();
97 +      if ( (*i)->haveRegion() ) {        
98 +        molStamp->setRegion( (*i)->getRegion() );
99 +      } else {
100 +        // set the region to a disallowed value:
101 +        molStamp->setRegion( -1 );
102 +      }
103 +
104        nMolWithSameStamp = (*i)->getNMol();
105        
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;
# Line 268 | Line 282 | namespace OpenMD {
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;
# Line 284 | Line 298 | namespace OpenMD {
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
# Line 340 | Line 354 | namespace OpenMD {
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
# Line 351 | Line 365 | namespace OpenMD {
365  
366      ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
367  
354
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_;
363
376    }
377  
378    void SimInfo::addInteractionPairs(Molecule* mol) {
# Line 411 | Line 423 | namespace OpenMD {
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)) {
# Line 696 | Line 709 | namespace OpenMD {
709     */
710    void SimInfo::update() {  
711      setupSimVariables();
712 +    calcNConstraints();
713      calcNdf();
714      calcNdfRaw();
715      calcNdfTrans();
# Line 735 | Line 749 | namespace OpenMD {
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 >    // int nproc = MPI::COMM_WORLD.Get_size();
755  
756      // we need arrays to hold the counts and displacement vectors for
757      // all processors
# Line 743 | 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 >    // MPI::COMM_WORLD.Allgather(&count_local, 1, MPI::INT, &counts[0],
765 >    //                           1, MPI::INT);
766    
767      // use the processor counts to compute the displacement array
768      disps[0] = 0;    
# Line 758 | Line 776 | namespace OpenMD {
776      vector<int> ftGlobal(totalCount);
777      
778      // now spray out the foundTypes to all the other processors:    
779 <    MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT,
780 <                               &ftGlobal[0], &counts[0], &disps[0],
781 <                               MPI::INT);
779 >    MPI_Allgatherv(&foundTypes[0], count_local, MPI_INT,
780 >                   &ftGlobal[0], &counts[0], &disps[0],
781 >                   MPI_INT, MPI_COMM_WORLD);
782 >    // MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT,
783 >    //                            &ftGlobal[0], &counts[0], &disps[0],
784 >    //                            MPI::INT);
785  
786      vector<int>::iterator j;
787  
# Line 824 | Line 845 | namespace OpenMD {
845      }
846  
847   #ifdef IS_MPI
848 <    bool temp;
848 >    int temp;
849 >
850      temp = usesDirectional;
851 <    MPI::COMM_WORLD.Allreduce(&temp, &usesDirectionalAtoms_, 1, MPI::BOOL,
852 <                              MPI::LOR);
831 <        
832 <    temp = usesMetallic;
833 <    MPI::COMM_WORLD.Allreduce(&temp, &usesMetallicAtoms_, 1, MPI::BOOL,
834 <                              MPI::LOR);
851 >    MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT,  MPI_LOR, MPI_COMM_WORLD);
852 >    usesDirectionalAtoms_ = (temp == 0) ? false : true;
853      
854 +    temp = usesMetallic;
855 +    MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT,  MPI_LOR, MPI_COMM_WORLD);
856 +    usesMetallicAtoms_ = (temp == 0) ? false : true;
857 +
858      temp = usesElectrostatic;
859 <    MPI::COMM_WORLD.Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI::BOOL,
860 <                              MPI::LOR);
859 >    MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT,  MPI_LOR, MPI_COMM_WORLD);
860 >    usesElectrostaticAtoms_ = (temp == 0) ? false : true;
861  
862      temp = usesFluctuatingCharges;
863 <    MPI::COMM_WORLD.Allreduce(&temp, &usesFluctuatingCharges_, 1, MPI::BOOL,
864 <                              MPI::LOR);
863 >    MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT,  MPI_LOR, MPI_COMM_WORLD);
864 >    usesFluctuatingCharges_ = (temp == 0) ? false : true;
865   #else
866  
867      usesDirectionalAtoms_ = usesDirectional;
# Line 931 | Line 953 | namespace OpenMD {
953        }      
954      }
955  
956 <    // Build the identArray_
956 >    // Build the identArray_ and regions_
957  
958      identArray_.clear();
959 <    identArray_.reserve(getNAtoms());    
960 <    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
959 >    identArray_.reserve(getNAtoms());  
960 >    regions_.clear();
961 >    regions_.reserve(getNAtoms());
962 >
963 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {      
964 >      int reg = mol->getRegion();      
965        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
966          identArray_.push_back(atom->getIdent());
967 +        regions_.push_back(reg);
968        }
969      }    
970 <    
970 >      
971      topologyDone_ = true;
972    }
973  
# Line 975 | Line 1002 | namespace OpenMD {
1002      delete sman_;
1003      sman_ = sman;
1004  
978    Molecule* mol;
979    RigidBody* rb;
980    Atom* atom;
981    CutoffGroup* cg;
1005      SimInfo::MoleculeIterator mi;
1006 +    Molecule::AtomIterator ai;
1007      Molecule::RigidBodyIterator rbIter;
984    Molecule::AtomIterator atomIter;
1008      Molecule::CutoffGroupIterator cgIter;
1009 +    Molecule::BondIterator bondIter;
1010 +    Molecule::BendIterator bendIter;
1011 +    Molecule::TorsionIterator torsionIter;
1012 +    Molecule::InversionIterator inversionIter;
1013  
1014 +    Molecule* mol;
1015 +    Atom* atom;
1016 +    RigidBody* rb;
1017 +    CutoffGroup* cg;
1018 +    Bond* bond;
1019 +    Bend* bend;
1020 +    Torsion* torsion;
1021 +    Inversion* inversion;    
1022 +
1023      for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
1024          
1025 <      for (atom = mol->beginAtom(atomIter); atom != NULL;
1026 <           atom = mol->nextAtom(atomIter)) {
1025 >      for (atom = mol->beginAtom(ai); atom != NULL;
1026 >           atom = mol->nextAtom(ai)) {
1027          atom->setSnapshotManager(sman_);
1028 <      }
993 <        
1028 >      }        
1029        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
1030             rb = mol->nextRigidBody(rbIter)) {
1031          rb->setSnapshotManager(sman_);
1032        }
998
1033        for (cg = mol->beginCutoffGroup(cgIter); cg != NULL;
1034             cg = mol->nextCutoffGroup(cgIter)) {
1035          cg->setSnapshotManager(sman_);
1036        }
1037 <    }    
1038 <    
1037 >      for (bond = mol->beginBond(bondIter); bond != NULL;
1038 >           bond = mol->nextBond(bondIter)) {
1039 >        bond->setSnapshotManager(sman_);
1040 >      }
1041 >      for (bend = mol->beginBend(bendIter); bend != NULL;
1042 >           bend = mol->nextBend(bendIter)) {
1043 >        bend->setSnapshotManager(sman_);
1044 >      }
1045 >      for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
1046 >           torsion = mol->nextTorsion(torsionIter)) {
1047 >        torsion->setSnapshotManager(sman_);
1048 >      }
1049 >      for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
1050 >           inversion = mol->nextInversion(inversionIter)) {
1051 >        inversion->setSnapshotManager(sman_);
1052 >      }
1053 >    }
1054    }
1055  
1056  
# Line 1027 | Line 1076 | namespace OpenMD {
1076      IOIndexToIntegrableObject= v;
1077    }
1078  
1079 <  int SimInfo::getNGlobalConstraints() {
1031 <    int nGlobalConstraints;
1079 >  void SimInfo::calcNConstraints() {
1080   #ifdef IS_MPI
1081 <    MPI::COMM_WORLD.Allreduce(&nConstraints_, &nGlobalConstraints, 1,
1082 <                              MPI::INT, MPI::SUM);
1081 >    MPI_Allreduce(&nConstraints_, &nGlobalConstraints_, 1,  
1082 >                  MPI_INT, MPI_SUM, MPI_COMM_WORLD);
1083   #else
1084 <    nGlobalConstraints =  nConstraints_;
1084 >    nGlobalConstraints_ =  nConstraints_;
1085   #endif
1038    return nGlobalConstraints;
1086    }
1087  
1088   }//end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines