--- branches/development/src/parallel/ForceDecomposition.cpp 2011/01/11 18:58:12 1538 +++ branches/development/src/parallel/ForceDecomposition.cpp 2011/01/14 22:31:31 1539 @@ -1,13 +1,6 @@ -/** - * @file ForceDecomposition.cpp - * @author Charles Vardeman - * @date 08/18/2010 - * @time 11:56am - * @version 1.0 +/* + * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * - * @section LICENSE - * Copyright (c) 2010 The University of Notre Dame. All Rights Reserved. - * * The University of Notre Dame grants you ("Licensee") a * non-exclusive, royalty free, license to use, modify and * redistribute this software in source and binary code form, provided @@ -45,93 +38,109 @@ * [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 "math/SquareMatrix3.hpp" +namespace OpenMD { - -/* -*- c++ -*- */ -#include "config.h" -#include + void ForceDecomposition::distributeInitialData() { #ifdef IS_MPI -#include -#endif -#include -#include -#include -#include -#include "parallel/ForceDecomposition.hpp" + int nAtoms; + int nGroups; + AtomCommRealI = new Comm(nAtoms); + AtomCommVectorI = new Comm(nAtoms); + AtomCommMatrixI = new Comm(nAtoms); -using namespace std; -using namespace OpenMD; + AtomCommRealJ = new Comm(nAtoms); + AtomCommVectorJ = new Comm(nAtoms); + AtomCommMatrixJ = new Comm(nAtoms); -//__static -#ifdef IS_MPI -static vector communictors; + cgCommVectorI = new Comm(nGroups); + cgCommVectorJ = new Comm(nGroups); + // more to come #endif + } + -//____ MPITypeTraits -template -struct MPITypeTraits; + void ForceDecomposition::distributeData() { #ifdef IS_MPI -template<> -struct MPITypeTraits { - static const MPI::Datatype datatype; -}; -const MPI_Datatype MPITypeTraits::datatype = MY_MPI_REAL; + Snapshot* snap = sman_->getCurrentSnapshot(); -template<> -struct MPITypeTraits { - static const MPI::Datatype datatype; -}; -const MPI::Datatype MPITypeTraits::datatype = MPI_INT; -#endif - -/** -* Constructor for ForceDecomposition Parallel Decomposition Method -* Will try to construct a symmetric grid of processors. Ideally, the -* number of processors will be a square ex: 4, 9, 16, 25. -* -*/ - -ForceDecomposition::ForceDecomposition() { - + // gather up the atomic positions + AtomCommVectorI->gather(snap->atomData.position, + snap->atomIData.position); + AtomCommVectorJ->gather(snap->atomData.position, + snap->atomJData.position); + + // gather up the cutoff group positions + cgCommVectorI->gather(snap->cgData.position, + snap->cgIData.position); + cgCommVectorJ->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, + snap->atomIData.aMat); + AtomCommMatrixJ->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, + snap->atomIData.electroFrame); + AtomCommMatrixJ->gather(snap->atomData.electroFrame, + snap->atomJData.electroFrame); + } +#endif + } + + void ForceDecomposition::collectIntermediateData() { #ifdef IS_MPI - int nProcs = MPI::COMM_WORLD.Get_size(); - int worldRank = MPI::COMM_WORLD.Get_rank(); + Snapshot* snap = sman_->getCurrentSnapshot(); + // gather up the atomic positions + + if (snap->atomData.getStorageLayout() & DataStorage::dslDensity) { + AtomCommRealI->scatter(snap->atomIData.density, + snap->atomData.density); + std::vector rho_tmp; + int n = snap->getNumberOfAtoms(); + rho_tmp.reserve( n ); + AtomCommRealJ->scatter(snap->atomJData.density, rho_tmp); + for (int i = 0; i < n; i++) + snap->atomData.density[i] += rho_tmp[i]; + } #endif - - // First time through, construct column stride. - if (communicators.size() == 0) - { - int nColumnsMax = (int) round(sqrt((float) nProcs)); - for (int i = 0; i < nProcs; ++i) - { - if (nProcs%i==0) nColumns=i; + } + + void ForceDecomposition::distributeIntermediateData() { +#ifdef IS_MPI + Snapshot* snap = sman_->getCurrentSnapshot(); + if (snap->atomData.getStorageLayout() & DataStorage::dslFunctional) { + AtomCommRealI->gather(snap->atomData.functional, + snap->atomIData.functional); + AtomCommRealJ->gather(snap->atomData.functional, + snap->atomJData.functional); } - - int nRows = nProcs/nColumns; - myRank_ = (int) worldRank%nColumns; + + if (snap->atomData.getStorageLayout() & DataStorage::dslFunctionalDerivative) { + AtomCommRealI->gather(snap->atomData.functionalDerivative, + snap->atomIData.functionalDerivative); + AtomCommRealJ->gather(snap->atomData.functionalDerivative, + snap->atomJData.functionalDerivative); + } +#endif } - else - { - myRank_ = myRank/nColumns; - } - MPI::Comm newComm = MPI:COMM_WORLD.Split(myRank_,0); - isColumn_ = false; -} - -ForceDecomposition::gather(sendbuf, receivebuf){ - communicators(myIndex_).Allgatherv(); -} - - - -ForceDecomposition::scatter(sbuffer, rbuffer){ - communicators(myIndex_).Reduce_scatter(sbuffer, recevbuf. recvcounts, MPI::DOUBLE, MPI::SUM); -} - - + void ForceDecomposition::collectData() { +#ifdef IS_MPI +#endif + } + +} //end namespace OpenMD