--- branches/development/src/parallel/Communicator.hpp 2011/08/04 20:04:35 1601 +++ trunk/src/parallel/Communicator.hpp 2014/04/17 19:07:31 1987 @@ -2,7 +2,6 @@ * @file Communicator.hpp * @author Charles Vardeman * @date 08/18/2010 - * @time 11:56am * @version 1.0 * * @section LICENSE @@ -42,8 +41,9 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #ifndef PARALLEL_COMMUNICATOR_HPP @@ -67,38 +67,38 @@ namespace OpenMD{ template class MPITraits { public: - static MPI::Datatype Type(); + static MPI_Datatype Type(); static int Length() { return 1; }; }; - template<> inline MPI::Datatype MPITraits::Type() { return MPI_INT; } - template<> inline MPI::Datatype MPITraits::Type() { return MPI_REALTYPE; } + template<> inline MPI_Datatype MPITraits::Type() { return MPI_INT; } + template<> inline MPI_Datatype MPITraits::Type() { return MPI_REALTYPE; } template class MPITraits< Vector > { public: - static MPI::Datatype Type() { return MPITraits::Type(); } + static MPI_Datatype Type() { return MPITraits::Type(); } static int Length() {return Dim;} }; template class MPITraits< Vector3 > { public: - static MPI::Datatype Type() { return MPITraits::Type(); } + static MPI_Datatype Type() { return MPITraits::Type(); } static int Length() {return 3;} }; - template - class MPITraits< RectMatrix > { + template + class MPITraits< RectMatrix > { public: - static MPI::Datatype Type() { return MPITraits::Type(); } - static int Length() {return Row * Col;} + static MPI_Datatype Type() { return MPITraits::Type(); } + static int Length() {return R * C;} }; template class MPITraits< SquareMatrix3 > { public: - static MPI::Datatype Type() { return MPITraits::Type(); } + static MPI_Datatype Type() { return MPITraits::Type(); } static int Length() {return 9;} }; @@ -109,8 +109,11 @@ namespace OpenMD{ Communicator() { - int nProc = MPI::COMM_WORLD.Get_size(); - int myRank = MPI::COMM_WORLD.Get_rank(); + int nProc; + int myRank; + + MPI_Comm_size( MPI_COMM_WORLD, &nProc); + MPI_Comm_rank( MPI_COMM_WORLD, &myRank); int nColumnsMax = (int) sqrt(RealType(nProc)); @@ -119,29 +122,29 @@ namespace OpenMD{ if (nProc % i == 0) nColumns = i; } - int nRows = nProc / nColumns; + // int nRows = nProc / nColumns; rowIndex_ = myRank / nColumns; columnIndex_ = myRank % nColumns; switch(D) { case Row : - myComm = MPI::COMM_WORLD.Split(rowIndex_, 0); + MPI_Comm_split(MPI_COMM_WORLD, rowIndex_, 0, &myComm); break; case Column: - myComm = MPI::COMM_WORLD.Split(columnIndex_, 0); + MPI_Comm_split(MPI_COMM_WORLD, columnIndex_, 0, &myComm); break; case Global: - myComm = MPI::COMM_WORLD.Split(myRank, 0); + MPI_Comm_split(MPI_COMM_WORLD, myRank, 0, &myComm); } } - MPI::Intracomm getComm() { return myComm; } + MPI_Comm getComm() { return myComm; } private: int rowIndex_; int columnIndex_; - MPI::Intracomm myComm; + MPI_Comm myComm; }; @@ -149,16 +152,17 @@ namespace OpenMD{ class Plan { public: - Plan(MPI::Intracomm comm, int nObjects) { - myComm = comm; - int nCommProcs = myComm.Get_size(); + Plan(MPI_Comm comm, int nObjects) : myComm(comm) { + + int nCommProcs; + MPI_Comm_size( myComm, &nCommProcs ); counts.resize(nCommProcs, 0); displacements.resize(nCommProcs, 0); planSize_ = MPITraits::Length() * nObjects; - myComm.Allgather(&planSize_, 1, MPI::INT, &counts[0], 1, MPI::INT); + MPI_Allgather(&planSize_, 1, MPI_INT, &counts[0], 1, MPI_INT, myComm); displacements[0] = 0; for (int i = 1; i < nCommProcs; i++) { @@ -177,21 +181,22 @@ namespace OpenMD{ // an assert would be helpful here to make sure the vectors are the // correct geometry - myComm.Allgatherv(&v1[0], - planSize_, - MPITraits::Type(), - &v2[0], - &counts[0], - &displacements[0], - MPITraits::Type()); + MPI_Allgatherv(&v1[0], + planSize_, + MPITraits::Type(), + &v2[0], + &counts[0], + &displacements[0], + MPITraits::Type(), + myComm); } void scatter(vector& v1, vector& v2) { // an assert would be helpful here to make sure the vectors are the // correct geometry - myComm.Reduce_scatter(&v1[0], &v2[0], &counts[0], - MPITraits::Type(), MPI::SUM); + MPI_Reduce_scatter(&v1[0], &v2[0], &counts[0], + MPITraits::Type(), MPI_SUM, myComm); } int getSize() { @@ -203,7 +208,7 @@ namespace OpenMD{ int size_; vector counts; vector displacements; - MPI::Intracomm myComm; + MPI_Comm myComm; }; #endif