--- branches/development/src/parallel/ForceMatrixDecomposition.cpp 2012/05/24 20:59:54 1723 +++ branches/development/src/parallel/ForceMatrixDecomposition.cpp 2012/07/31 14:00:05 1772 @@ -175,6 +175,9 @@ namespace OpenMD { pot_row.resize(nAtomsInRow_); pot_col.resize(nAtomsInCol_); + + expot_row.resize(nAtomsInRow_); + expot_col.resize(nAtomsInCol_); AtomRowToGlobal.resize(nAtomsInRow_); AtomColToGlobal.resize(nAtomsInCol_); @@ -307,7 +310,6 @@ namespace OpenMD { RealType tol = 1e-6; largestRcut_ = 0.0; - RealType rc; int atid; set atypes = info_->getSimulatedAtomTypes(); @@ -392,7 +394,7 @@ namespace OpenMD { } bool gTypeFound = false; - for (int gt = 0; gt < gTypeCutoffs.size(); gt++) { + for (unsigned int gt = 0; gt < gTypeCutoffs.size(); gt++) { if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) { groupToGtype[cg1] = gt; gTypeFound = true; @@ -417,8 +419,8 @@ namespace OpenMD { RealType tradRcut = groupMax; - for (int i = 0; i < gTypeCutoffs.size(); i++) { - for (int j = 0; j < gTypeCutoffs.size(); j++) { + for (unsigned int i = 0; i < gTypeCutoffs.size(); i++) { + for (unsigned int j = 0; j < gTypeCutoffs.size(); j++) { RealType thisRcut; switch(cutoffPolicy_) { case TRADITIONAL: @@ -461,7 +463,6 @@ namespace OpenMD { } } - groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) { int i, j; #ifdef IS_MPI @@ -475,7 +476,7 @@ namespace OpenMD { } int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) { - for (int j = 0; j < toposForAtom[atom1].size(); j++) { + for (unsigned int j = 0; j < toposForAtom[atom1].size(); j++) { if (toposForAtom[atom1][j] == atom2) return topoDist[atom1][j]; } @@ -485,6 +486,8 @@ namespace OpenMD { void ForceMatrixDecomposition::zeroWorkArrays() { pairwisePot = 0.0; embeddingPot = 0.0; + excludedPot = 0.0; + excludedSelfPot = 0.0; #ifdef IS_MPI if (storageLayout_ & DataStorage::dslForce) { @@ -503,6 +506,12 @@ namespace OpenMD { fill(pot_col.begin(), pot_col.end(), Vector (0.0)); + fill(expot_row.begin(), expot_row.end(), + Vector (0.0)); + + fill(expot_col.begin(), expot_col.end(), + Vector (0.0)); + if (storageLayout_ & DataStorage::dslParticlePot) { fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0); @@ -781,13 +790,19 @@ namespace OpenMD { vector pot_temp(nLocal_, Vector (0.0)); + vector expot_temp(nLocal_, + Vector (0.0)); // scatter/gather pot_row into the members of my column AtomPlanPotRow->scatter(pot_row, pot_temp); + AtomPlanPotRow->scatter(expot_row, expot_temp); - for (int ii = 0; ii < pot_temp.size(); ii++ ) + for (int ii = 0; ii < pot_temp.size(); ii++ ) pairwisePot += pot_temp[ii]; + + for (int ii = 0; ii < expot_temp.size(); ii++ ) + excludedPot += expot_temp[ii]; if (storageLayout_ & DataStorage::dslParticlePot) { // This is the pairwise contribution to the particle pot. The @@ -805,12 +820,18 @@ namespace OpenMD { fill(pot_temp.begin(), pot_temp.end(), Vector (0.0)); + fill(expot_temp.begin(), expot_temp.end(), + Vector (0.0)); AtomPlanPotColumn->scatter(pot_col, pot_temp); + AtomPlanPotColumn->scatter(expot_col, expot_temp); for (int ii = 0; ii < pot_temp.size(); ii++ ) pairwisePot += pot_temp[ii]; + for (int ii = 0; ii < expot_temp.size(); ii++ ) + excludedPot += expot_temp[ii]; + if (storageLayout_ & DataStorage::dslParticlePot) { // This is the pairwise contribution to the particle pot. The // embedding contribution is added in each of the low level @@ -853,12 +874,12 @@ namespace OpenMD { } for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { - RealType ploc1 = embeddingPot[ii]; + RealType ploc1 = excludedPot[ii]; RealType ploc2 = 0.0; MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM); - embeddingPot[ii] = ploc2; + excludedPot[ii] = ploc2; } - + // Here be dragons. MPI::Intracomm col = colComm.getComm(); @@ -869,8 +890,35 @@ namespace OpenMD { #endif + } + + /** + * Collects information obtained during the post-pair (and embedding + * functional) loops onto local data structures. + */ + void ForceMatrixDecomposition::collectSelfData() { + snap_ = sman_->getCurrentSnapshot(); + storageLayout_ = sman_->getStorageLayout(); + +#ifdef IS_MPI + for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { + RealType ploc1 = embeddingPot[ii]; + RealType ploc2 = 0.0; + MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM); + embeddingPot[ii] = ploc2; + } + for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { + RealType ploc1 = excludedSelfPot[ii]; + RealType ploc2 = 0.0; + MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM); + excludedSelfPot[ii] = ploc2; + } +#endif + } + + int ForceMatrixDecomposition::getNAtomsInRow() { #ifdef IS_MPI return nAtomsInRow_; @@ -993,16 +1041,20 @@ namespace OpenMD { * We need to exclude some overcounted interactions that result from * the parallel decomposition. */ - bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) { - int unique_id_1, unique_id_2; + bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2, int cg1, int cg2) { + int unique_id_1, unique_id_2, group1, group2; #ifdef IS_MPI // in MPI, we have to look up the unique IDs for each atom unique_id_1 = AtomRowToGlobal[atom1]; unique_id_2 = AtomColToGlobal[atom2]; + group1 = cgRowToGlobal[cg1]; + group2 = cgColToGlobal[cg2]; #else unique_id_1 = AtomLocalToGlobal[atom1]; unique_id_2 = AtomLocalToGlobal[atom2]; + group1 = cgLocalToGlobal[cg1]; + group2 = cgLocalToGlobal[cg2]; #endif if (unique_id_1 == unique_id_2) return true; @@ -1014,6 +1066,12 @@ namespace OpenMD { } else { if ((unique_id_1 + unique_id_2) % 2 == 1) return true; } +#endif + +#ifndef IS_MPI + if (group1 == group2) { + if (unique_id_1 < unique_id_2) return true; + } #endif return false; @@ -1116,14 +1174,7 @@ namespace OpenMD { #else - - // cerr << "atoms = " << atom1 << " " << atom2 << "\n"; - // cerr << "pos1 = " << snap_->atomData.position[atom1] << "\n"; - // cerr << "pos2 = " << snap_->atomData.position[atom2] << "\n"; - idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]); - //idat.atypes = make_pair( ff_->getAtomType(idents[atom1]), - // ff_->getAtomType(idents[atom2]) ); if (storageLayout_ & DataStorage::dslAmat) { idat.A1 = &(snap_->atomData.aMat[atom1]); @@ -1178,13 +1229,15 @@ namespace OpenMD { #ifdef IS_MPI pot_row[atom1] += RealType(0.5) * *(idat.pot); pot_col[atom2] += RealType(0.5) * *(idat.pot); + expot_row[atom1] += RealType(0.5) * *(idat.excludedPot); + expot_col[atom2] += RealType(0.5) * *(idat.excludedPot); atomRowData.force[atom1] += *(idat.f1); atomColData.force[atom2] -= *(idat.f1); if (storageLayout_ & DataStorage::dslFlucQForce) { - atomRowData.flucQFrc[atom1] += *(idat.dVdFQ1); - atomColData.flucQFrc[atom2] += *(idat.dVdFQ2); + atomRowData.flucQFrc[atom1] -= *(idat.dVdFQ1); + atomColData.flucQFrc[atom2] -= *(idat.dVdFQ2); } if (storageLayout_ & DataStorage::dslElectricField) { @@ -1194,6 +1247,7 @@ namespace OpenMD { #else pairwisePot += *(idat.pot); + excludedPot += *(idat.excludedPot); snap_->atomData.force[atom1] += *(idat.f1); snap_->atomData.force[atom2] -= *(idat.f1); @@ -1208,7 +1262,7 @@ namespace OpenMD { } if (storageLayout_ & DataStorage::dslFlucQForce) { - snap_->atomData.flucQFrc[atom1] += *(idat.dVdFQ1); + snap_->atomData.flucQFrc[atom1] -= *(idat.dVdFQ1); snap_->atomData.flucQFrc[atom2] -= *(idat.dVdFQ2); } @@ -1285,6 +1339,10 @@ namespace OpenMD { for (int j = 0; j < 3; j++) { scaled[j] -= roundMe(scaled[j]); scaled[j] += 0.5; + // Handle the special case when an object is exactly on the + // boundary (a scaled coordinate of 1.0 is the same as + // scaled coordinate of 0.0) + if (scaled[j] >= 1.0) scaled[j] -= 1.0; } // find xyz-indices of cell that cutoffGroup is in. @@ -1309,6 +1367,10 @@ namespace OpenMD { for (int j = 0; j < 3; j++) { scaled[j] -= roundMe(scaled[j]); scaled[j] += 0.5; + // Handle the special case when an object is exactly on the + // boundary (a scaled coordinate of 1.0 is the same as + // scaled coordinate of 0.0) + if (scaled[j] >= 1.0) scaled[j] -= 1.0; } // find xyz-indices of cell that cutoffGroup is in. @@ -1335,6 +1397,10 @@ namespace OpenMD { for (int j = 0; j < 3; j++) { scaled[j] -= roundMe(scaled[j]); scaled[j] += 0.5; + // Handle the special case when an object is exactly on the + // boundary (a scaled coordinate of 1.0 is the same as + // scaled coordinate of 0.0) + if (scaled[j] >= 1.0) scaled[j] -= 1.0; } // find xyz-indices of cell that cutoffGroup is in.