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

Comparing trunk/src/parallel/ForceMatrixDecomposition.cpp (file contents):
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC vs.
Revision 1993 by gezelter, Tue Apr 29 17:32:31 2014 UTC

# Line 99 | Line 99 | namespace OpenMD {
99      nGroups_ = info_->getNLocalCutoffGroups();
100      // gather the information for atomtype IDs (atids):
101      idents = info_->getIdentArray();
102 +    regions = info_->getRegions();
103      AtomLocalToGlobal = info_->getGlobalAtomIndices();
104      cgLocalToGlobal = info_->getGlobalGroupIndices();
105      vector<int> globalGroupMembership = info_->getGlobalGroupMembership();
# Line 118 | Line 119 | namespace OpenMD {
119      
120   #ifdef IS_MPI
121  
122 <    MPI::Intracomm row = rowComm.getComm();
123 <    MPI::Intracomm col = colComm.getComm();
122 >    MPI_Comm row = rowComm.getComm();
123 >    MPI_Comm col = colComm.getComm();
124  
125      AtomPlanIntRow = new Plan<int>(row, nLocal_);
126      AtomPlanRealRow = new Plan<RealType>(row, nLocal_);
# Line 163 | Line 164 | namespace OpenMD {
164      
165      AtomPlanIntRow->gather(idents, identsRow);
166      AtomPlanIntColumn->gather(idents, identsCol);
167 +
168 +    regionsRow.resize(nAtomsInRow_);
169 +    regionsCol.resize(nAtomsInCol_);
170      
171 +    AtomPlanIntRow->gather(regions, regionsRow);
172 +    AtomPlanIntColumn->gather(regions, regionsCol);
173 +    
174      // allocate memory for the parallel objects
175      atypesRow.resize(nAtomsInRow_);
176      atypesCol.resize(nAtomsInCol_);
# Line 308 | Line 315 | namespace OpenMD {
315    
316    void ForceMatrixDecomposition::createGtypeCutoffMap() {
317      
318 +    GrCut.clear();
319 +    GrCutSq.clear();
320 +    GrlistSq.clear();
321 +
322      RealType tol = 1e-6;
323      largestRcut_ = 0.0;
324      int atid;
# Line 413 | Line 424 | namespace OpenMD {
424                                       gTypeCutoffs.end());
425  
426   #ifdef IS_MPI
427 <    MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE,
428 <                              MPI::MAX);
427 >    MPI_Allreduce(MPI_IN_PLACE, &groupMax, 1, MPI_REALTYPE,
428 >                  MPI_MAX, MPI_COMM_WORLD);
429   #endif
430      
431      RealType tradRcut = groupMax;
432 +
433 +    GrCut.resize( gTypeCutoffs.size() );
434 +    GrCutSq.resize( gTypeCutoffs.size() );
435 +    GrlistSq.resize( gTypeCutoffs.size() );
436 +
437  
438      for (unsigned int i = 0; i < gTypeCutoffs.size();  i++) {
439 +      GrCut[i].resize( gTypeCutoffs.size() , 0.0);
440 +      GrCutSq[i].resize( gTypeCutoffs.size(), 0.0 );
441 +      GrlistSq[i].resize( gTypeCutoffs.size(), 0.0 );
442 +
443        for (unsigned int j = 0; j < gTypeCutoffs.size();  j++) {      
444          RealType thisRcut;
445          switch(cutoffPolicy_) {
# Line 442 | Line 462 | namespace OpenMD {
462            break;
463          }
464  
465 <        pair<int,int> key = make_pair(i,j);
446 <        gTypeCutoffMap[key].first = thisRcut;
465 >        GrCut[i][j] = thisRcut;
466          if (thisRcut > largestRcut_) largestRcut_ = thisRcut;
467 <        gTypeCutoffMap[key].second = thisRcut*thisRcut;
468 <        gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2);
467 >        GrCutSq[i][j] = thisRcut * thisRcut;
468 >        GrlistSq[i][j] = pow(thisRcut + skinThickness_, 2);
469 >
470 >        // pair<int,int> key = make_pair(i,j);
471 >        // gTypeCutoffMap[key].first = thisRcut;
472 >        // gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2);
473          // sanity check
474          
475          if (userChoseCutoff_) {
476 <          if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) {
476 >          if (abs(GrCut[i][j] - userCutoff_) > 0.0001) {
477              sprintf(painCave.errMsg,
478                      "ForceMatrixDecomposition::createGtypeCutoffMap "
479                      "user-specified rCut (%lf) does not match computed group Cutoff\n", userCutoff_);
# Line 463 | Line 486 | namespace OpenMD {
486      }
487    }
488  
489 <  groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) {
489 >  void ForceMatrixDecomposition::getGroupCutoffs(int &cg1, int &cg2, RealType &rcut, RealType &rcutsq, RealType &rlistsq) {
490      int i, j;  
491   #ifdef IS_MPI
492      i = groupRowToGtype[cg1];
# Line 472 | Line 495 | namespace OpenMD {
495      i = groupToGtype[cg1];
496      j = groupToGtype[cg2];
497   #endif    
498 <    return gTypeCutoffMap[make_pair(i,j)];
498 >    rcut = GrCut[i][j];
499 >    rcutsq = GrCutSq[i][j];
500 >    rlistsq = GrlistSq[i][j];
501 >    return;
502 >    //return gTypeCutoffMap[make_pair(i,j)];
503    }
504  
505    int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) {
506      for (unsigned int j = 0; j < toposForAtom[atom1].size(); j++) {
507        if (toposForAtom[atom1][j] == atom2)
508          return topoDist[atom1][j];
509 <    }
509 >    }                                          
510      return 0;
511    }
512  
# Line 559 | Line 586 | namespace OpenMD {
586             atomColData.electricField.end(), V3Zero);
587      }
588  
589 +    if (storageLayout_ & DataStorage::dslSitePotential) {    
590 +      fill(atomRowData.sitePotential.begin(),
591 +           atomRowData.sitePotential.end(), 0.0);
592 +      fill(atomColData.sitePotential.begin(),
593 +           atomColData.sitePotential.end(), 0.0);
594 +    }
595 +
596   #endif
597      // even in parallel, we need to zero out the local arrays:
598  
# Line 591 | Line 625 | namespace OpenMD {
625        fill(snap_->atomData.electricField.begin(),
626             snap_->atomData.electricField.end(), V3Zero);
627      }
628 +    if (storageLayout_ & DataStorage::dslSitePotential) {      
629 +      fill(snap_->atomData.sitePotential.begin(),
630 +           snap_->atomData.sitePotential.end(), 0.0);
631 +    }
632    }
633  
634  
# Line 805 | Line 843 | namespace OpenMD {
843          snap_->atomData.electricField[i] += efield_tmp[i];
844      }
845  
846 +    if (storageLayout_ & DataStorage::dslSitePotential) {
847 +
848 +      int nsp = snap_->atomData.sitePotential.size();
849 +      vector<RealType> sp_tmp(nsp, 0.0);
850 +
851 +      AtomPlanRealRow->scatter(atomRowData.sitePotential, sp_tmp);
852 +      for (int i = 0; i < nsp; i++) {
853 +        snap_->atomData.sitePotential[i] += sp_tmp[i];
854 +        sp_tmp[i] = 0.0;
855 +      }
856 +      
857 +      AtomPlanRealColumn->scatter(atomColData.sitePotential, sp_tmp);
858 +      for (int i = 0; i < nsp; i++)
859 +        snap_->atomData.sitePotential[i] += sp_tmp[i];
860 +    }
861  
862      nLocal_ = snap_->getNumberOfAtoms();
863  
# Line 889 | Line 942 | namespace OpenMD {
942      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
943        RealType ploc1 = pairwisePot[ii];
944        RealType ploc2 = 0.0;
945 <      MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
945 >      MPI_Allreduce(&ploc1, &ploc2, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
946        pairwisePot[ii] = ploc2;
947      }
948  
949      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
950        RealType ploc1 = excludedPot[ii];
951        RealType ploc2 = 0.0;
952 <      MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
952 >      MPI_Allreduce(&ploc1, &ploc2, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
953        excludedPot[ii] = ploc2;
954      }
955  
956      // Here be dragons.
957 <    MPI::Intracomm col = colComm.getComm();
957 >    MPI_Comm col = colComm.getComm();
958  
959 <    col.Allreduce(MPI::IN_PLACE,
959 >    MPI_Allreduce(MPI_IN_PLACE,
960                    &snap_->frameData.conductiveHeatFlux[0], 3,
961 <                  MPI::REALTYPE, MPI::SUM);
961 >                  MPI_REALTYPE, MPI_SUM, col);
962  
963  
964   #endif
# Line 924 | Line 977 | namespace OpenMD {
977      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
978        RealType ploc1 = embeddingPot[ii];
979        RealType ploc2 = 0.0;
980 <      MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
980 >      MPI_Allreduce(&ploc1, &ploc2, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
981        embeddingPot[ii] = ploc2;
982      }    
983      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
984        RealType ploc1 = excludedSelfPot[ii];
985        RealType ploc2 = 0.0;
986 <      MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
986 >      MPI_Allreduce(&ploc1, &ploc2, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
987        excludedSelfPot[ii] = ploc2;
988      }    
989   #endif
# Line 939 | Line 992 | namespace OpenMD {
992  
993  
994  
995 <  int ForceMatrixDecomposition::getNAtomsInRow() {  
995 >  int& ForceMatrixDecomposition::getNAtomsInRow() {  
996   #ifdef IS_MPI
997      return nAtomsInRow_;
998   #else
# Line 950 | Line 1003 | namespace OpenMD {
1003    /**
1004     * returns the list of atoms belonging to this group.  
1005     */
1006 <  vector<int> ForceMatrixDecomposition::getAtomsInGroupRow(int cg1){
1006 >  vector<int>& ForceMatrixDecomposition::getAtomsInGroupRow(int cg1){
1007   #ifdef IS_MPI
1008      return groupListRow_[cg1];
1009   #else
# Line 958 | Line 1011 | namespace OpenMD {
1011   #endif
1012    }
1013  
1014 <  vector<int> ForceMatrixDecomposition::getAtomsInGroupColumn(int cg2){
1014 >  vector<int>& ForceMatrixDecomposition::getAtomsInGroupColumn(int cg2){
1015   #ifdef IS_MPI
1016      return groupListCol_[cg2];
1017   #else
# Line 981 | Line 1034 | namespace OpenMD {
1034      return d;    
1035    }
1036  
1037 <  Vector3d ForceMatrixDecomposition::getGroupVelocityColumn(int cg2){
1037 >  Vector3d& ForceMatrixDecomposition::getGroupVelocityColumn(int cg2){
1038   #ifdef IS_MPI
1039      return cgColData.velocity[cg2];
1040   #else
# Line 989 | Line 1042 | namespace OpenMD {
1042   #endif
1043    }
1044  
1045 <  Vector3d ForceMatrixDecomposition::getAtomVelocityColumn(int atom2){
1045 >  Vector3d& ForceMatrixDecomposition::getAtomVelocityColumn(int atom2){
1046   #ifdef IS_MPI
1047      return atomColData.velocity[atom2];
1048   #else
# Line 1027 | Line 1080 | namespace OpenMD {
1080      return d;    
1081    }
1082  
1083 <  RealType ForceMatrixDecomposition::getMassFactorRow(int atom1) {
1083 >  RealType& ForceMatrixDecomposition::getMassFactorRow(int atom1) {
1084   #ifdef IS_MPI
1085      return massFactorsRow[atom1];
1086   #else
# Line 1035 | Line 1088 | namespace OpenMD {
1088   #endif
1089    }
1090  
1091 <  RealType ForceMatrixDecomposition::getMassFactorColumn(int atom2) {
1091 >  RealType& ForceMatrixDecomposition::getMassFactorColumn(int atom2) {
1092   #ifdef IS_MPI
1093      return massFactorsCol[atom2];
1094   #else
# Line 1058 | Line 1111 | namespace OpenMD {
1111      return d;    
1112    }
1113  
1114 <  vector<int> ForceMatrixDecomposition::getExcludesForAtom(int atom1) {
1114 >  vector<int>& ForceMatrixDecomposition::getExcludesForAtom(int atom1) {
1115      return excludesForAtom[atom1];
1116    }
1117  
# Line 1148 | Line 1201 | namespace OpenMD {
1201      idat.excluded = excludeAtomPair(atom1, atom2);
1202    
1203   #ifdef IS_MPI
1204 <    idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]);
1205 <    //idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
1206 <    //                         ff_->getAtomType(identsCol[atom2]) );
1207 <    
1204 >    //idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]);
1205 >    idat.atid1 = identsRow[atom1];
1206 >    idat.atid2 = identsCol[atom2];
1207 >
1208 >    if (regionsRow[atom1] >= 0 && regionsCol[atom2] >= 0) {
1209 >      idat.sameRegion = (regionsRow[atom1] == regionsCol[atom2]);
1210 >    } else {
1211 >      idat.sameRegion = false;
1212 >    }
1213 >
1214      if (storageLayout_ & DataStorage::dslAmat) {
1215        idat.A1 = &(atomRowData.aMat[atom1]);
1216        idat.A2 = &(atomColData.aMat[atom2]);
# Line 1204 | Line 1263 | namespace OpenMD {
1263  
1264   #else
1265      
1266 <    idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]);
1266 >    //idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]);
1267 >    idat.atid1 = idents[atom1];
1268 >    idat.atid2 = idents[atom2];
1269  
1270 +    if (regions[atom1] >= 0 && regions[atom2] >= 0) {
1271 +      idat.sameRegion = (regions[atom1] == regions[atom2]);
1272 +    } else {
1273 +      idat.sameRegion = false;
1274 +    }
1275 +
1276      if (storageLayout_ & DataStorage::dslAmat) {
1277        idat.A1 = &(snap_->atomData.aMat[atom1]);
1278        idat.A2 = &(snap_->atomData.aMat[atom2]);
# Line 1280 | Line 1347 | namespace OpenMD {
1347        atomColData.electricField[atom2] += *(idat.eField2);
1348      }
1349  
1350 +    if (storageLayout_ & DataStorage::dslSitePotential) {              
1351 +      atomRowData.sitePotential[atom1] += *(idat.sPot1);
1352 +      atomColData.sitePotential[atom2] += *(idat.sPot2);
1353 +    }
1354 +
1355   #else
1356      pairwisePot += *(idat.pot);
1357      excludedPot += *(idat.excludedPot);
# Line 1306 | Line 1378 | namespace OpenMD {
1378        snap_->atomData.electricField[atom2] += *(idat.eField2);
1379      }
1380  
1381 +    if (storageLayout_ & DataStorage::dslSitePotential) {              
1382 +      snap_->atomData.sitePotential[atom1] += *(idat.sPot1);
1383 +      snap_->atomData.sitePotential[atom2] += *(idat.sPot2);
1384 +    }
1385 +
1386   #endif
1387      
1388    }
# Line 1316 | Line 1393 | namespace OpenMD {
1393     * first element of pair is row-indexed CutoffGroup
1394     * second element of pair is column-indexed CutoffGroup
1395     */
1396 <  vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() {
1397 <      
1398 <    vector<pair<int, int> > neighborList;
1396 >  void ForceMatrixDecomposition::buildNeighborList(vector<pair<int,int> >& neighborList) {
1397 >    
1398 >    neighborList.clear();
1399      groupCutoffs cuts;
1400      bool doAllPairs = false;
1401  
1402      RealType rList_ = (largestRcut_ + skinThickness_);
1403 +    RealType rcut, rcutsq, rlistsq;
1404      Snapshot* snap_ = sman_->getCurrentSnapshot();
1405      Mat3x3d box;
1406      Mat3x3d invBox;
# Line 1350 | Line 1428 | namespace OpenMD {
1428      Vector3d boxY = box.getColumn(1);
1429      Vector3d boxZ = box.getColumn(2);
1430      
1431 <    nCells_.x() = (int) ( boxX.length() )/ rList_;
1432 <    nCells_.y() = (int) ( boxY.length() )/ rList_;
1433 <    nCells_.z() = (int) ( boxZ.length() )/ rList_;
1431 >    nCells_.x() = int( boxX.length() / rList_ );
1432 >    nCells_.y() = int( boxY.length() / rList_ );
1433 >    nCells_.z() = int( boxZ.length() / rList_ );
1434      
1435      // handle small boxes where the cell offsets can end up repeating cells
1436      
# Line 1448 | Line 1526 | namespace OpenMD {
1526          }
1527          
1528          // find xyz-indices of cell that cutoffGroup is in.
1529 <        whichCell.x() = nCells_.x() * scaled.x();
1530 <        whichCell.y() = nCells_.y() * scaled.y();
1531 <        whichCell.z() = nCells_.z() * scaled.z();
1529 >        whichCell.x() = int(nCells_.x() * scaled.x());
1530 >        whichCell.y() = int(nCells_.y() * scaled.y());
1531 >        whichCell.z() = int(nCells_.z() * scaled.z());
1532          
1533          // find single index of this cell:
1534          cellIndex = Vlinear(whichCell, nCells_);
# Line 1506 | Line 1584 | namespace OpenMD {
1584                    if (usePeriodicBoundaryConditions_) {
1585                      snap_->wrapVector(dr);
1586                    }
1587 <                  cuts = getGroupCutoffs( (*j1), (*j2) );
1588 <                  if (dr.lengthSquare() < cuts.third) {
1587 >                  getGroupCutoffs( (*j1), (*j2), rcut, rcutsq, rlistsq );
1588 >                  if (dr.lengthSquare() < rlistsq) {
1589                      neighborList.push_back(make_pair((*j1), (*j2)));
1590                    }                  
1591                  }
# Line 1533 | Line 1611 | namespace OpenMD {
1611                      if (usePeriodicBoundaryConditions_) {
1612                        snap_->wrapVector(dr);
1613                      }
1614 <                    cuts = getGroupCutoffs( (*j1), (*j2) );
1615 <                    if (dr.lengthSquare() < cuts.third) {
1614 >                    getGroupCutoffs( (*j1), (*j2), rcut, rcutsq, rlistsq );
1615 >                    if (dr.lengthSquare() < rlistsq) {
1616                        neighborList.push_back(make_pair((*j1), (*j2)));
1617                      }
1618                    }
# Line 1554 | Line 1632 | namespace OpenMD {
1632            if (usePeriodicBoundaryConditions_) {
1633              snap_->wrapVector(dr);
1634            }
1635 <          cuts = getGroupCutoffs( j1, j2 );
1636 <          if (dr.lengthSquare() < cuts.third) {
1635 >          getGroupCutoffs( j1, j2, rcut, rcutsq, rlistsq);
1636 >          if (dr.lengthSquare() < rlistsq) {
1637              neighborList.push_back(make_pair(j1, j2));
1638            }
1639          }
# Line 1569 | Line 1647 | namespace OpenMD {
1647            if (usePeriodicBoundaryConditions_) {
1648              snap_->wrapVector(dr);
1649            }
1650 <          cuts = getGroupCutoffs( j1, j2 );
1651 <          if (dr.lengthSquare() < cuts.third) {
1650 >          getGroupCutoffs( j1, j2, rcut, rcutsq, rlistsq );
1651 >          if (dr.lengthSquare() < rlistsq) {
1652              neighborList.push_back(make_pair(j1, j2));
1653            }
1654          }    
# Line 1583 | Line 1661 | namespace OpenMD {
1661      saved_CG_positions_.clear();
1662      for (int i = 0; i < nGroups_; i++)
1663        saved_CG_positions_.push_back(snap_->cgData.position[i]);
1586    
1587    return neighborList;
1664    }
1665   } //end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines