47 |
|
|
48 |
|
#include "utils/OpenMDBitSet.hpp" |
49 |
|
#include "utils/Algorithm.hpp" |
50 |
+ |
#ifdef IS_MPI |
51 |
+ |
#include <mpi.h> |
52 |
+ |
#endif |
53 |
|
|
54 |
|
namespace OpenMD { |
55 |
|
int OpenMDBitSet::countBits() { |
194 |
|
bool operator== (const OpenMDBitSet & bs1, const OpenMDBitSet &bs2) { |
195 |
|
assert(bs1.size() == bs2.size()); |
196 |
|
return std::equal(bs1.bitset_.begin(), bs1.bitset_.end(), bs2.bitset_.begin()); |
197 |
+ |
} |
198 |
+ |
|
199 |
+ |
OpenMDBitSet OpenMDBitSet::parallelReduce() { |
200 |
+ |
OpenMDBitSet result; |
201 |
+ |
|
202 |
+ |
#ifdef IS_MPI |
203 |
+ |
|
204 |
+ |
// This is necessary because std::vector<bool> isn't really a |
205 |
+ |
// std::vector, so we can't pass the address of the first element |
206 |
+ |
// to the MPI call that follows. We first have to convert to a |
207 |
+ |
// std::vector<int> to do the logical_or Allreduce call, then back |
208 |
+ |
// convert it into the vector<bool>. |
209 |
+ |
|
210 |
+ |
std::vector<int> bsInt(bitset_.begin(), bitset_.end()); |
211 |
+ |
|
212 |
+ |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bsInt[0], |
213 |
+ |
bsInt.size(), MPI::INT, MPI::LOR); |
214 |
+ |
|
215 |
+ |
std::transform(bsInt.begin(), bsInt.end(), |
216 |
+ |
std::back_inserter( result.bitset_ ), to_bool<int>()); |
217 |
+ |
#else |
218 |
+ |
|
219 |
+ |
// Not in MPI? Just return a copy of the current bitset: |
220 |
+ |
std::copy(bitset_.begin(), bitset_.end(), |
221 |
+ |
std::back_inserter( result.bitset_ )); |
222 |
+ |
#endif |
223 |
+ |
|
224 |
+ |
return result; |
225 |
|
} |
226 |
|
|
227 |
|
//std::istream& operator>> ( std::istream& is, const OpenMDBitSet& bs) { |