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

Comparing trunk/src/selection/DistanceFinder.cpp (file contents):
Revision 1434 by chuckv, Wed Apr 14 14:41:33 2010 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 "selection/DistanceFinder.hpp"
48   #include "primitives/Molecule.hpp"
44 namespace OpenMD {
49  
50 + namespace OpenMD {
51 +  
52    DistanceFinder::DistanceFinder(SimInfo* info) : info_(info) {
53 <
53 >    
54      nStuntDoubles_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies();
55      stuntdoubles_.resize(nStuntDoubles_);
56      
# Line 54 | Line 60 | namespace OpenMD {
60      Atom* atom;
61      Molecule::RigidBodyIterator rbIter;
62      RigidBody* rb;
57
63      
64 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
64 >    
65 >    for (mol = info_->beginMolecule(mi); mol != NULL;
66 >         mol = info_->nextMolecule(mi)) {
67          
68 <      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
68 >      for(atom = mol->beginAtom(ai); atom != NULL;
69 >          atom = mol->nextAtom(ai)) {
70          stuntdoubles_[atom->getGlobalIndex()] = atom;
71        }
72  
73 <      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
73 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
74 >           rb = mol->nextRigidBody(rbIter)) {
75          stuntdoubles_[rb->getGlobalIndex()] = rb;
76        }
77 <        
69 <    }    
70 <
77 >    }
78    }
79  
80    OpenMDBitSet DistanceFinder::find(const OpenMDBitSet& bs, RealType distance) {
81      StuntDouble * center;
82      Vector3d centerPos;
83      Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
84 <    OpenMDBitSet bsResult(nStuntDoubles_);
84 >    OpenMDBitSet bsResult(nStuntDoubles_);  
85      assert(bsResult.size() == bs.size());
86 <  
87 <    for (int j = 0; j < stuntdoubles_.size(); ++j) {
86 >
87 > #ifdef IS_MPI
88 >    int mol;
89 >    int proc;
90 >    RealType data[3];
91 >    int worldRank = MPI::COMM_WORLD.Get_rank();
92 > #endif
93 >
94 >    for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) {
95        if (stuntdoubles_[j]->isRigidBody()) {
96          RigidBody* rb = static_cast<RigidBody*>(stuntdoubles_[j]);
97          rb->updateAtoms();
98        }
99      }
100 <  
101 <    for (int i = bs.firstOnBit(); i != -1; i = bs.nextOnBit(i)) {
100 >      
101 >    OpenMDBitSet bsTemp(nStuntDoubles_);
102 >    bsTemp = bs;
103 >    bsTemp.parallelReduce();
104 >
105 >    for (int i = bsTemp.firstOnBit(); i != -1; i = bsTemp.nextOnBit(i)) {
106 >
107 >      // Now, if we own stuntdouble i, we can use the position, but in
108 >      // parallel, we'll need to let everyone else know what that
109 >      // position is!
110 >
111 > #ifdef IS_MPI
112 >      mol = info_->getGlobalMolMembership(i);
113 >      proc = info_->getMolToProc(mol);
114 >    
115 >      if (proc == worldRank) {
116 >        center = stuntdoubles_[i];
117 >        centerPos = center->getPos();
118 >        data[0] = centerPos.x();
119 >        data[1] = centerPos.y();
120 >        data[2] = centerPos.z();          
121 >        MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc);
122 >      } else {
123 >        MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc);
124 >        centerPos = Vector3d(data);
125 >      }
126 > #else
127        center = stuntdoubles_[i];
128        centerPos = center->getPos();
129 <      for (int j = 0; j < stuntdoubles_.size(); ++j) {
129 > #endif
130 >      
131 >      for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) {
132          Vector3d r =centerPos - stuntdoubles_[j]->getPos();
133          currSnapshot->wrapVector(r);
134          if (r.length() <= distance) {
# Line 95 | Line 136 | namespace OpenMD {
136          }
137        }
138      }
98
139      return bsResult;
140    }
141  
142 +
143 + OpenMDBitSet DistanceFinder::find(const OpenMDBitSet& bs, RealType distance, int frame ) {
144 +    StuntDouble * center;
145 +    Vector3d centerPos;
146 +    Snapshot* currSnapshot = info_->getSnapshotManager()->getSnapshot(frame);
147 +    OpenMDBitSet bsResult(nStuntDoubles_);  
148 +    assert(bsResult.size() == bs.size());
149 +
150 + #ifdef IS_MPI
151 +    int mol;
152 +    int proc;
153 +    RealType data[3];
154 +    int worldRank = MPI::COMM_WORLD.Get_rank();
155 + #endif
156 +
157 +    for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) {
158 +      if (stuntdoubles_[j]->isRigidBody()) {
159 +        RigidBody* rb = static_cast<RigidBody*>(stuntdoubles_[j]);
160 +        rb->updateAtoms(frame);
161 +      }
162 +    }
163 +      
164 +    OpenMDBitSet bsTemp(nStuntDoubles_);
165 +    bsTemp = bs;
166 +    bsTemp.parallelReduce();
167 +
168 +    for (int i = bsTemp.firstOnBit(); i != -1; i = bsTemp.nextOnBit(i)) {
169 +
170 +      // Now, if we own stuntdouble i, we can use the position, but in
171 +      // parallel, we'll need to let everyone else know what that
172 +      // position is!
173 +
174 + #ifdef IS_MPI
175 +      mol = info_->getGlobalMolMembership(i);
176 +      proc = info_->getMolToProc(mol);
177 +    
178 +      if (proc == worldRank) {
179 +        center = stuntdoubles_[i];
180 +        centerPos = center->getPos(frame);
181 +        data[0] = centerPos.x();
182 +        data[1] = centerPos.y();
183 +        data[2] = centerPos.z();          
184 +        MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc);
185 +      } else {
186 +        MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc);
187 +        centerPos = Vector3d(data);
188 +      }
189 + #else
190 +      center = stuntdoubles_[i];
191 +      centerPos = center->getPos(frame);
192 + #endif
193 +      
194 +      for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) {
195 +        Vector3d r =centerPos - stuntdoubles_[j]->getPos(frame);
196 +        currSnapshot->wrapVector(r);
197 +        if (r.length() <= distance) {
198 +          bsResult.setBitOn(j);
199 +        }
200 +      }
201 +    }
202 +    return bsResult;
203 +  }
204   }

Comparing trunk/src/selection/DistanceFinder.cpp (property svn:keywords):
Revision 1434 by chuckv, Wed Apr 14 14:41:33 2010 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