--- trunk/OOPSE-4/src/restraints/ThermoIntegrationForceManager.cpp 2006/08/31 11:36:54 2989 +++ trunk/OOPSE-4/src/restraints/ThermoIntegrationForceManager.cpp 2006/08/31 20:12:12 2990 @@ -48,6 +48,11 @@ namespace oopse { #include "utils/OOPSEConstant.hpp" #include "utils/StringUtils.hpp" +#ifdef IS_MPI +#include +#define TAKE_THIS_TAG_REAL 2 +#endif //is_mpi + namespace oopse { ThermoIntegrationForceManager::ThermoIntegrationForceManager(SimInfo* info): @@ -146,8 +151,9 @@ namespace oopse { tempTau = curSnapshot->statData.getTau(); tempTau *= factor_; curSnapshot->statData.setTau(tempTau); - - // do crystal restraint forces for thermodynamic integration +#ifndef IS_MPI + // do the single processor crystal restraint forces for + // thermodynamic integration if (simParam->getUseSolidThermInt()) { lrPot_ += restraint_->Calc_Restraint_Forces(); @@ -156,7 +162,52 @@ namespace oopse { vHarm_ = restraint_->getVharm(); curSnapshot->statData[Stats::VHARM] = vHarm_; } - +#else + double tempLRPot = 0.0; + double tempVHarm = 0.0; + MPI_Status ierr; + int nproc; + MPI_Comm_size(MPI_COMM_WORLD, &nproc); + + // do the MPI crystal restraint forces for each processor + if (simParam->getUseSolidThermInt()) { + tempLRPot = restraint_->Calc_Restraint_Forces(); + tempVHarm = restraint_->getVharm(); + } + + // master receives and accumulates the restraint info + if (worldRank == 0) { + for(int i = 0 ; i < nproc; ++i) { + if (i == worldRank) { + lrPot_ += tempLRPot; + vHarm_ += tempVHarm; + } else { + MPI_Recv(&tempLRPot, 1, MPI_REALTYPE, i, + TAKE_THIS_TAG_REAL, MPI_COMM_WORLD, &ierr); + MPI_Recv(&tempVHarm, 1, MPI_REALTYPE, i, + TAKE_THIS_TAG_REAL, MPI_COMM_WORLD, &ierr); + lrPot_ += tempLRPot; + vHarm_ += tempVHarm; + } + } + + // give the final values to stats + curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot_; + curSnapshot->statData[Stats::VHARM] = vHarm_; + + } else { + // pack up and send the appropriate info to the master node + for(int j = 1; j < nproc; ++j) { + if (worldRank == j) { + + MPI_Send(&tempLRPot, 1, MPI_REALTYPE, 0, + TAKE_THIS_TAG_REAL, MPI_COMM_WORLD); + MPI_Send(&tempVHarm, 1, MPI_REALTYPE, 0, + TAKE_THIS_TAG_REAL, MPI_COMM_WORLD); + } + } + } +#endif //is_mpi } }