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

Comparing:
trunk/src/utils/OpenMDBitSet.cpp (file contents), Revision 1442 by gezelter, Mon May 10 17:28:26 2010 UTC vs.
branches/development/src/utils/OpenMDBitSet.cpp (file contents), Revision 1803 by gezelter, Wed Oct 3 14:20:07 2012 UTC

# Line 36 | Line 36
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).                        
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   #include <algorithm>
44   #include <cassert>
45   #include <string>
46 + #include <iterator>
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() {
# Line 63 | Line 68 | namespace OpenMD {
68      assert(fromIndex <= toIndex);
69      assert(fromIndex >=0);
70      assert(toIndex <= size());
71 <    std::vector<char>::iterator first = bitset_.begin() + fromIndex;
72 <    std::vector<char>::iterator last = bitset_.begin() + toIndex;
71 >    std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
72 >    std::vector<bool>::iterator last = bitset_.begin() + toIndex;
73  
74      std::transform(first, last, first, std::logical_not<bool>());
75          
# Line 74 | Line 79 | namespace OpenMD {
79      assert(fromIndex <= toIndex);
80      assert(fromIndex >=0);
81      assert(toIndex <= size());
82 <    std::vector<char>::iterator first = bitset_.begin() + fromIndex;
83 <    std::vector<char>::iterator last = bitset_.begin() + toIndex;
82 >    std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
83 >    std::vector<bool>::iterator last = bitset_.begin() + toIndex;
84  
85      OpenMDBitSet result;
86      std::copy(first, last, std::back_inserter(result.bitset_));
# Line 83 | Line 88 | namespace OpenMD {
88    }
89  
90    bool OpenMDBitSet::none() {
91 <    std::vector<char>::iterator i = std::find(bitset_.begin(), bitset_.end(), true);
91 >    std::vector<bool>::iterator i = std::find(bitset_.begin(), bitset_.end(), true);
92      return i == bitset_.end() ? true : false;
93    }
94      
# Line 141 | Line 146 | namespace OpenMD {
146      assert(fromIndex <= toIndex);
147      assert(fromIndex >=0);
148      assert(toIndex <= size());
149 <    std::vector<char>::iterator first = bitset_.begin() + fromIndex;
150 <    std::vector<char>::iterator last = bitset_.begin() + toIndex;
149 >    std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
150 >    std::vector<bool>::iterator last = bitset_.begin() + toIndex;
151      std::fill(first, last, value);
152    }
153  
# Line 189 | Line 194 | namespace OpenMD {
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) {
# Line 197 | Line 230 | namespace OpenMD {
230    //}
231  
232    std::ostream& operator<< ( std::ostream& os, const OpenMDBitSet& bs) {
233 <    for (int i = 0; i < bs.bitset_.size(); ++i) {
233 >    for (unsigned int i = 0; i < bs.bitset_.size(); ++i) {
234        std::string val = bs[i] ? "true" : "false";
235        os << "OpenMDBitSet[" << i <<"] = " << val << std::endl;
236      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines