ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/utils/OpenMDBitSet.cpp
(Generate patch)

Comparing trunk/src/utils/OpenMDBitSet.cpp (file contents):
Revision 1390 by gezelter, Wed Nov 25 20:02:06 2009 UTC vs.
Revision 1938 by gezelter, Thu Oct 31 15:32:17 2013 UTC

# Line 35 | Line 35
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).          
39 < * [4]  Vardeman & Gezelter, in progress (2009).                        
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>
50 + #include <iterator>
51  
52   #include "utils/OpenMDBitSet.hpp"
53   #include "utils/Algorithm.hpp"
# Line 63 | Line 69 | namespace OpenMD {
69      assert(fromIndex <= toIndex);
70      assert(fromIndex >=0);
71      assert(toIndex <= size());
72 <    std::vector<char>::iterator first = bitset_.begin() + fromIndex;
73 <    std::vector<char>::iterator last = bitset_.begin() + toIndex;
72 >    std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
73 >    std::vector<bool>::iterator last = bitset_.begin() + toIndex;
74  
75      std::transform(first, last, first, std::logical_not<bool>());
76          
# Line 74 | Line 80 | namespace OpenMD {
80      assert(fromIndex <= toIndex);
81      assert(fromIndex >=0);
82      assert(toIndex <= size());
83 <    std::vector<char>::iterator first = bitset_.begin() + fromIndex;
84 <    std::vector<char>::iterator last = bitset_.begin() + toIndex;
83 >    std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
84 >    std::vector<bool>::iterator last = bitset_.begin() + toIndex;
85  
86      OpenMDBitSet result;
87      std::copy(first, last, std::back_inserter(result.bitset_));
# Line 83 | Line 89 | namespace OpenMD {
89    }
90  
91    bool OpenMDBitSet::none() {
92 <    std::vector<char>::iterator i = std::find(bitset_.begin(), bitset_.end(), true);
92 >    std::vector<bool>::iterator i = std::find(bitset_.begin(), bitset_.end(), true);
93      return i == bitset_.end() ? true : false;
94    }
95      
# Line 141 | Line 147 | namespace OpenMD {
147      assert(fromIndex <= toIndex);
148      assert(fromIndex >=0);
149      assert(toIndex <= size());
150 <    std::vector<char>::iterator first = bitset_.begin() + fromIndex;
151 <    std::vector<char>::iterator last = bitset_.begin() + toIndex;
150 >    std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
151 >    std::vector<bool>::iterator last = bitset_.begin() + toIndex;
152      std::fill(first, last, value);
153    }
154  
# Line 189 | Line 195 | namespace OpenMD {
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::COMM_WORLD.Allreduce(MPI::IN_PLACE, &bsInt[0],
214 +                              bsInt.size(), MPI::INT, MPI::LOR);
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) {
# Line 197 | Line 231 | namespace OpenMD {
231    //}
232  
233    std::ostream& operator<< ( std::ostream& os, const OpenMDBitSet& bs) {
234 <    for (int i = 0; i < bs.bitset_.size(); ++i) {
234 >    for (unsigned int i = 0; i < bs.bitset_.size(); ++i) {
235        std::string val = bs[i] ? "true" : "false";
236        os << "OpenMDBitSet[" << i <<"] = " << val << std::endl;
237      }

Comparing trunk/src/utils/OpenMDBitSet.cpp (property svn:keywords):
Revision 1390 by gezelter, Wed Nov 25 20:02:06 2009 UTC vs.
Revision 1938 by gezelter, Thu Oct 31 15:32:17 2013 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines