--- trunk/src/utils/OpenMDBitSet.cpp 2012/08/22 02:28:28 1782 +++ trunk/src/utils/OpenMDBitSet.cpp 2013/10/31 15:32:17 1938 @@ -35,11 +35,15 @@ * * [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). + * [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). */ +#ifdef IS_MPI +#include +#endif + #include #include #include @@ -191,6 +195,34 @@ namespace OpenMD { bool operator== (const OpenMDBitSet & bs1, const OpenMDBitSet &bs2) { assert(bs1.size() == bs2.size()); return std::equal(bs1.bitset_.begin(), bs1.bitset_.end(), bs2.bitset_.begin()); + } + + OpenMDBitSet OpenMDBitSet::parallelReduce() { + OpenMDBitSet result; + +#ifdef IS_MPI + + // This is necessary because std::vector isn't really a + // std::vector, so we can't pass the address of the first element + // to the MPI call that follows. We first have to convert to a + // std::vector to do the logical_or Allreduce call, then back + // convert it into the vector. + + std::vector bsInt(bitset_.begin(), bitset_.end()); + + MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bsInt[0], + bsInt.size(), MPI::INT, MPI::LOR); + + std::transform(bsInt.begin(), bsInt.end(), + std::back_inserter( result.bitset_ ), to_bool()); +#else + + // Not in MPI? Just return a copy of the current bitset: + std::copy(bitset_.begin(), bitset_.end(), + std::back_inserter( result.bitset_ )); +#endif + + return result; } //std::istream& operator>> ( std::istream& is, const OpenMDBitSet& bs) {