| 35 |
|
* |
| 36 |
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
| 37 |
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
| 38 |
< |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
| 38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
| 39 |
|
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
|
*/ |
| 42 |
|
|
| 43 |
+ |
#ifdef IS_MPI |
| 44 |
+ |
#include <mpi.h> |
| 45 |
+ |
#endif |
| 46 |
+ |
|
| 47 |
|
#include <algorithm> |
| 48 |
|
#include <cassert> |
| 49 |
|
#include <string> |
| 195 |
|
bool operator== (const OpenMDBitSet & bs1, const OpenMDBitSet &bs2) { |
| 196 |
|
assert(bs1.size() == bs2.size()); |
| 197 |
|
return std::equal(bs1.bitset_.begin(), bs1.bitset_.end(), bs2.bitset_.begin()); |
| 198 |
+ |
} |
| 199 |
+ |
|
| 200 |
+ |
OpenMDBitSet OpenMDBitSet::parallelReduce() { |
| 201 |
+ |
OpenMDBitSet result; |
| 202 |
+ |
|
| 203 |
+ |
#ifdef IS_MPI |
| 204 |
+ |
|
| 205 |
+ |
// This is necessary because std::vector<bool> isn't really a |
| 206 |
+ |
// std::vector, so we can't pass the address of the first element |
| 207 |
+ |
// to the MPI call that follows. We first have to convert to a |
| 208 |
+ |
// std::vector<int> to do the logical_or Allreduce call, then back |
| 209 |
+ |
// convert it into the vector<bool>. |
| 210 |
+ |
|
| 211 |
+ |
std::vector<int> bsInt(bitset_.begin(), bitset_.end()); |
| 212 |
+ |
|
| 213 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &bsInt[0], |
| 214 |
+ |
bsInt.size(), MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 215 |
+ |
|
| 216 |
+ |
std::transform(bsInt.begin(), bsInt.end(), |
| 217 |
+ |
std::back_inserter( result.bitset_ ), to_bool<int>()); |
| 218 |
+ |
#else |
| 219 |
+ |
|
| 220 |
+ |
// Not in MPI? Just return a copy of the current bitset: |
| 221 |
+ |
std::copy(bitset_.begin(), bitset_.end(), |
| 222 |
+ |
std::back_inserter( result.bitset_ )); |
| 223 |
+ |
#endif |
| 224 |
+ |
|
| 225 |
+ |
return result; |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
//std::istream& operator>> ( std::istream& is, const OpenMDBitSet& bs) { |