--- branches/development/src/parallel/ForceDecomposition.cpp 2011/02/04 20:04:56 1541 +++ branches/development/src/parallel/ForceMatrixDecomposition.cpp 2011/04/27 18:38:15 1549 @@ -38,132 +38,162 @@ * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). * [4] Vardeman & Gezelter, in progress (2009). */ -#include "parallel/ForceDecomposition.hpp" -#include "parallel/Communicator.hpp" +#include "parallel/ForceMatrixDecomposition.hpp" #include "math/SquareMatrix3.hpp" +#include "nonbonded/NonBondedInteraction.hpp" +#include "brains/SnapshotManager.hpp" using namespace std; namespace OpenMD { - void ForceDecomposition::distributeInitialData() { -#ifdef IS_MPI + /** + * distributeInitialData is essentially a copy of the older fortran + * SimulationSetup + */ + + void ForceMatrixDecomposition::distributeInitialData() { +#ifdef IS_MPI Snapshot* snap = sman_->getCurrentSnapshot(); - int nAtoms = snap->getNumberOfAtoms(); + int nLocal = snap->getNumberOfAtoms(); int nGroups = snap->getNumberOfCutoffGroups(); - AtomCommRealI = new Communicator(nAtoms); - AtomCommVectorI = new Communicator(nAtoms); - AtomCommMatrixI = new Communicator(nAtoms); + AtomCommIntRow = new Communicator(nLocal); + AtomCommRealRow = new Communicator(nLocal); + AtomCommVectorRow = new Communicator(nLocal); + AtomCommMatrixRow = new Communicator(nLocal); - AtomCommRealJ = new Communicator(nAtoms); - AtomCommVectorJ = new Communicator(nAtoms); - AtomCommMatrixJ = new Communicator(nAtoms); + AtomCommIntColumn = new Communicator(nLocal); + AtomCommRealColumn = new Communicator(nLocal); + AtomCommVectorColumn = new Communicator(nLocal); + AtomCommMatrixColumn = new Communicator(nLocal); - cgCommVectorI = new Communicator(nGroups); - cgCommVectorJ = new Communicator(nGroups); + cgCommIntRow = new Communicator(nGroups); + cgCommVectorRow = new Communicator(nGroups); + cgCommIntColumn = new Communicator(nGroups); + cgCommVectorColumn = new Communicator(nGroups); - int nInRow = AtomCommRealI.getSize(); - int nInCol = AtomCommRealJ.getSize(); + int nAtomsInRow = AtomCommIntRow->getSize(); + int nAtomsInCol = AtomCommIntColumn->getSize(); + int nGroupsInRow = cgCommIntRow->getSize(); + int nGroupsInCol = cgCommIntColumn->getSize(); + + vector > pot_row(N_INTERACTION_FAMILIES, + vector (nAtomsInRow, 0.0)); + vector > pot_col(N_INTERACTION_FAMILIES, + vector (nAtomsInCol, 0.0)); + + vector pot_local(N_INTERACTION_FAMILIES, 0.0); + + // gather the information for atomtype IDs (atids): + vector identsLocal = info_->getIdentArray(); + identsRow.reserve(nAtomsInRow); + identsCol.reserve(nAtomsInCol); + + AtomCommIntRow->gather(identsLocal, identsRow); + AtomCommIntColumn->gather(identsLocal, identsCol); + + AtomLocalToGlobal = info_->getGlobalAtomIndices(); + AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal); + AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal); + + cgLocalToGlobal = info_->getGlobalGroupIndices(); + cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal); + cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal); - vector > pot_row(LR_POT_TYPES, - vector (nInRow, 0.0)); - vector > pot_col(LR_POT_TYPES, - vector (nInCol, 0.0)); - - vector > pot_local(LR_POT_TYPES, - vector (nAtoms, 0.0)); - + // still need: + // topoDist + // exclude #endif } - void ForceDecomposition::distributeData() { + void ForceMatrixDecomposition::distributeData() { #ifdef IS_MPI Snapshot* snap = sman_->getCurrentSnapshot(); // gather up the atomic positions - AtomCommVectorI->gather(snap->atomData.position, + AtomCommVectorRow->gather(snap->atomData.position, snap->atomIData.position); - AtomCommVectorJ->gather(snap->atomData.position, + AtomCommVectorColumn->gather(snap->atomData.position, snap->atomJData.position); // gather up the cutoff group positions - cgCommVectorI->gather(snap->cgData.position, + cgCommVectorRow->gather(snap->cgData.position, snap->cgIData.position); - cgCommVectorJ->gather(snap->cgData.position, + cgCommVectorColumn->gather(snap->cgData.position, snap->cgJData.position); // if needed, gather the atomic rotation matrices if (snap->atomData.getStorageLayout() & DataStorage::dslAmat) { - AtomCommMatrixI->gather(snap->atomData.aMat, + AtomCommMatrixRow->gather(snap->atomData.aMat, snap->atomIData.aMat); - AtomCommMatrixJ->gather(snap->atomData.aMat, + AtomCommMatrixColumn->gather(snap->atomData.aMat, snap->atomJData.aMat); } // if needed, gather the atomic eletrostatic frames if (snap->atomData.getStorageLayout() & DataStorage::dslElectroFrame) { - AtomCommMatrixI->gather(snap->atomData.electroFrame, + AtomCommMatrixRow->gather(snap->atomData.electroFrame, snap->atomIData.electroFrame); - AtomCommMatrixJ->gather(snap->atomData.electroFrame, + AtomCommMatrixColumn->gather(snap->atomData.electroFrame, snap->atomJData.electroFrame); } #endif } - void ForceDecomposition::collectIntermediateData() { + void ForceMatrixDecomposition::collectIntermediateData() { #ifdef IS_MPI Snapshot* snap = sman_->getCurrentSnapshot(); if (snap->atomData.getStorageLayout() & DataStorage::dslDensity) { - AtomCommRealI->scatter(snap->atomIData.density, + AtomCommRealRow->scatter(snap->atomIData.density, snap->atomData.density); int n = snap->atomData.density.size(); std::vector rho_tmp(n, 0.0); - AtomCommRealJ->scatter(snap->atomJData.density, rho_tmp); + AtomCommRealColumn->scatter(snap->atomJData.density, rho_tmp); for (int i = 0; i < n; i++) snap->atomData.density[i] += rho_tmp[i]; } #endif } - void ForceDecomposition::distributeIntermediateData() { + void ForceMatrixDecomposition::distributeIntermediateData() { #ifdef IS_MPI Snapshot* snap = sman_->getCurrentSnapshot(); if (snap->atomData.getStorageLayout() & DataStorage::dslFunctional) { - AtomCommRealI->gather(snap->atomData.functional, + AtomCommRealRow->gather(snap->atomData.functional, snap->atomIData.functional); - AtomCommRealJ->gather(snap->atomData.functional, + AtomCommRealColumn->gather(snap->atomData.functional, snap->atomJData.functional); } if (snap->atomData.getStorageLayout() & DataStorage::dslFunctionalDerivative) { - AtomCommRealI->gather(snap->atomData.functionalDerivative, + AtomCommRealRow->gather(snap->atomData.functionalDerivative, snap->atomIData.functionalDerivative); - AtomCommRealJ->gather(snap->atomData.functionalDerivative, + AtomCommRealColumn->gather(snap->atomData.functionalDerivative, snap->atomJData.functionalDerivative); } #endif } - void ForceDecomposition::collectData() { + void ForceMatrixDecomposition::collectData() { #ifdef IS_MPI Snapshot* snap = sman_->getCurrentSnapshot(); int n = snap->atomData.force.size(); - std::vector frc_tmp(n, 0.0); + vector frc_tmp(n, V3Zero); - AtomCommVectorI->scatter(snap->atomIData.force, frc_tmp); + AtomCommVectorRow->scatter(snap->atomIData.force, frc_tmp); for (int i = 0; i < n; i++) { snap->atomData.force[i] += frc_tmp[i]; frc_tmp[i] = 0.0; } - AtomCommVectorJ->scatter(snap->atomJData.force, frc_tmp); + AtomCommVectorColumn->scatter(snap->atomJData.force, frc_tmp); for (int i = 0; i < n; i++) snap->atomData.force[i] += frc_tmp[i]; @@ -171,32 +201,30 @@ namespace OpenMD { if (snap->atomData.getStorageLayout() & DataStorage::dslTorque) { int nt = snap->atomData.force.size(); - std::vector trq_tmp(nt, 0.0); + vector trq_tmp(nt, V3Zero); - AtomCommVectorI->scatter(snap->atomIData.torque, trq_tmp); + AtomCommVectorRow->scatter(snap->atomIData.torque, trq_tmp); for (int i = 0; i < n; i++) { snap->atomData.torque[i] += trq_tmp[i]; trq_tmp[i] = 0.0; } - AtomCommVectorJ->scatter(snap->atomJData.torque, trq_tmp); + AtomCommVectorColumn->scatter(snap->atomJData.torque, trq_tmp); for (int i = 0; i < n; i++) snap->atomData.torque[i] += trq_tmp[i]; } + int nLocal = snap->getNumberOfAtoms(); + + vector > pot_temp(N_INTERACTION_FAMILIES, + vector (nLocal, 0.0)); - vector > pot_temp(LR_POT_TYPES, - vector (nAtoms, 0.0)); - - for (int i = 0; i < LR_POT_TYPES; i++) { - AtomCommRealI->scatter(pot_row[i], pot_temp[i]); + for (int i = 0; i < N_INTERACTION_FAMILIES; i++) { + AtomCommRealRow->scatter(pot_row[i], pot_temp[i]); for (int ii = 0; ii < pot_temp[i].size(); ii++ ) { pot_local[i] += pot_temp[i][ii]; } } - - - #endif }