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

Comparing branches/development/src/brains/SimInfo.cpp (file contents):
Revision 1577 by gezelter, Wed Jun 8 20:26:56 2011 UTC vs.
Revision 1627 by gezelter, Tue Sep 13 22:05:04 2011 UTC

# Line 60 | Line 60
60   #include "io/ForceFieldOptions.hpp"
61   #include "UseTheForce/ForceField.hpp"
62   #include "nonbonded/SwitchingFunction.hpp"
63 + #ifdef IS_MPI
64 + #include <mpi.h>
65 + #endif
66  
67   using namespace std;
68   namespace OpenMD {
# Line 694 | Line 697 | namespace OpenMD {
697      Atom* atom;
698      set<AtomType*> atomTypes;
699      
700 <    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {      
701 <      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
700 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
701 >      for(atom = mol->beginAtom(ai); atom != NULL;
702 >          atom = mol->nextAtom(ai)) {
703          atomTypes.insert(atom->getAtomType());
704        }      
705      }    
706 <
706 >    
707   #ifdef IS_MPI
708  
709      // loop over the found atom types on this processor, and add their
710      // numerical idents to a vector:
711 <
711 >    
712      vector<int> foundTypes;
713      set<AtomType*>::iterator i;
714      for (i = atomTypes.begin(); i != atomTypes.end(); ++i)
# Line 712 | Line 716 | namespace OpenMD {
716  
717      // count_local holds the number of found types on this processor
718      int count_local = foundTypes.size();
715
716    // count holds the total number of found types on all processors
717    // (some will be redundant with the ones found locally):
718    int count;
719    MPI::COMM_WORLD.Allreduce(&count_local, &count, 1, MPI::INT, MPI::SUM);
719  
721    // create a vector to hold the globally found types, and resize it:
722    vector<int> ftGlobal;
723    ftGlobal.resize(count);
724    vector<int> counts;
725
720      int nproc = MPI::COMM_WORLD.Get_size();
727    counts.resize(nproc);
728    vector<int> disps;
729    disps.resize(nproc);
721  
722 <    // now spray out the foundTypes to all the other processors:
722 >    // we need arrays to hold the counts and displacement vectors for
723 >    // all processors
724 >    vector<int> counts(nproc, 0);
725 >    vector<int> disps(nproc, 0);
726 >
727 >    // fill the counts array
728 >    MPI::COMM_WORLD.Allgather(&count_local, 1, MPI::INT, &counts[0],
729 >                              1, MPI::INT);
730 >  
731 >    // use the processor counts to compute the displacement array
732 >    disps[0] = 0;    
733 >    int totalCount = counts[0];
734 >    for (int iproc = 1; iproc < nproc; iproc++) {
735 >      disps[iproc] = disps[iproc-1] + counts[iproc-1];
736 >      totalCount += counts[iproc];
737 >    }
738 >
739 >    // we need a (possibly redundant) set of all found types:
740 >    vector<int> ftGlobal(totalCount);
741      
742 +    // now spray out the foundTypes to all the other processors:    
743      MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT,
744 <                               &ftGlobal[0], &counts[0], &disps[0], MPI::INT);
744 >                               &ftGlobal[0], &counts[0], &disps[0],
745 >                               MPI::INT);
746  
747 +    vector<int>::iterator j;
748 +
749      // foundIdents is a stl set, so inserting an already found ident
750      // will have no effect.
751      set<int> foundIdents;
752 <    vector<int>::iterator j;
752 >
753      for (j = ftGlobal.begin(); j != ftGlobal.end(); ++j)
754        foundIdents.insert((*j));
755      
756      // now iterate over the foundIdents and get the actual atom types
757      // that correspond to these:
758      set<int>::iterator it;
759 <    for (it = foundIdents.begin(); it != foundIdents.end(); ++it)
759 >    for (it = foundIdents.begin(); it != foundIdents.end(); ++it)
760        atomTypes.insert( forceField_->getAtomType((*it)) );
761  
762   #endif
763 <    
763 >
764      return atomTypes;        
765    }
766  
# Line 759 | Line 772 | namespace OpenMD {
772        if ( simParams_->getAccumulateBoxDipole() ) {
773          calcBoxDipole_ = true;      
774        }
775 <
775 >    
776      set<AtomType*>::iterator i;
777      set<AtomType*> atomTypes;
778      atomTypes = getSimulatedAtomTypes();    
# Line 772 | Line 785 | namespace OpenMD {
785        usesMetallic |= (*i)->isMetal();
786        usesDirectional |= (*i)->isDirectional();
787      }
788 <
788 >    
789   #ifdef IS_MPI    
790      int temp;
791      temp = usesDirectional;
792      MPI_Allreduce(&temp, &usesDirectionalAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
793 <
793 >    
794      temp = usesMetallic;
795      MPI_Allreduce(&temp, &usesMetallicAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
796 <
796 >    
797      temp = usesElectrostatic;
798      MPI_Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
799 + #else
800 +
801 +    usesDirectionalAtoms_ = usesDirectional;
802 +    usesMetallicAtoms_ = usesMetallic;
803 +    usesElectrostaticAtoms_ = usesElectrostatic;
804 +
805   #endif
806 +    
807 +    requiresPrepair_ = usesMetallicAtoms_ ? true : false;
808 +    requiresSkipCorrection_ = usesElectrostaticAtoms_ ? true : false;
809 +    requiresSelfCorrection_ = usesElectrostaticAtoms_ ? true : false;    
810    }
811  
812  
# Line 838 | Line 861 | namespace OpenMD {
861      Atom* atom;
862      RealType totalMass;
863  
864 <    //to avoid memory reallocation, reserve enough space for massFactors_
864 >    /**
865 >     * The mass factor is the relative mass of an atom to the total
866 >     * mass of the cutoff group it belongs to.  By default, all atoms
867 >     * are their own cutoff groups, and therefore have mass factors of
868 >     * 1.  We need some special handling for massless atoms, which
869 >     * will be treated as carrying the entire mass of the cutoff
870 >     * group.
871 >     */
872      massFactors_.clear();
873 <    massFactors_.reserve(getNCutoffGroups());
873 >    massFactors_.resize(getNAtoms(), 1.0);
874      
875      for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
876        for (cg = mol->beginCutoffGroup(ci); cg != NULL;
# Line 849 | Line 879 | namespace OpenMD {
879          totalMass = cg->getMass();
880          for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
881            // Check for massless groups - set mfact to 1 if true
882 <          if (totalMass != 0)
883 <            massFactors_.push_back(atom->getMass()/totalMass);
882 >          if (totalMass != 0)
883 >            massFactors_[atom->getLocalIndex()] = atom->getMass()/totalMass;
884            else
885 <            massFactors_.push_back( 1.0 );
885 >            massFactors_[atom->getLocalIndex()] = 1.0;
886          }
887        }      
888      }
# Line 879 | Line 909 | namespace OpenMD {
909      int* oneThreeList = oneThreeInteractions_.getPairList();
910      int* oneFourList = oneFourInteractions_.getPairList();
911  
882    //setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray_[0],
883    //               &nExclude, excludeList,
884    //               &nOneTwo, oneTwoList,
885    //               &nOneThree, oneThreeList,
886    //               &nOneFour, oneFourList,
887    //               &molMembershipArray[0], &mfact[0], &nCutoffGroups_,
888    //               &fortranGlobalGroupMembership[0], &isError);
889    
912      topologyDone_ = true;
913    }
914  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines