--- branches/development/src/parallel/ForceMatrixDecomposition.cpp 2012/03/14 17:56:01 1688 +++ branches/development/src/parallel/ForceMatrixDecomposition.cpp 2012/06/18 18:23:20 1756 @@ -95,7 +95,7 @@ namespace OpenMD { storageLayout_ = sman_->getStorageLayout(); ff_ = info_->getForceField(); nLocal_ = snap_->getNumberOfAtoms(); - + nGroups_ = info_->getNLocalCutoffGroups(); // gather the information for atomtype IDs (atids): idents = info_->getIdentArray(); @@ -109,7 +109,13 @@ namespace OpenMD { PairList* oneTwo = info_->getOneTwoInteractions(); PairList* oneThree = info_->getOneThreeInteractions(); PairList* oneFour = info_->getOneFourInteractions(); - + + if (needVelocities_) + snap_->cgData.setStorageLayout(DataStorage::dslPosition | + DataStorage::dslVelocity); + else + snap_->cgData.setStorageLayout(DataStorage::dslPosition); + #ifdef IS_MPI MPI::Intracomm row = rowComm.getComm(); @@ -145,8 +151,13 @@ namespace OpenMD { cgRowData.resize(nGroupsInRow_); cgRowData.setStorageLayout(DataStorage::dslPosition); cgColData.resize(nGroupsInCol_); - cgColData.setStorageLayout(DataStorage::dslPosition); - + if (needVelocities_) + // we only need column velocities if we need them. + cgColData.setStorageLayout(DataStorage::dslPosition | + DataStorage::dslVelocity); + else + cgColData.setStorageLayout(DataStorage::dslPosition); + identsRow.resize(nAtomsInRow_); identsCol.resize(nAtomsInCol_); @@ -450,7 +461,6 @@ namespace OpenMD { } } - groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) { int i, j; #ifdef IS_MPI @@ -523,8 +533,29 @@ namespace OpenMD { atomRowData.skippedCharge.end(), 0.0); fill(atomColData.skippedCharge.begin(), atomColData.skippedCharge.end(), 0.0); + } + + if (storageLayout_ & DataStorage::dslFlucQForce) { + fill(atomRowData.flucQFrc.begin(), + atomRowData.flucQFrc.end(), 0.0); + fill(atomColData.flucQFrc.begin(), + atomColData.flucQFrc.end(), 0.0); + } + + if (storageLayout_ & DataStorage::dslElectricField) { + fill(atomRowData.electricField.begin(), + atomRowData.electricField.end(), V3Zero); + fill(atomColData.electricField.begin(), + atomColData.electricField.end(), V3Zero); } + if (storageLayout_ & DataStorage::dslFlucQForce) { + fill(atomRowData.flucQFrc.begin(), atomRowData.flucQFrc.end(), + 0.0); + fill(atomColData.flucQFrc.begin(), atomColData.flucQFrc.end(), + 0.0); + } + #endif // even in parallel, we need to zero out the local arrays: @@ -537,19 +568,26 @@ namespace OpenMD { fill(snap_->atomData.density.begin(), snap_->atomData.density.end(), 0.0); } + if (storageLayout_ & DataStorage::dslFunctional) { fill(snap_->atomData.functional.begin(), snap_->atomData.functional.end(), 0.0); } + if (storageLayout_ & DataStorage::dslFunctionalDerivative) { fill(snap_->atomData.functionalDerivative.begin(), snap_->atomData.functionalDerivative.end(), 0.0); } + if (storageLayout_ & DataStorage::dslSkippedCharge) { fill(snap_->atomData.skippedCharge.begin(), snap_->atomData.skippedCharge.end(), 0.0); } - + + if (storageLayout_ & DataStorage::dslElectricField) { + fill(snap_->atomData.electricField.begin(), + snap_->atomData.electricField.end(), V3Zero); + } } @@ -572,6 +610,17 @@ namespace OpenMD { cgPlanVectorColumn->gather(snap_->cgData.position, cgColData.position); + + + if (needVelocities_) { + // gather up the atomic velocities + AtomPlanVectorColumn->gather(snap_->atomData.velocity, + atomColData.velocity); + + cgPlanVectorColumn->gather(snap_->cgData.velocity, + cgColData.velocity); + } + // if needed, gather the atomic rotation matrices if (storageLayout_ & DataStorage::dslAmat) { @@ -587,6 +636,14 @@ namespace OpenMD { atomRowData.electroFrame); AtomPlanMatrixColumn->gather(snap_->atomData.electroFrame, atomColData.electroFrame); + } + + // if needed, gather the atomic fluctuating charge values + if (storageLayout_ & DataStorage::dslFlucQPosition) { + AtomPlanRealRow->gather(snap_->atomData.flucQPos, + atomRowData.flucQPos); + AtomPlanRealColumn->gather(snap_->atomData.flucQPos, + atomColData.flucQPos); } #endif @@ -611,6 +668,18 @@ namespace OpenMD { for (int i = 0; i < n; i++) snap_->atomData.density[i] += rho_tmp[i]; } + + if (storageLayout_ & DataStorage::dslElectricField) { + + AtomPlanVectorRow->scatter(atomRowData.electricField, + snap_->atomData.electricField); + + int n = snap_->atomData.electricField.size(); + vector field_tmp(n, V3Zero); + AtomPlanVectorColumn->scatter(atomColData.electricField, field_tmp); + for (int i = 0; i < n; i++) + snap_->atomData.electricField[i] += field_tmp[i]; + } #endif } @@ -690,6 +759,23 @@ namespace OpenMD { } + if (storageLayout_ & DataStorage::dslFlucQForce) { + + int nq = snap_->atomData.flucQFrc.size(); + vector fqfrc_tmp(nq, 0.0); + + AtomPlanRealRow->scatter(atomRowData.flucQFrc, fqfrc_tmp); + for (int i = 0; i < nq; i++) { + snap_->atomData.flucQFrc[i] += fqfrc_tmp[i]; + fqfrc_tmp[i] = 0.0; + } + + AtomPlanRealColumn->scatter(atomColData.flucQFrc, fqfrc_tmp); + for (int i = 0; i < nq; i++) + snap_->atomData.flucQFrc[i] += fqfrc_tmp[i]; + + } + nLocal_ = snap_->getNumberOfAtoms(); vector pot_temp(nLocal_, @@ -701,7 +787,21 @@ namespace OpenMD { for (int ii = 0; ii < pot_temp.size(); ii++ ) pairwisePot += pot_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 + // non-bonded routines. In single processor, this is done in + // unpackInteractionData, not in collectData. + for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { + for (int i = 0; i < nLocal_; i++) { + // factor of two is because the total potential terms are divided + // by 2 in parallel due to row/ column scatter + snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii); + } + } + } + fill(pot_temp.begin(), pot_temp.end(), Vector (0.0)); @@ -709,7 +809,41 @@ namespace OpenMD { for (int ii = 0; ii < pot_temp.size(); ii++ ) pairwisePot += pot_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 + // non-bonded routines. In single processor, this is done in + // unpackInteractionData, not in collectData. + for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { + for (int i = 0; i < nLocal_; i++) { + // factor of two is because the total potential terms are divided + // by 2 in parallel due to row/ column scatter + snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii); + } + } + } + if (storageLayout_ & DataStorage::dslParticlePot) { + int npp = snap_->atomData.particlePot.size(); + vector ppot_temp(npp, 0.0); + + // This is the direct or embedding contribution to the particle + // pot. + + AtomPlanRealRow->scatter(atomRowData.particlePot, ppot_temp); + for (int i = 0; i < npp; i++) { + snap_->atomData.particlePot[i] += ppot_temp[i]; + } + + fill(ppot_temp.begin(), ppot_temp.end(), 0.0); + + AtomPlanRealColumn->scatter(atomColData.particlePot, ppot_temp); + for (int i = 0; i < npp; i++) { + snap_->atomData.particlePot[i] += ppot_temp[i]; + } + } + for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) { RealType ploc1 = pairwisePot[ii]; RealType ploc2 = 0.0; @@ -717,17 +851,39 @@ namespace OpenMD { pairwisePot[ii] = ploc2; } + // Here be dragons. + MPI::Intracomm col = colComm.getComm(); + + col.Allreduce(MPI::IN_PLACE, + &snap_->frameData.conductiveHeatFlux[0], 3, + MPI::REALTYPE, MPI::SUM); + + +#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; - } - + } #endif - + } + + int ForceMatrixDecomposition::getNAtomsInRow() { #ifdef IS_MPI return nAtomsInRow_; @@ -768,7 +924,23 @@ namespace OpenMD { return d; } + Vector3d ForceMatrixDecomposition::getGroupVelocityColumn(int cg2){ +#ifdef IS_MPI + return cgColData.velocity[cg2]; +#else + return snap_->cgData.velocity[cg2]; +#endif + } + Vector3d ForceMatrixDecomposition::getAtomVelocityColumn(int atom2){ +#ifdef IS_MPI + return atomColData.velocity[atom2]; +#else + return snap_->atomData.velocity[atom2]; +#endif + } + + Vector3d ForceMatrixDecomposition::getAtomToGroupVectorRow(int atom1, int cg1){ Vector3d d; @@ -834,16 +1006,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; @@ -855,6 +1031,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; @@ -950,16 +1132,14 @@ namespace OpenMD { idat.skippedCharge2 = &(atomColData.skippedCharge[atom2]); } + if (storageLayout_ & DataStorage::dslFlucQPosition) { + idat.flucQ1 = &(atomRowData.flucQPos[atom1]); + idat.flucQ2 = &(atomColData.flucQPos[atom2]); + } + #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]); @@ -1000,6 +1180,12 @@ namespace OpenMD { idat.skippedCharge1 = &(snap_->atomData.skippedCharge[atom1]); idat.skippedCharge2 = &(snap_->atomData.skippedCharge[atom2]); } + + if (storageLayout_ & DataStorage::dslFlucQPosition) { + idat.flucQ1 = &(snap_->atomData.flucQPos[atom1]); + idat.flucQ2 = &(snap_->atomData.flucQPos[atom2]); + } + #endif } @@ -1011,11 +1197,42 @@ namespace OpenMD { atomRowData.force[atom1] += *(idat.f1); atomColData.force[atom2] -= *(idat.f1); + + if (storageLayout_ & DataStorage::dslFlucQForce) { + atomRowData.flucQFrc[atom1] -= *(idat.dVdFQ1); + atomColData.flucQFrc[atom2] -= *(idat.dVdFQ2); + } + + if (storageLayout_ & DataStorage::dslElectricField) { + atomRowData.electricField[atom1] += *(idat.eField1); + atomColData.electricField[atom2] += *(idat.eField2); + } + #else pairwisePot += *(idat.pot); snap_->atomData.force[atom1] += *(idat.f1); snap_->atomData.force[atom2] -= *(idat.f1); + + if (idat.doParticlePot) { + // This is the pairwise contribution to the particle pot. The + // embedding contribution is added in each of the low level + // non-bonded routines. In parallel, this calculation is done + // in collectData, not in unpackInteractionData. + snap_->atomData.particlePot[atom1] += *(idat.vpair) * *(idat.sw); + snap_->atomData.particlePot[atom2] += *(idat.vpair) * *(idat.sw); + } + + if (storageLayout_ & DataStorage::dslFlucQForce) { + snap_->atomData.flucQFrc[atom1] -= *(idat.dVdFQ1); + snap_->atomData.flucQFrc[atom2] -= *(idat.dVdFQ2); + } + + if (storageLayout_ & DataStorage::dslElectricField) { + snap_->atomData.electricField[atom1] += *(idat.eField1); + snap_->atomData.electricField[atom2] += *(idat.eField2); + } + #endif }