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

Comparing branches/development/src/parallel/ForceMatrixDecomposition.cpp (file contents):
Revision 1575 by gezelter, Fri Jun 3 21:39:49 2011 UTC vs.
Revision 1755 by gezelter, Thu Jun 14 01:58:35 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   #include "parallel/ForceMatrixDecomposition.hpp"
43   #include "math/SquareMatrix3.hpp"
# Line 47 | Line 48 | namespace OpenMD {
48   using namespace std;
49   namespace OpenMD {
50  
51 +  ForceMatrixDecomposition::ForceMatrixDecomposition(SimInfo* info, InteractionManager* iMan) : ForceDecomposition(info, iMan) {
52 +
53 +    // In a parallel computation, row and colum scans must visit all
54 +    // surrounding cells (not just the 14 upper triangular blocks that
55 +    // are used when the processor can see all pairs)
56 + #ifdef IS_MPI
57 +    cellOffsets_.clear();
58 +    cellOffsets_.push_back( Vector3i(-1,-1,-1) );
59 +    cellOffsets_.push_back( Vector3i( 0,-1,-1) );
60 +    cellOffsets_.push_back( Vector3i( 1,-1,-1) );                          
61 +    cellOffsets_.push_back( Vector3i(-1, 0,-1) );
62 +    cellOffsets_.push_back( Vector3i( 0, 0,-1) );
63 +    cellOffsets_.push_back( Vector3i( 1, 0,-1) );
64 +    cellOffsets_.push_back( Vector3i(-1, 1,-1) );
65 +    cellOffsets_.push_back( Vector3i( 0, 1,-1) );      
66 +    cellOffsets_.push_back( Vector3i( 1, 1,-1) );
67 +    cellOffsets_.push_back( Vector3i(-1,-1, 0) );
68 +    cellOffsets_.push_back( Vector3i( 0,-1, 0) );
69 +    cellOffsets_.push_back( Vector3i( 1,-1, 0) );
70 +    cellOffsets_.push_back( Vector3i(-1, 0, 0) );      
71 +    cellOffsets_.push_back( Vector3i( 0, 0, 0) );
72 +    cellOffsets_.push_back( Vector3i( 1, 0, 0) );
73 +    cellOffsets_.push_back( Vector3i(-1, 1, 0) );
74 +    cellOffsets_.push_back( Vector3i( 0, 1, 0) );
75 +    cellOffsets_.push_back( Vector3i( 1, 1, 0) );
76 +    cellOffsets_.push_back( Vector3i(-1,-1, 1) );
77 +    cellOffsets_.push_back( Vector3i( 0,-1, 1) );
78 +    cellOffsets_.push_back( Vector3i( 1,-1, 1) );
79 +    cellOffsets_.push_back( Vector3i(-1, 0, 1) );
80 +    cellOffsets_.push_back( Vector3i( 0, 0, 1) );
81 +    cellOffsets_.push_back( Vector3i( 1, 0, 1) );
82 +    cellOffsets_.push_back( Vector3i(-1, 1, 1) );
83 +    cellOffsets_.push_back( Vector3i( 0, 1, 1) );
84 +    cellOffsets_.push_back( Vector3i( 1, 1, 1) );
85 + #endif    
86 +  }
87 +
88 +
89    /**
90     * distributeInitialData is essentially a copy of the older fortran
91     * SimulationSetup
92     */
54  
93    void ForceMatrixDecomposition::distributeInitialData() {
94      snap_ = sman_->getCurrentSnapshot();
95      storageLayout_ = sman_->getStorageLayout();
96      ff_ = info_->getForceField();
97      nLocal_ = snap_->getNumberOfAtoms();
98 <    nGroups_ = snap_->getNumberOfCutoffGroups();
99 <
98 >  
99 >    nGroups_ = info_->getNLocalCutoffGroups();
100      // gather the information for atomtype IDs (atids):
101 <    identsLocal = info_->getIdentArray();
101 >    idents = info_->getIdentArray();
102      AtomLocalToGlobal = info_->getGlobalAtomIndices();
103      cgLocalToGlobal = info_->getGlobalGroupIndices();
104      vector<int> globalGroupMembership = info_->getGlobalGroupMembership();
67    vector<RealType> massFactorsLocal = info_->getMassFactors();
68    PairList excludes = info_->getExcludedInteractions();
69    PairList oneTwo = info_->getOneTwoInteractions();
70    PairList oneThree = info_->getOneThreeInteractions();
71    PairList oneFour = info_->getOneFourInteractions();
105  
106 +    massFactors = info_->getMassFactors();
107 +
108 +    PairList* excludes = info_->getExcludedInteractions();
109 +    PairList* oneTwo = info_->getOneTwoInteractions();
110 +    PairList* oneThree = info_->getOneThreeInteractions();
111 +    PairList* oneFour = info_->getOneFourInteractions();
112 +    
113 +    if (needVelocities_)
114 +      snap_->cgData.setStorageLayout(DataStorage::dslPosition |
115 +                                     DataStorage::dslVelocity);
116 +    else
117 +      snap_->cgData.setStorageLayout(DataStorage::dslPosition);
118 +    
119   #ifdef IS_MPI
120  
121 <    AtomCommIntRow = new Communicator<Row,int>(nLocal_);
122 <    AtomCommRealRow = new Communicator<Row,RealType>(nLocal_);
77 <    AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal_);
78 <    AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal_);
79 <    AtomCommPotRow = new Communicator<Row,potVec>(nLocal_);
121 >    MPI::Intracomm row = rowComm.getComm();
122 >    MPI::Intracomm col = colComm.getComm();
123  
124 <    AtomCommIntColumn = new Communicator<Column,int>(nLocal_);
125 <    AtomCommRealColumn = new Communicator<Column,RealType>(nLocal_);
126 <    AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal_);
127 <    AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal_);
128 <    AtomCommPotColumn = new Communicator<Column,potVec>(nLocal_);
124 >    AtomPlanIntRow = new Plan<int>(row, nLocal_);
125 >    AtomPlanRealRow = new Plan<RealType>(row, nLocal_);
126 >    AtomPlanVectorRow = new Plan<Vector3d>(row, nLocal_);
127 >    AtomPlanMatrixRow = new Plan<Mat3x3d>(row, nLocal_);
128 >    AtomPlanPotRow = new Plan<potVec>(row, nLocal_);
129  
130 <    cgCommIntRow = new Communicator<Row,int>(nGroups_);
131 <    cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups_);
132 <    cgCommIntColumn = new Communicator<Column,int>(nGroups_);
133 <    cgCommVectorColumn = new Communicator<Column,Vector3d>(nGroups_);
130 >    AtomPlanIntColumn = new Plan<int>(col, nLocal_);
131 >    AtomPlanRealColumn = new Plan<RealType>(col, nLocal_);
132 >    AtomPlanVectorColumn = new Plan<Vector3d>(col, nLocal_);
133 >    AtomPlanMatrixColumn = new Plan<Mat3x3d>(col, nLocal_);
134 >    AtomPlanPotColumn = new Plan<potVec>(col, nLocal_);
135  
136 <    nAtomsInRow_ = AtomCommIntRow->getSize();
137 <    nAtomsInCol_ = AtomCommIntColumn->getSize();
138 <    nGroupsInRow_ = cgCommIntRow->getSize();
139 <    nGroupsInCol_ = cgCommIntColumn->getSize();
136 >    cgPlanIntRow = new Plan<int>(row, nGroups_);
137 >    cgPlanVectorRow = new Plan<Vector3d>(row, nGroups_);
138 >    cgPlanIntColumn = new Plan<int>(col, nGroups_);
139 >    cgPlanVectorColumn = new Plan<Vector3d>(col, nGroups_);
140  
141 +    nAtomsInRow_ = AtomPlanIntRow->getSize();
142 +    nAtomsInCol_ = AtomPlanIntColumn->getSize();
143 +    nGroupsInRow_ = cgPlanIntRow->getSize();
144 +    nGroupsInCol_ = cgPlanIntColumn->getSize();
145 +
146      // Modify the data storage objects with the correct layouts and sizes:
147      atomRowData.resize(nAtomsInRow_);
148      atomRowData.setStorageLayout(storageLayout_);
# Line 102 | Line 151 | namespace OpenMD {
151      cgRowData.resize(nGroupsInRow_);
152      cgRowData.setStorageLayout(DataStorage::dslPosition);
153      cgColData.resize(nGroupsInCol_);
154 <    cgColData.setStorageLayout(DataStorage::dslPosition);
155 <        
156 <    identsRow.reserve(nAtomsInRow_);
157 <    identsCol.reserve(nAtomsInCol_);
154 >    if (needVelocities_)
155 >      // we only need column velocities if we need them.
156 >      cgColData.setStorageLayout(DataStorage::dslPosition |
157 >                                 DataStorage::dslVelocity);
158 >    else    
159 >      cgColData.setStorageLayout(DataStorage::dslPosition);
160 >      
161 >    identsRow.resize(nAtomsInRow_);
162 >    identsCol.resize(nAtomsInCol_);
163      
164 <    AtomCommIntRow->gather(identsLocal, identsRow);
165 <    AtomCommIntColumn->gather(identsLocal, identsCol);
164 >    AtomPlanIntRow->gather(idents, identsRow);
165 >    AtomPlanIntColumn->gather(idents, identsCol);
166      
167 <    AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal);
168 <    AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal);
169 <    
116 <    cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal);
117 <    cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal);
167 >    // allocate memory for the parallel objects
168 >    atypesRow.resize(nAtomsInRow_);
169 >    atypesCol.resize(nAtomsInCol_);
170  
171 <    AtomCommRealRow->gather(massFactorsLocal, massFactorsRow);
172 <    AtomCommRealColumn->gather(massFactorsLocal, massFactorsCol);
171 >    for (int i = 0; i < nAtomsInRow_; i++)
172 >      atypesRow[i] = ff_->getAtomType(identsRow[i]);
173 >    for (int i = 0; i < nAtomsInCol_; i++)
174 >      atypesCol[i] = ff_->getAtomType(identsCol[i]);        
175  
176 +    pot_row.resize(nAtomsInRow_);
177 +    pot_col.resize(nAtomsInCol_);
178 +
179 +    AtomRowToGlobal.resize(nAtomsInRow_);
180 +    AtomColToGlobal.resize(nAtomsInCol_);
181 +    AtomPlanIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal);
182 +    AtomPlanIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal);
183 +
184 +    cgRowToGlobal.resize(nGroupsInRow_);
185 +    cgColToGlobal.resize(nGroupsInCol_);
186 +    cgPlanIntRow->gather(cgLocalToGlobal, cgRowToGlobal);
187 +    cgPlanIntColumn->gather(cgLocalToGlobal, cgColToGlobal);
188 +
189 +    massFactorsRow.resize(nAtomsInRow_);
190 +    massFactorsCol.resize(nAtomsInCol_);
191 +    AtomPlanRealRow->gather(massFactors, massFactorsRow);
192 +    AtomPlanRealColumn->gather(massFactors, massFactorsCol);
193 +
194      groupListRow_.clear();
195 <    groupListRow_.reserve(nGroupsInRow_);
195 >    groupListRow_.resize(nGroupsInRow_);
196      for (int i = 0; i < nGroupsInRow_; i++) {
197        int gid = cgRowToGlobal[i];
198        for (int j = 0; j < nAtomsInRow_; j++) {
# Line 131 | Line 203 | namespace OpenMD {
203      }
204  
205      groupListCol_.clear();
206 <    groupListCol_.reserve(nGroupsInCol_);
206 >    groupListCol_.resize(nGroupsInCol_);
207      for (int i = 0; i < nGroupsInCol_; i++) {
208        int gid = cgColToGlobal[i];
209        for (int j = 0; j < nAtomsInCol_; j++) {
# Line 141 | Line 213 | namespace OpenMD {
213        }      
214      }
215  
216 <    skipsForRowAtom.clear();
217 <    skipsForRowAtom.reserve(nAtomsInRow_);
216 >    excludesForAtom.clear();
217 >    excludesForAtom.resize(nAtomsInRow_);
218 >    toposForAtom.clear();
219 >    toposForAtom.resize(nAtomsInRow_);
220 >    topoDist.clear();
221 >    topoDist.resize(nAtomsInRow_);
222      for (int i = 0; i < nAtomsInRow_; i++) {
223        int iglob = AtomRowToGlobal[i];
224 +
225        for (int j = 0; j < nAtomsInCol_; j++) {
226 <        int jglob = AtomColToGlobal[j];        
227 <        if (excludes.hasPair(iglob, jglob))
228 <          skipsForRowAtom[i].push_back(j);      
226 >        int jglob = AtomColToGlobal[j];
227 >
228 >        if (excludes->hasPair(iglob, jglob))
229 >          excludesForAtom[i].push_back(j);      
230 >        
231 >        if (oneTwo->hasPair(iglob, jglob)) {
232 >          toposForAtom[i].push_back(j);
233 >          topoDist[i].push_back(1);
234 >        } else {
235 >          if (oneThree->hasPair(iglob, jglob)) {
236 >            toposForAtom[i].push_back(j);
237 >            topoDist[i].push_back(2);
238 >          } else {
239 >            if (oneFour->hasPair(iglob, jglob)) {
240 >              toposForAtom[i].push_back(j);
241 >              topoDist[i].push_back(3);
242 >            }
243 >          }
244 >        }
245        }      
246      }
247  
248 <    toposForRowAtom.clear();
249 <    toposForRowAtom.reserve(nAtomsInRow_);
250 <    for (int i = 0; i < nAtomsInRow_; i++) {
251 <      int iglob = AtomRowToGlobal[i];
252 <      int nTopos = 0;
253 <      for (int j = 0; j < nAtomsInCol_; j++) {
254 <        int jglob = AtomColToGlobal[j];        
255 <        if (oneTwo.hasPair(iglob, jglob)) {
256 <          toposForRowAtom[i].push_back(j);
257 <          topoDistRow[i][nTopos] = 1;
258 <          nTopos++;
248 > #else
249 >    excludesForAtom.clear();
250 >    excludesForAtom.resize(nLocal_);
251 >    toposForAtom.clear();
252 >    toposForAtom.resize(nLocal_);
253 >    topoDist.clear();
254 >    topoDist.resize(nLocal_);
255 >
256 >    for (int i = 0; i < nLocal_; i++) {
257 >      int iglob = AtomLocalToGlobal[i];
258 >
259 >      for (int j = 0; j < nLocal_; j++) {
260 >        int jglob = AtomLocalToGlobal[j];
261 >
262 >        if (excludes->hasPair(iglob, jglob))
263 >          excludesForAtom[i].push_back(j);              
264 >        
265 >        if (oneTwo->hasPair(iglob, jglob)) {
266 >          toposForAtom[i].push_back(j);
267 >          topoDist[i].push_back(1);
268 >        } else {
269 >          if (oneThree->hasPair(iglob, jglob)) {
270 >            toposForAtom[i].push_back(j);
271 >            topoDist[i].push_back(2);
272 >          } else {
273 >            if (oneFour->hasPair(iglob, jglob)) {
274 >              toposForAtom[i].push_back(j);
275 >              topoDist[i].push_back(3);
276 >            }
277 >          }
278          }
167        if (oneThree.hasPair(iglob, jglob)) {
168          toposForRowAtom[i].push_back(j);
169          topoDistRow[i][nTopos] = 2;
170          nTopos++;
171        }
172        if (oneFour.hasPair(iglob, jglob)) {
173          toposForRowAtom[i].push_back(j);
174          topoDistRow[i][nTopos] = 3;
175          nTopos++;
176        }
279        }      
280      }
179
281   #endif
282  
283 +    // allocate memory for the parallel objects
284 +    atypesLocal.resize(nLocal_);
285 +
286 +    for (int i = 0; i < nLocal_; i++)
287 +      atypesLocal[i] = ff_->getAtomType(idents[i]);
288 +
289      groupList_.clear();
290 <    groupList_.reserve(nGroups_);
290 >    groupList_.resize(nGroups_);
291      for (int i = 0; i < nGroups_; i++) {
292        int gid = cgLocalToGlobal[i];
293        for (int j = 0; j < nLocal_; j++) {
294          int aid = AtomLocalToGlobal[j];
295 <        if (globalGroupMembership[aid] == gid)
295 >        if (globalGroupMembership[aid] == gid) {
296            groupList_[i].push_back(j);
297 +        }
298        }      
299      }
300  
193    skipsForLocalAtom.clear();
194    skipsForLocalAtom.reserve(nLocal_);
301  
302 <    for (int i = 0; i < nLocal_; i++) {
197 <      int iglob = AtomLocalToGlobal[i];
198 <      for (int j = 0; j < nLocal_; j++) {
199 <        int jglob = AtomLocalToGlobal[j];        
200 <        if (excludes.hasPair(iglob, jglob))
201 <          skipsForLocalAtom[i].push_back(j);      
202 <      }      
203 <    }
302 >    createGtypeCutoffMap();
303  
304 <    toposForLocalAtom.clear();
305 <    toposForLocalAtom.reserve(nLocal_);
306 <    for (int i = 0; i < nLocal_; i++) {
307 <      int iglob = AtomLocalToGlobal[i];
308 <      int nTopos = 0;
309 <      for (int j = 0; j < nLocal_; j++) {
310 <        int jglob = AtomLocalToGlobal[j];        
311 <        if (oneTwo.hasPair(iglob, jglob)) {
312 <          toposForLocalAtom[i].push_back(j);
313 <          topoDistLocal[i][nTopos] = 1;
314 <          nTopos++;
304 >  }
305 >  
306 >  void ForceMatrixDecomposition::createGtypeCutoffMap() {
307 >    
308 >    RealType tol = 1e-6;
309 >    largestRcut_ = 0.0;
310 >    RealType rc;
311 >    int atid;
312 >    set<AtomType*> atypes = info_->getSimulatedAtomTypes();
313 >    
314 >    map<int, RealType> atypeCutoff;
315 >      
316 >    for (set<AtomType*>::iterator at = atypes.begin();
317 >         at != atypes.end(); ++at){
318 >      atid = (*at)->getIdent();
319 >      if (userChoseCutoff_)
320 >        atypeCutoff[atid] = userCutoff_;
321 >      else
322 >        atypeCutoff[atid] = interactionMan_->getSuggestedCutoffRadius(*at);
323 >    }
324 >    
325 >    vector<RealType> gTypeCutoffs;
326 >    // first we do a single loop over the cutoff groups to find the
327 >    // largest cutoff for any atypes present in this group.
328 > #ifdef IS_MPI
329 >    vector<RealType> groupCutoffRow(nGroupsInRow_, 0.0);
330 >    groupRowToGtype.resize(nGroupsInRow_);
331 >    for (int cg1 = 0; cg1 < nGroupsInRow_; cg1++) {
332 >      vector<int> atomListRow = getAtomsInGroupRow(cg1);
333 >      for (vector<int>::iterator ia = atomListRow.begin();
334 >           ia != atomListRow.end(); ++ia) {            
335 >        int atom1 = (*ia);
336 >        atid = identsRow[atom1];
337 >        if (atypeCutoff[atid] > groupCutoffRow[cg1]) {
338 >          groupCutoffRow[cg1] = atypeCutoff[atid];
339          }
340 <        if (oneThree.hasPair(iglob, jglob)) {
341 <          toposForLocalAtom[i].push_back(j);
342 <          topoDistLocal[i][nTopos] = 2;
343 <          nTopos++;
344 <        }
345 <        if (oneFour.hasPair(iglob, jglob)) {
346 <          toposForLocalAtom[i].push_back(j);
347 <          topoDistLocal[i][nTopos] = 3;
348 <          nTopos++;
340 >      }
341 >
342 >      bool gTypeFound = false;
343 >      for (int gt = 0; gt < gTypeCutoffs.size(); gt++) {
344 >        if (abs(groupCutoffRow[cg1] - gTypeCutoffs[gt]) < tol) {
345 >          groupRowToGtype[cg1] = gt;
346 >          gTypeFound = true;
347 >        }
348 >      }
349 >      if (!gTypeFound) {
350 >        gTypeCutoffs.push_back( groupCutoffRow[cg1] );
351 >        groupRowToGtype[cg1] = gTypeCutoffs.size() - 1;
352 >      }
353 >      
354 >    }
355 >    vector<RealType> groupCutoffCol(nGroupsInCol_, 0.0);
356 >    groupColToGtype.resize(nGroupsInCol_);
357 >    for (int cg2 = 0; cg2 < nGroupsInCol_; cg2++) {
358 >      vector<int> atomListCol = getAtomsInGroupColumn(cg2);
359 >      for (vector<int>::iterator jb = atomListCol.begin();
360 >           jb != atomListCol.end(); ++jb) {            
361 >        int atom2 = (*jb);
362 >        atid = identsCol[atom2];
363 >        if (atypeCutoff[atid] > groupCutoffCol[cg2]) {
364 >          groupCutoffCol[cg2] = atypeCutoff[atid];
365          }
366 +      }
367 +      bool gTypeFound = false;
368 +      for (int gt = 0; gt < gTypeCutoffs.size(); gt++) {
369 +        if (abs(groupCutoffCol[cg2] - gTypeCutoffs[gt]) < tol) {
370 +          groupColToGtype[cg2] = gt;
371 +          gTypeFound = true;
372 +        }
373 +      }
374 +      if (!gTypeFound) {
375 +        gTypeCutoffs.push_back( groupCutoffCol[cg2] );
376 +        groupColToGtype[cg2] = gTypeCutoffs.size() - 1;
377 +      }
378 +    }
379 + #else
380 +
381 +    vector<RealType> groupCutoff(nGroups_, 0.0);
382 +    groupToGtype.resize(nGroups_);
383 +    for (int cg1 = 0; cg1 < nGroups_; cg1++) {
384 +      groupCutoff[cg1] = 0.0;
385 +      vector<int> atomList = getAtomsInGroupRow(cg1);
386 +      for (vector<int>::iterator ia = atomList.begin();
387 +           ia != atomList.end(); ++ia) {            
388 +        int atom1 = (*ia);
389 +        atid = idents[atom1];
390 +        if (atypeCutoff[atid] > groupCutoff[cg1])
391 +          groupCutoff[cg1] = atypeCutoff[atid];
392 +      }
393 +      
394 +      bool gTypeFound = false;
395 +      for (int gt = 0; gt < gTypeCutoffs.size(); gt++) {
396 +        if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) {
397 +          groupToGtype[cg1] = gt;
398 +          gTypeFound = true;
399 +        }
400 +      }
401 +      if (!gTypeFound) {      
402 +        gTypeCutoffs.push_back( groupCutoff[cg1] );
403 +        groupToGtype[cg1] = gTypeCutoffs.size() - 1;
404        }      
405      }
406 + #endif
407 +
408 +    // Now we find the maximum group cutoff value present in the simulation
409 +
410 +    RealType groupMax = *max_element(gTypeCutoffs.begin(),
411 +                                     gTypeCutoffs.end());
412 +
413 + #ifdef IS_MPI
414 +    MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE,
415 +                              MPI::MAX);
416 + #endif
417 +    
418 +    RealType tradRcut = groupMax;
419 +
420 +    for (int i = 0; i < gTypeCutoffs.size();  i++) {
421 +      for (int j = 0; j < gTypeCutoffs.size();  j++) {      
422 +        RealType thisRcut;
423 +        switch(cutoffPolicy_) {
424 +        case TRADITIONAL:
425 +          thisRcut = tradRcut;
426 +          break;
427 +        case MIX:
428 +          thisRcut = 0.5 * (gTypeCutoffs[i] + gTypeCutoffs[j]);
429 +          break;
430 +        case MAX:
431 +          thisRcut = max(gTypeCutoffs[i], gTypeCutoffs[j]);
432 +          break;
433 +        default:
434 +          sprintf(painCave.errMsg,
435 +                  "ForceMatrixDecomposition::createGtypeCutoffMap "
436 +                  "hit an unknown cutoff policy!\n");
437 +          painCave.severity = OPENMD_ERROR;
438 +          painCave.isFatal = 1;
439 +          simError();
440 +          break;
441 +        }
442 +
443 +        pair<int,int> key = make_pair(i,j);
444 +        gTypeCutoffMap[key].first = thisRcut;
445 +        if (thisRcut > largestRcut_) largestRcut_ = thisRcut;
446 +        gTypeCutoffMap[key].second = thisRcut*thisRcut;
447 +        gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2);
448 +        // sanity check
449 +        
450 +        if (userChoseCutoff_) {
451 +          if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) {
452 +            sprintf(painCave.errMsg,
453 +                    "ForceMatrixDecomposition::createGtypeCutoffMap "
454 +                    "user-specified rCut (%lf) does not match computed group Cutoff\n", userCutoff_);
455 +            painCave.severity = OPENMD_ERROR;
456 +            painCave.isFatal = 1;
457 +            simError();            
458 +          }
459 +        }
460 +      }
461 +    }
462    }
230  
231  void ForceMatrixDecomposition::zeroWorkArrays() {
463  
464 <    for (int j = 0; j < N_INTERACTION_FAMILIES; j++) {
465 <      longRangePot_[j] = 0.0;
464 >
465 >  groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) {
466 >    int i, j;  
467 > #ifdef IS_MPI
468 >    i = groupRowToGtype[cg1];
469 >    j = groupColToGtype[cg2];
470 > #else
471 >    i = groupToGtype[cg1];
472 >    j = groupToGtype[cg2];
473 > #endif    
474 >    return gTypeCutoffMap[make_pair(i,j)];
475 >  }
476 >
477 >  int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) {
478 >    for (int j = 0; j < toposForAtom[atom1].size(); j++) {
479 >      if (toposForAtom[atom1][j] == atom2)
480 >        return topoDist[atom1][j];
481      }
482 +    return 0;
483 +  }
484  
485 +  void ForceMatrixDecomposition::zeroWorkArrays() {
486 +    pairwisePot = 0.0;
487 +    embeddingPot = 0.0;
488 +
489   #ifdef IS_MPI
490      if (storageLayout_ & DataStorage::dslForce) {
491        fill(atomRowData.force.begin(), atomRowData.force.end(), V3Zero);
# Line 249 | Line 501 | namespace OpenMD {
501           Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
502  
503      fill(pot_col.begin(), pot_col.end(),
504 <         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
253 <    
254 <    pot_local = Vector<RealType, N_INTERACTION_FAMILIES>(0.0);
504 >         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));  
505  
506      if (storageLayout_ & DataStorage::dslParticlePot) {    
507 <      fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0);
508 <      fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), 0.0);
507 >      fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(),
508 >           0.0);
509 >      fill(atomColData.particlePot.begin(), atomColData.particlePot.end(),
510 >           0.0);
511      }
512  
513      if (storageLayout_ & DataStorage::dslDensity) {      
# Line 264 | Line 516 | namespace OpenMD {
516      }
517  
518      if (storageLayout_ & DataStorage::dslFunctional) {  
519 <      fill(atomRowData.functional.begin(), atomRowData.functional.end(), 0.0);
520 <      fill(atomColData.functional.begin(), atomColData.functional.end(), 0.0);
519 >      fill(atomRowData.functional.begin(), atomRowData.functional.end(),
520 >           0.0);
521 >      fill(atomColData.functional.begin(), atomColData.functional.end(),
522 >           0.0);
523      }
524  
525      if (storageLayout_ & DataStorage::dslFunctionalDerivative) {      
# Line 275 | Line 529 | namespace OpenMD {
529             atomColData.functionalDerivative.end(), 0.0);
530      }
531  
532 < #else
533 <    
532 >    if (storageLayout_ & DataStorage::dslSkippedCharge) {      
533 >      fill(atomRowData.skippedCharge.begin(),
534 >           atomRowData.skippedCharge.end(), 0.0);
535 >      fill(atomColData.skippedCharge.begin(),
536 >           atomColData.skippedCharge.end(), 0.0);
537 >    }
538 >
539 >    if (storageLayout_ & DataStorage::dslFlucQForce) {      
540 >      fill(atomRowData.flucQFrc.begin(),
541 >           atomRowData.flucQFrc.end(), 0.0);
542 >      fill(atomColData.flucQFrc.begin(),
543 >           atomColData.flucQFrc.end(), 0.0);
544 >    }
545 >
546 >    if (storageLayout_ & DataStorage::dslElectricField) {    
547 >      fill(atomRowData.electricField.begin(),
548 >           atomRowData.electricField.end(), V3Zero);
549 >      fill(atomColData.electricField.begin(),
550 >           atomColData.electricField.end(), V3Zero);
551 >    }
552 >
553 >    if (storageLayout_ & DataStorage::dslFlucQForce) {    
554 >      fill(atomRowData.flucQFrc.begin(), atomRowData.flucQFrc.end(),
555 >           0.0);
556 >      fill(atomColData.flucQFrc.begin(), atomColData.flucQFrc.end(),
557 >           0.0);
558 >    }
559 >
560 > #endif
561 >    // even in parallel, we need to zero out the local arrays:
562 >
563      if (storageLayout_ & DataStorage::dslParticlePot) {      
564        fill(snap_->atomData.particlePot.begin(),
565             snap_->atomData.particlePot.end(), 0.0);
# Line 286 | Line 569 | namespace OpenMD {
569        fill(snap_->atomData.density.begin(),
570             snap_->atomData.density.end(), 0.0);
571      }
572 +
573      if (storageLayout_ & DataStorage::dslFunctional) {
574        fill(snap_->atomData.functional.begin(),
575             snap_->atomData.functional.end(), 0.0);
576      }
577 +
578      if (storageLayout_ & DataStorage::dslFunctionalDerivative) {      
579        fill(snap_->atomData.functionalDerivative.begin(),
580             snap_->atomData.functionalDerivative.end(), 0.0);
581      }
582 < #endif
583 <    
582 >
583 >    if (storageLayout_ & DataStorage::dslSkippedCharge) {      
584 >      fill(snap_->atomData.skippedCharge.begin(),
585 >           snap_->atomData.skippedCharge.end(), 0.0);
586 >    }
587 >
588 >    if (storageLayout_ & DataStorage::dslElectricField) {      
589 >      fill(snap_->atomData.electricField.begin(),
590 >           snap_->atomData.electricField.end(), V3Zero);
591 >    }
592    }
593  
594  
# Line 305 | Line 598 | namespace OpenMD {
598   #ifdef IS_MPI
599      
600      // gather up the atomic positions
601 <    AtomCommVectorRow->gather(snap_->atomData.position,
601 >    AtomPlanVectorRow->gather(snap_->atomData.position,
602                                atomRowData.position);
603 <    AtomCommVectorColumn->gather(snap_->atomData.position,
603 >    AtomPlanVectorColumn->gather(snap_->atomData.position,
604                                   atomColData.position);
605      
606      // gather up the cutoff group positions
607 <    cgCommVectorRow->gather(snap_->cgData.position,
607 >
608 >    cgPlanVectorRow->gather(snap_->cgData.position,
609                              cgRowData.position);
610 <    cgCommVectorColumn->gather(snap_->cgData.position,
610 >
611 >    cgPlanVectorColumn->gather(snap_->cgData.position,
612                                 cgColData.position);
613 +
614 +
615 +
616 +    if (needVelocities_) {
617 +      // gather up the atomic velocities
618 +      AtomPlanVectorColumn->gather(snap_->atomData.velocity,
619 +                                   atomColData.velocity);
620 +      
621 +      cgPlanVectorColumn->gather(snap_->cgData.velocity,
622 +                                 cgColData.velocity);
623 +    }
624 +
625      
626      // if needed, gather the atomic rotation matrices
627      if (storageLayout_ & DataStorage::dslAmat) {
628 <      AtomCommMatrixRow->gather(snap_->atomData.aMat,
628 >      AtomPlanMatrixRow->gather(snap_->atomData.aMat,
629                                  atomRowData.aMat);
630 <      AtomCommMatrixColumn->gather(snap_->atomData.aMat,
630 >      AtomPlanMatrixColumn->gather(snap_->atomData.aMat,
631                                     atomColData.aMat);
632      }
633      
634      // if needed, gather the atomic eletrostatic frames
635      if (storageLayout_ & DataStorage::dslElectroFrame) {
636 <      AtomCommMatrixRow->gather(snap_->atomData.electroFrame,
636 >      AtomPlanMatrixRow->gather(snap_->atomData.electroFrame,
637                                  atomRowData.electroFrame);
638 <      AtomCommMatrixColumn->gather(snap_->atomData.electroFrame,
638 >      AtomPlanMatrixColumn->gather(snap_->atomData.electroFrame,
639                                     atomColData.electroFrame);
640      }
641 +
642 +    // if needed, gather the atomic fluctuating charge values
643 +    if (storageLayout_ & DataStorage::dslFlucQPosition) {
644 +      AtomPlanRealRow->gather(snap_->atomData.flucQPos,
645 +                              atomRowData.flucQPos);
646 +      AtomPlanRealColumn->gather(snap_->atomData.flucQPos,
647 +                                 atomColData.flucQPos);
648 +    }
649 +
650   #endif      
651    }
652    
# Line 344 | Line 660 | namespace OpenMD {
660      
661      if (storageLayout_ & DataStorage::dslDensity) {
662        
663 <      AtomCommRealRow->scatter(atomRowData.density,
663 >      AtomPlanRealRow->scatter(atomRowData.density,
664                                 snap_->atomData.density);
665        
666        int n = snap_->atomData.density.size();
667        vector<RealType> rho_tmp(n, 0.0);
668 <      AtomCommRealColumn->scatter(atomColData.density, rho_tmp);
668 >      AtomPlanRealColumn->scatter(atomColData.density, rho_tmp);
669        for (int i = 0; i < n; i++)
670          snap_->atomData.density[i] += rho_tmp[i];
671      }
672 +
673 +    if (storageLayout_ & DataStorage::dslElectricField) {
674 +      
675 +      AtomPlanVectorRow->scatter(atomRowData.electricField,
676 +                                 snap_->atomData.electricField);
677 +      
678 +      int n = snap_->atomData.electricField.size();
679 +      vector<Vector3d> field_tmp(n, V3Zero);
680 +      AtomPlanVectorColumn->scatter(atomColData.electricField, field_tmp);
681 +      for (int i = 0; i < n; i++)
682 +        snap_->atomData.electricField[i] += field_tmp[i];
683 +    }
684   #endif
685    }
686  
# Line 365 | Line 693 | namespace OpenMD {
693      storageLayout_ = sman_->getStorageLayout();
694   #ifdef IS_MPI
695      if (storageLayout_ & DataStorage::dslFunctional) {
696 <      AtomCommRealRow->gather(snap_->atomData.functional,
696 >      AtomPlanRealRow->gather(snap_->atomData.functional,
697                                atomRowData.functional);
698 <      AtomCommRealColumn->gather(snap_->atomData.functional,
698 >      AtomPlanRealColumn->gather(snap_->atomData.functional,
699                                   atomColData.functional);
700      }
701      
702      if (storageLayout_ & DataStorage::dslFunctionalDerivative) {
703 <      AtomCommRealRow->gather(snap_->atomData.functionalDerivative,
703 >      AtomPlanRealRow->gather(snap_->atomData.functionalDerivative,
704                                atomRowData.functionalDerivative);
705 <      AtomCommRealColumn->gather(snap_->atomData.functionalDerivative,
705 >      AtomPlanRealColumn->gather(snap_->atomData.functionalDerivative,
706                                   atomColData.functionalDerivative);
707      }
708   #endif
# Line 388 | Line 716 | namespace OpenMD {
716      int n = snap_->atomData.force.size();
717      vector<Vector3d> frc_tmp(n, V3Zero);
718      
719 <    AtomCommVectorRow->scatter(atomRowData.force, frc_tmp);
719 >    AtomPlanVectorRow->scatter(atomRowData.force, frc_tmp);
720      for (int i = 0; i < n; i++) {
721        snap_->atomData.force[i] += frc_tmp[i];
722        frc_tmp[i] = 0.0;
723      }
724      
725 <    AtomCommVectorColumn->scatter(atomColData.force, frc_tmp);
726 <    for (int i = 0; i < n; i++)
725 >    AtomPlanVectorColumn->scatter(atomColData.force, frc_tmp);
726 >    for (int i = 0; i < n; i++) {
727        snap_->atomData.force[i] += frc_tmp[i];
728 <    
729 <    
728 >    }
729 >        
730      if (storageLayout_ & DataStorage::dslTorque) {
731  
732 <      int nt = snap_->atomData.force.size();
732 >      int nt = snap_->atomData.torque.size();
733        vector<Vector3d> trq_tmp(nt, V3Zero);
734  
735 <      AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp);
736 <      for (int i = 0; i < n; i++) {
735 >      AtomPlanVectorRow->scatter(atomRowData.torque, trq_tmp);
736 >      for (int i = 0; i < nt; i++) {
737          snap_->atomData.torque[i] += trq_tmp[i];
738          trq_tmp[i] = 0.0;
739        }
740        
741 <      AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp);
742 <      for (int i = 0; i < n; i++)
741 >      AtomPlanVectorColumn->scatter(atomColData.torque, trq_tmp);
742 >      for (int i = 0; i < nt; i++)
743          snap_->atomData.torque[i] += trq_tmp[i];
744      }
745 +
746 +    if (storageLayout_ & DataStorage::dslSkippedCharge) {
747 +
748 +      int ns = snap_->atomData.skippedCharge.size();
749 +      vector<RealType> skch_tmp(ns, 0.0);
750 +
751 +      AtomPlanRealRow->scatter(atomRowData.skippedCharge, skch_tmp);
752 +      for (int i = 0; i < ns; i++) {
753 +        snap_->atomData.skippedCharge[i] += skch_tmp[i];
754 +        skch_tmp[i] = 0.0;
755 +      }
756 +      
757 +      AtomPlanRealColumn->scatter(atomColData.skippedCharge, skch_tmp);
758 +      for (int i = 0; i < ns; i++)
759 +        snap_->atomData.skippedCharge[i] += skch_tmp[i];
760 +            
761 +    }
762      
763 +    if (storageLayout_ & DataStorage::dslFlucQForce) {
764 +
765 +      int nq = snap_->atomData.flucQFrc.size();
766 +      vector<RealType> fqfrc_tmp(nq, 0.0);
767 +
768 +      AtomPlanRealRow->scatter(atomRowData.flucQFrc, fqfrc_tmp);
769 +      for (int i = 0; i < nq; i++) {
770 +        snap_->atomData.flucQFrc[i] += fqfrc_tmp[i];
771 +        fqfrc_tmp[i] = 0.0;
772 +      }
773 +      
774 +      AtomPlanRealColumn->scatter(atomColData.flucQFrc, fqfrc_tmp);
775 +      for (int i = 0; i < nq; i++)
776 +        snap_->atomData.flucQFrc[i] += fqfrc_tmp[i];
777 +            
778 +    }
779 +
780      nLocal_ = snap_->getNumberOfAtoms();
781  
782      vector<potVec> pot_temp(nLocal_,
# Line 422 | Line 784 | namespace OpenMD {
784  
785      // scatter/gather pot_row into the members of my column
786            
787 <    AtomCommPotRow->scatter(pot_row, pot_temp);
787 >    AtomPlanPotRow->scatter(pot_row, pot_temp);
788  
789      for (int ii = 0;  ii < pot_temp.size(); ii++ )
790 <      pot_local += pot_temp[ii];
791 <    
790 >      pairwisePot += pot_temp[ii];
791 >        
792 >    if (storageLayout_ & DataStorage::dslParticlePot) {
793 >      // This is the pairwise contribution to the particle pot.  The
794 >      // embedding contribution is added in each of the low level
795 >      // non-bonded routines.  In single processor, this is done in
796 >      // unpackInteractionData, not in collectData.
797 >      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
798 >        for (int i = 0; i < nLocal_; i++) {
799 >          // factor of two is because the total potential terms are divided
800 >          // by 2 in parallel due to row/ column scatter      
801 >          snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii);
802 >        }
803 >      }
804 >    }
805 >
806      fill(pot_temp.begin(), pot_temp.end(),
807           Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
808        
809 <    AtomCommPotColumn->scatter(pot_col, pot_temp);    
809 >    AtomPlanPotColumn->scatter(pot_col, pot_temp);    
810      
811      for (int ii = 0;  ii < pot_temp.size(); ii++ )
812 <      pot_local += pot_temp[ii];
812 >      pairwisePot += pot_temp[ii];    
813 >
814 >    if (storageLayout_ & DataStorage::dslParticlePot) {
815 >      // This is the pairwise contribution to the particle pot.  The
816 >      // embedding contribution is added in each of the low level
817 >      // non-bonded routines.  In single processor, this is done in
818 >      // unpackInteractionData, not in collectData.
819 >      for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
820 >        for (int i = 0; i < nLocal_; i++) {
821 >          // factor of two is because the total potential terms are divided
822 >          // by 2 in parallel due to row/ column scatter      
823 >          snap_->atomData.particlePot[i] += 2.0 * pot_temp[i](ii);
824 >        }
825 >      }
826 >    }
827      
828 +    if (storageLayout_ & DataStorage::dslParticlePot) {
829 +      int npp = snap_->atomData.particlePot.size();
830 +      vector<RealType> ppot_temp(npp, 0.0);
831 +
832 +      // This is the direct or embedding contribution to the particle
833 +      // pot.
834 +      
835 +      AtomPlanRealRow->scatter(atomRowData.particlePot, ppot_temp);
836 +      for (int i = 0; i < npp; i++) {
837 +        snap_->atomData.particlePot[i] += ppot_temp[i];
838 +      }
839 +
840 +      fill(ppot_temp.begin(), ppot_temp.end(), 0.0);
841 +      
842 +      AtomPlanRealColumn->scatter(atomColData.particlePot, ppot_temp);
843 +      for (int i = 0; i < npp; i++) {
844 +        snap_->atomData.particlePot[i] += ppot_temp[i];
845 +      }
846 +    }
847 +
848 +    for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
849 +      RealType ploc1 = pairwisePot[ii];
850 +      RealType ploc2 = 0.0;
851 +      MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
852 +      pairwisePot[ii] = ploc2;
853 +    }
854 +
855 +    for (int ii = 0; ii < N_INTERACTION_FAMILIES; ii++) {
856 +      RealType ploc1 = embeddingPot[ii];
857 +      RealType ploc2 = 0.0;
858 +      MPI::COMM_WORLD.Allreduce(&ploc1, &ploc2, 1, MPI::REALTYPE, MPI::SUM);
859 +      embeddingPot[ii] = ploc2;
860 +    }
861 +    
862 +    // Here be dragons.
863 +    MPI::Intracomm col = colComm.getComm();
864 +
865 +    col.Allreduce(MPI::IN_PLACE,
866 +                  &snap_->frameData.conductiveHeatFlux[0], 3,
867 +                  MPI::REALTYPE, MPI::SUM);
868 +
869 +
870   #endif
871 +
872    }
873  
874    int ForceMatrixDecomposition::getNAtomsInRow() {  
# Line 478 | Line 911 | namespace OpenMD {
911      return d;    
912    }
913  
914 +  Vector3d ForceMatrixDecomposition::getGroupVelocityColumn(int cg2){
915 + #ifdef IS_MPI
916 +    return cgColData.velocity[cg2];
917 + #else
918 +    return snap_->cgData.velocity[cg2];
919 + #endif
920 +  }
921  
922 +  Vector3d ForceMatrixDecomposition::getAtomVelocityColumn(int atom2){
923 + #ifdef IS_MPI
924 +    return atomColData.velocity[atom2];
925 + #else
926 +    return snap_->atomData.velocity[atom2];
927 + #endif
928 +  }
929 +
930 +
931    Vector3d ForceMatrixDecomposition::getAtomToGroupVectorRow(int atom1, int cg1){
932  
933      Vector3d d;
# Line 510 | Line 959 | namespace OpenMD {
959   #ifdef IS_MPI
960      return massFactorsRow[atom1];
961   #else
962 <    return massFactorsLocal[atom1];
962 >    return massFactors[atom1];
963   #endif
964    }
965  
# Line 518 | Line 967 | namespace OpenMD {
967   #ifdef IS_MPI
968      return massFactorsCol[atom2];
969   #else
970 <    return massFactorsLocal[atom2];
970 >    return massFactors[atom2];
971   #endif
972  
973    }
# Line 536 | Line 985 | namespace OpenMD {
985      return d;    
986    }
987  
988 <  vector<int> ForceMatrixDecomposition::getSkipsForRowAtom(int atom1) {
989 < #ifdef IS_MPI
541 <    return skipsForRowAtom[atom1];
542 < #else
543 <    return skipsForLocalAtom[atom1];
544 < #endif
988 >  vector<int> ForceMatrixDecomposition::getExcludesForAtom(int atom1) {
989 >    return excludesForAtom[atom1];
990    }
991  
992    /**
993 <   * There are a number of reasons to skip a pair or a
549 <   * particle. Mostly we do this to exclude atoms who are involved in
550 <   * short range interactions (bonds, bends, torsions), but we also
551 <   * need to exclude some overcounted interactions that result from
993 >   * We need to exclude some overcounted interactions that result from
994     * the parallel decomposition.
995     */
996    bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) {
997      int unique_id_1, unique_id_2;
998 <
998 >        
999   #ifdef IS_MPI
1000      // in MPI, we have to look up the unique IDs for each atom
1001      unique_id_1 = AtomRowToGlobal[atom1];
1002      unique_id_2 = AtomColToGlobal[atom2];
1003 + #else
1004 +    unique_id_1 = AtomLocalToGlobal[atom1];
1005 +    unique_id_2 = AtomLocalToGlobal[atom2];
1006 + #endif  
1007  
562    // this situation should only arise in MPI simulations
1008      if (unique_id_1 == unique_id_2) return true;
1009 <    
1009 >
1010 > #ifdef IS_MPI
1011      // this prevents us from doing the pair on multiple processors
1012      if (unique_id_1 < unique_id_2) {
1013        if ((unique_id_1 + unique_id_2) % 2 == 0) return true;
1014      } else {
1015 <      if ((unique_id_1 + unique_id_2) % 2 == 1) return true;
1015 >      if ((unique_id_1 + unique_id_2) % 2 == 1) return true;
1016      }
571 #else
572    // in the normal loop, the atom numbers are unique
573    unique_id_1 = atom1;
574    unique_id_2 = atom2;
1017   #endif
1018      
1019 < #ifdef IS_MPI
578 <    for (vector<int>::iterator i = skipsForRowAtom[atom1].begin();
579 <         i != skipsForRowAtom[atom1].end(); ++i) {
580 <      if ( (*i) == unique_id_2 ) return true;
581 <    }    
582 < #else
583 <    for (vector<int>::iterator i = skipsForLocalAtom[atom1].begin();
584 <         i != skipsForLocalAtom[atom1].end(); ++i) {
585 <      if ( (*i) == unique_id_2 ) return true;
586 <    }    
587 < #endif
1019 >    return false;
1020    }
1021  
1022 <  int ForceMatrixDecomposition::getTopoDistance(int atom1, int atom2) {
1023 <    
1024 < #ifdef IS_MPI
1025 <    for (int i = 0; i < toposForRowAtom[atom1].size(); i++) {
1026 <      if ( toposForRowAtom[atom1][i] == atom2 ) return topoDistRow[atom1][i];
1022 >  /**
1023 >   * We need to handle the interactions for atoms who are involved in
1024 >   * the same rigid body as well as some short range interactions
1025 >   * (bonds, bends, torsions) differently from other interactions.
1026 >   * We'll still visit the pairwise routines, but with a flag that
1027 >   * tells those routines to exclude the pair from direct long range
1028 >   * interactions.  Some indirect interactions (notably reaction
1029 >   * field) must still be handled for these pairs.
1030 >   */
1031 >  bool ForceMatrixDecomposition::excludeAtomPair(int atom1, int atom2) {
1032 >
1033 >    // excludesForAtom was constructed to use row/column indices in the MPI
1034 >    // version, and to use local IDs in the non-MPI version:
1035 >    
1036 >    for (vector<int>::iterator i = excludesForAtom[atom1].begin();
1037 >         i != excludesForAtom[atom1].end(); ++i) {
1038 >      if ( (*i) == atom2 ) return true;
1039      }
596 #else
597    for (int i = 0; i < toposForLocalAtom[atom1].size(); i++) {
598      if ( toposForLocalAtom[atom1][i] == atom2 ) return topoDistLocal[atom1][i];
599    }
600 #endif
1040  
1041 <    // zero is default for unconnected (i.e. normal) pair interactions
603 <    return 0;
1041 >    return false;
1042    }
1043  
1044 +
1045    void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){
1046   #ifdef IS_MPI
1047      atomRowData.force[atom1] += fg;
# Line 620 | Line 1059 | namespace OpenMD {
1059    }
1060  
1061      // filling interaction blocks with pointers
1062 <  InteractionData ForceMatrixDecomposition::fillInteractionData(int atom1, int atom2) {    
1063 <    InteractionData idat;
1062 >  void ForceMatrixDecomposition::fillInteractionData(InteractionData &idat,
1063 >                                                     int atom1, int atom2) {
1064  
1065 +    idat.excluded = excludeAtomPair(atom1, atom2);
1066 +  
1067   #ifdef IS_MPI
1068 +    idat.atypes = make_pair( atypesRow[atom1], atypesCol[atom2]);
1069 +    //idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
1070 +    //                         ff_->getAtomType(identsCol[atom2]) );
1071      
628    idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
629                             ff_->getAtomType(identsCol[atom2]) );
630
631    
1072      if (storageLayout_ & DataStorage::dslAmat) {
1073        idat.A1 = &(atomRowData.aMat[atom1]);
1074        idat.A2 = &(atomColData.aMat[atom2]);
# Line 664 | Line 1104 | namespace OpenMD {
1104        idat.particlePot2 = &(atomColData.particlePot[atom2]);
1105      }
1106  
1107 < #else
1107 >    if (storageLayout_ & DataStorage::dslSkippedCharge) {              
1108 >      idat.skippedCharge1 = &(atomRowData.skippedCharge[atom1]);
1109 >      idat.skippedCharge2 = &(atomColData.skippedCharge[atom2]);
1110 >    }
1111  
1112 <    idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]),
1113 <                             ff_->getAtomType(identsLocal[atom2]) );
1112 >    if (storageLayout_ & DataStorage::dslFlucQPosition) {              
1113 >      idat.flucQ1 = &(atomRowData.flucQPos[atom1]);
1114 >      idat.flucQ2 = &(atomColData.flucQPos[atom2]);
1115 >    }
1116  
1117 + #else
1118 +    
1119 +    idat.atypes = make_pair( atypesLocal[atom1], atypesLocal[atom2]);
1120 +
1121      if (storageLayout_ & DataStorage::dslAmat) {
1122        idat.A1 = &(snap_->atomData.aMat[atom1]);
1123        idat.A2 = &(snap_->atomData.aMat[atom2]);
# Line 684 | Line 1133 | namespace OpenMD {
1133        idat.t2 = &(snap_->atomData.torque[atom2]);
1134      }
1135  
1136 <    if (storageLayout_ & DataStorage::dslDensity) {
1136 >    if (storageLayout_ & DataStorage::dslDensity) {    
1137        idat.rho1 = &(snap_->atomData.density[atom1]);
1138        idat.rho2 = &(snap_->atomData.density[atom2]);
1139      }
# Line 704 | Line 1153 | namespace OpenMD {
1153        idat.particlePot2 = &(snap_->atomData.particlePot[atom2]);
1154      }
1155  
1156 +    if (storageLayout_ & DataStorage::dslSkippedCharge) {
1157 +      idat.skippedCharge1 = &(snap_->atomData.skippedCharge[atom1]);
1158 +      idat.skippedCharge2 = &(snap_->atomData.skippedCharge[atom2]);
1159 +    }
1160 +
1161 +    if (storageLayout_ & DataStorage::dslFlucQPosition) {              
1162 +      idat.flucQ1 = &(snap_->atomData.flucQPos[atom1]);
1163 +      idat.flucQ2 = &(snap_->atomData.flucQPos[atom2]);
1164 +    }
1165 +
1166   #endif
708    return idat;
1167    }
1168  
1169    
1170 <  void ForceMatrixDecomposition::unpackInteractionData(InteractionData idat, int atom1, int atom2) {    
1170 >  void ForceMatrixDecomposition::unpackInteractionData(InteractionData &idat, int atom1, int atom2) {    
1171   #ifdef IS_MPI
1172 <    pot_row[atom1] += 0.5 *  *(idat.pot);
1173 <    pot_col[atom2] += 0.5 *  *(idat.pot);
1172 >    pot_row[atom1] += RealType(0.5) *  *(idat.pot);
1173 >    pot_col[atom2] += RealType(0.5) *  *(idat.pot);
1174  
1175      atomRowData.force[atom1] += *(idat.f1);
1176      atomColData.force[atom2] -= *(idat.f1);
719 #else
720    longRangePot_ += *(idat.pot);
721    
722    snap_->atomData.force[atom1] += *(idat.f1);
723    snap_->atomData.force[atom2] -= *(idat.f1);
724 #endif
1177  
1178 <  }
1178 >    if (storageLayout_ & DataStorage::dslFlucQForce) {              
1179 >      atomRowData.flucQFrc[atom1] -= *(idat.dVdFQ1);
1180 >      atomColData.flucQFrc[atom2] -= *(idat.dVdFQ2);
1181 >    }
1182  
1183 +    if (storageLayout_ & DataStorage::dslElectricField) {              
1184 +      atomRowData.electricField[atom1] += *(idat.eField1);
1185 +      atomColData.electricField[atom2] += *(idat.eField2);
1186 +    }
1187  
1188 <  InteractionData ForceMatrixDecomposition::fillSkipData(int atom1, int atom2){
1188 > #else
1189 >    pairwisePot += *(idat.pot);
1190  
1191 <    InteractionData idat;
1192 < #ifdef IS_MPI
733 <    idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
734 <                             ff_->getAtomType(identsCol[atom2]) );
1191 >    snap_->atomData.force[atom1] += *(idat.f1);
1192 >    snap_->atomData.force[atom2] -= *(idat.f1);
1193  
1194 <    if (storageLayout_ & DataStorage::dslElectroFrame) {
1195 <      idat.eFrame1 = &(atomRowData.electroFrame[atom1]);
1196 <      idat.eFrame2 = &(atomColData.electroFrame[atom2]);
1194 >    if (idat.doParticlePot) {
1195 >      // This is the pairwise contribution to the particle pot.  The
1196 >      // embedding contribution is added in each of the low level
1197 >      // non-bonded routines.  In parallel, this calculation is done
1198 >      // in collectData, not in unpackInteractionData.
1199 >      snap_->atomData.particlePot[atom1] += *(idat.vpair) * *(idat.sw);
1200 >      snap_->atomData.particlePot[atom2] += *(idat.vpair) * *(idat.sw);
1201      }
1202 <    if (storageLayout_ & DataStorage::dslTorque) {
1203 <      idat.t1 = &(atomRowData.torque[atom1]);
1204 <      idat.t2 = &(atomColData.torque[atom2]);
1202 >    
1203 >    if (storageLayout_ & DataStorage::dslFlucQForce) {              
1204 >      snap_->atomData.flucQFrc[atom1] -= *(idat.dVdFQ1);
1205 >      snap_->atomData.flucQFrc[atom2] -= *(idat.dVdFQ2);
1206      }
744 #else
745    idat.atypes = make_pair( ff_->getAtomType(identsLocal[atom1]),
746                             ff_->getAtomType(identsLocal[atom2]) );
1207  
1208 <    if (storageLayout_ & DataStorage::dslElectroFrame) {
1209 <      idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]);
1210 <      idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]);
1208 >    if (storageLayout_ & DataStorage::dslElectricField) {              
1209 >      snap_->atomData.electricField[atom1] += *(idat.eField1);
1210 >      snap_->atomData.electricField[atom2] += *(idat.eField2);
1211      }
1212 <    if (storageLayout_ & DataStorage::dslTorque) {
1213 <      idat.t1 = &(snap_->atomData.torque[atom1]);
1214 <      idat.t2 = &(snap_->atomData.torque[atom2]);
755 <    }
756 < #endif    
1212 >
1213 > #endif
1214 >    
1215    }
1216  
1217    /*
# Line 765 | Line 1223 | namespace OpenMD {
1223    vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() {
1224        
1225      vector<pair<int, int> > neighborList;
1226 +    groupCutoffs cuts;
1227 +    bool doAllPairs = false;
1228 +
1229   #ifdef IS_MPI
1230      cellListRow_.clear();
1231      cellListCol_.clear();
# Line 772 | Line 1233 | namespace OpenMD {
1233      cellList_.clear();
1234   #endif
1235  
1236 <    // dangerous to not do error checking.
776 <    RealType rCut_;
777 <
778 <    RealType rList_ = (rCut_ + skinThickness_);
1236 >    RealType rList_ = (largestRcut_ + skinThickness_);
1237      RealType rl2 = rList_ * rList_;
1238      Snapshot* snap_ = sman_->getCurrentSnapshot();
1239      Mat3x3d Hmat = snap_->getHmat();
# Line 787 | Line 1245 | namespace OpenMD {
1245      nCells_.y() = (int) ( Hy.length() )/ rList_;
1246      nCells_.z() = (int) ( Hz.length() )/ rList_;
1247  
1248 +    // handle small boxes where the cell offsets can end up repeating cells
1249 +    
1250 +    if (nCells_.x() < 3) doAllPairs = true;
1251 +    if (nCells_.y() < 3) doAllPairs = true;
1252 +    if (nCells_.z() < 3) doAllPairs = true;
1253 +
1254      Mat3x3d invHmat = snap_->getInvHmat();
1255      Vector3d rs, scaled, dr;
1256      Vector3i whichCell;
1257      int cellIndex;
1258 +    int nCtot = nCells_.x() * nCells_.y() * nCells_.z();
1259 +
1260 + #ifdef IS_MPI
1261 +    cellListRow_.resize(nCtot);
1262 +    cellListCol_.resize(nCtot);
1263 + #else
1264 +    cellList_.resize(nCtot);
1265 + #endif
1266  
1267 +    if (!doAllPairs) {
1268   #ifdef IS_MPI
796    for (int i = 0; i < nGroupsInRow_; i++) {
797      rs = cgRowData.position[i];
798      // scaled positions relative to the box vectors
799      scaled = invHmat * rs;
800      // wrap the vector back into the unit box by subtracting integer box
801      // numbers
802      for (int j = 0; j < 3; j++)
803        scaled[j] -= roundMe(scaled[j]);
804    
805      // find xyz-indices of cell that cutoffGroup is in.
806      whichCell.x() = nCells_.x() * scaled.x();
807      whichCell.y() = nCells_.y() * scaled.y();
808      whichCell.z() = nCells_.z() * scaled.z();
1269  
1270 <      // find single index of this cell:
1271 <      cellIndex = Vlinear(whichCell, nCells_);
1272 <      // add this cutoff group to the list of groups in this cell;
1273 <      cellListRow_[cellIndex].push_back(i);
1274 <    }
1275 <
1276 <    for (int i = 0; i < nGroupsInCol_; i++) {
1277 <      rs = cgColData.position[i];
1278 <      // scaled positions relative to the box vectors
1279 <      scaled = invHmat * rs;
1280 <      // wrap the vector back into the unit box by subtracting integer box
1281 <      // numbers
1282 <      for (int j = 0; j < 3; j++)
1283 <        scaled[j] -= roundMe(scaled[j]);
1284 <
1285 <      // find xyz-indices of cell that cutoffGroup is in.
1286 <      whichCell.x() = nCells_.x() * scaled.x();
1287 <      whichCell.y() = nCells_.y() * scaled.y();
1288 <      whichCell.z() = nCells_.z() * scaled.z();
1289 <
1290 <      // find single index of this cell:
1291 <      cellIndex = Vlinear(whichCell, nCells_);
1292 <      // add this cutoff group to the list of groups in this cell;
1293 <      cellListCol_[cellIndex].push_back(i);
1294 <    }
1270 >      for (int i = 0; i < nGroupsInRow_; i++) {
1271 >        rs = cgRowData.position[i];
1272 >        
1273 >        // scaled positions relative to the box vectors
1274 >        scaled = invHmat * rs;
1275 >        
1276 >        // wrap the vector back into the unit box by subtracting integer box
1277 >        // numbers
1278 >        for (int j = 0; j < 3; j++) {
1279 >          scaled[j] -= roundMe(scaled[j]);
1280 >          scaled[j] += 0.5;
1281 >        }
1282 >        
1283 >        // find xyz-indices of cell that cutoffGroup is in.
1284 >        whichCell.x() = nCells_.x() * scaled.x();
1285 >        whichCell.y() = nCells_.y() * scaled.y();
1286 >        whichCell.z() = nCells_.z() * scaled.z();
1287 >        
1288 >        // find single index of this cell:
1289 >        cellIndex = Vlinear(whichCell, nCells_);
1290 >        
1291 >        // add this cutoff group to the list of groups in this cell;
1292 >        cellListRow_[cellIndex].push_back(i);
1293 >      }
1294 >      for (int i = 0; i < nGroupsInCol_; i++) {
1295 >        rs = cgColData.position[i];
1296 >        
1297 >        // scaled positions relative to the box vectors
1298 >        scaled = invHmat * rs;
1299 >        
1300 >        // wrap the vector back into the unit box by subtracting integer box
1301 >        // numbers
1302 >        for (int j = 0; j < 3; j++) {
1303 >          scaled[j] -= roundMe(scaled[j]);
1304 >          scaled[j] += 0.5;
1305 >        }
1306 >        
1307 >        // find xyz-indices of cell that cutoffGroup is in.
1308 >        whichCell.x() = nCells_.x() * scaled.x();
1309 >        whichCell.y() = nCells_.y() * scaled.y();
1310 >        whichCell.z() = nCells_.z() * scaled.z();
1311 >        
1312 >        // find single index of this cell:
1313 >        cellIndex = Vlinear(whichCell, nCells_);
1314 >        
1315 >        // add this cutoff group to the list of groups in this cell;
1316 >        cellListCol_[cellIndex].push_back(i);
1317 >      }
1318 >    
1319   #else
1320 <    for (int i = 0; i < nGroups_; i++) {
1321 <      rs = snap_->cgData.position[i];
1322 <      // scaled positions relative to the box vectors
1323 <      scaled = invHmat * rs;
1324 <      // wrap the vector back into the unit box by subtracting integer box
1325 <      // numbers
1326 <      for (int j = 0; j < 3; j++)
1327 <        scaled[j] -= roundMe(scaled[j]);
1320 >      for (int i = 0; i < nGroups_; i++) {
1321 >        rs = snap_->cgData.position[i];
1322 >        
1323 >        // scaled positions relative to the box vectors
1324 >        scaled = invHmat * rs;
1325 >        
1326 >        // wrap the vector back into the unit box by subtracting integer box
1327 >        // numbers
1328 >        for (int j = 0; j < 3; j++) {
1329 >          scaled[j] -= roundMe(scaled[j]);
1330 >          scaled[j] += 0.5;
1331 >        }
1332 >        
1333 >        // find xyz-indices of cell that cutoffGroup is in.
1334 >        whichCell.x() = nCells_.x() * scaled.x();
1335 >        whichCell.y() = nCells_.y() * scaled.y();
1336 >        whichCell.z() = nCells_.z() * scaled.z();
1337 >        
1338 >        // find single index of this cell:
1339 >        cellIndex = Vlinear(whichCell, nCells_);
1340 >        
1341 >        // add this cutoff group to the list of groups in this cell;
1342 >        cellList_[cellIndex].push_back(i);
1343 >      }
1344  
845      // find xyz-indices of cell that cutoffGroup is in.
846      whichCell.x() = nCells_.x() * scaled.x();
847      whichCell.y() = nCells_.y() * scaled.y();
848      whichCell.z() = nCells_.z() * scaled.z();
849
850      // find single index of this cell:
851      cellIndex = Vlinear(whichCell, nCells_);
852      // add this cutoff group to the list of groups in this cell;
853      cellList_[cellIndex].push_back(i);
854    }
1345   #endif
1346  
1347 <    for (int m1z = 0; m1z < nCells_.z(); m1z++) {
1348 <      for (int m1y = 0; m1y < nCells_.y(); m1y++) {
1349 <        for (int m1x = 0; m1x < nCells_.x(); m1x++) {
1350 <          Vector3i m1v(m1x, m1y, m1z);
1351 <          int m1 = Vlinear(m1v, nCells_);
862 <
863 <          for (vector<Vector3i>::iterator os = cellOffsets_.begin();
864 <               os != cellOffsets_.end(); ++os) {
1347 >      for (int m1z = 0; m1z < nCells_.z(); m1z++) {
1348 >        for (int m1y = 0; m1y < nCells_.y(); m1y++) {
1349 >          for (int m1x = 0; m1x < nCells_.x(); m1x++) {
1350 >            Vector3i m1v(m1x, m1y, m1z);
1351 >            int m1 = Vlinear(m1v, nCells_);
1352              
1353 <            Vector3i m2v = m1v + (*os);
1354 <            
1355 <            if (m2v.x() >= nCells_.x()) {
1356 <              m2v.x() = 0;          
1357 <            } else if (m2v.x() < 0) {
871 <              m2v.x() = nCells_.x() - 1;
872 <            }
873 <            
874 <            if (m2v.y() >= nCells_.y()) {
875 <              m2v.y() = 0;          
876 <            } else if (m2v.y() < 0) {
877 <              m2v.y() = nCells_.y() - 1;
878 <            }
879 <            
880 <            if (m2v.z() >= nCells_.z()) {
881 <              m2v.z() = 0;          
882 <            } else if (m2v.z() < 0) {
883 <              m2v.z() = nCells_.z() - 1;
884 <            }
885 <            
886 <            int m2 = Vlinear (m2v, nCells_);
1353 >            for (vector<Vector3i>::iterator os = cellOffsets_.begin();
1354 >                 os != cellOffsets_.end(); ++os) {
1355 >              
1356 >              Vector3i m2v = m1v + (*os);
1357 >            
1358  
1359 < #ifdef IS_MPI
1360 <            for (vector<int>::iterator j1 = cellListRow_[m1].begin();
1361 <                 j1 != cellListRow_[m1].end(); ++j1) {
1362 <              for (vector<int>::iterator j2 = cellListCol_[m2].begin();
1363 <                   j2 != cellListCol_[m2].end(); ++j2) {
1364 <                              
1365 <                // Always do this if we're in different cells or if
1366 <                // we're in the same cell and the global index of the
1367 <                // j2 cutoff group is less than the j1 cutoff group
1359 >              if (m2v.x() >= nCells_.x()) {
1360 >                m2v.x() = 0;          
1361 >              } else if (m2v.x() < 0) {
1362 >                m2v.x() = nCells_.x() - 1;
1363 >              }
1364 >              
1365 >              if (m2v.y() >= nCells_.y()) {
1366 >                m2v.y() = 0;          
1367 >              } else if (m2v.y() < 0) {
1368 >                m2v.y() = nCells_.y() - 1;
1369 >              }
1370 >              
1371 >              if (m2v.z() >= nCells_.z()) {
1372 >                m2v.z() = 0;          
1373 >              } else if (m2v.z() < 0) {
1374 >                m2v.z() = nCells_.z() - 1;
1375 >              }
1376  
1377 <                if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) {
1377 >              int m2 = Vlinear (m2v, nCells_);
1378 >              
1379 > #ifdef IS_MPI
1380 >              for (vector<int>::iterator j1 = cellListRow_[m1].begin();
1381 >                   j1 != cellListRow_[m1].end(); ++j1) {
1382 >                for (vector<int>::iterator j2 = cellListCol_[m2].begin();
1383 >                     j2 != cellListCol_[m2].end(); ++j2) {
1384 >                  
1385 >                  // In parallel, we need to visit *all* pairs of row
1386 >                  // & column indicies and will divide labor in the
1387 >                  // force evaluation later.
1388                    dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)];
1389                    snap_->wrapVector(dr);
1390 <                  if (dr.lengthSquare() < rl2) {
1390 >                  cuts = getGroupCutoffs( (*j1), (*j2) );
1391 >                  if (dr.lengthSquare() < cuts.third) {
1392                      neighborList.push_back(make_pair((*j1), (*j2)));
1393 <                  }
1393 >                  }                  
1394                  }
1395                }
906            }
1396   #else
1397 <            for (vector<int>::iterator j1 = cellList_[m1].begin();
1398 <                 j1 != cellList_[m1].end(); ++j1) {
1399 <              for (vector<int>::iterator j2 = cellList_[m2].begin();
1400 <                   j2 != cellList_[m2].end(); ++j2) {
1401 <                              
1402 <                // Always do this if we're in different cells or if
1403 <                // we're in the same cell and the global index of the
1404 <                // j2 cutoff group is less than the j1 cutoff group
1397 >              for (vector<int>::iterator j1 = cellList_[m1].begin();
1398 >                   j1 != cellList_[m1].end(); ++j1) {
1399 >                for (vector<int>::iterator j2 = cellList_[m2].begin();
1400 >                     j2 != cellList_[m2].end(); ++j2) {
1401 >    
1402 >                  // Always do this if we're in different cells or if
1403 >                  // we're in the same cell and the global index of
1404 >                  // the j2 cutoff group is greater than or equal to
1405 >                  // the j1 cutoff group.  Note that Rappaport's code
1406 >                  // has a "less than" conditional here, but that
1407 >                  // deals with atom-by-atom computation.  OpenMD
1408 >                  // allows atoms within a single cutoff group to
1409 >                  // interact with each other.
1410  
1411 <                if (m2 != m1 || (*j2) < (*j1)) {
1412 <                  dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)];
1413 <                  snap_->wrapVector(dr);
1414 <                  if (dr.lengthSquare() < rl2) {
1415 <                    neighborList.push_back(make_pair((*j1), (*j2)));
1411 >
1412 >
1413 >                  if (m2 != m1 || (*j2) >= (*j1) ) {
1414 >
1415 >                    dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)];
1416 >                    snap_->wrapVector(dr);
1417 >                    cuts = getGroupCutoffs( (*j1), (*j2) );
1418 >                    if (dr.lengthSquare() < cuts.third) {
1419 >                      neighborList.push_back(make_pair((*j1), (*j2)));
1420 >                    }
1421                    }
1422                  }
1423                }
925            }
1424   #endif
1425 +            }
1426            }
1427          }
1428        }
1429 +    } else {
1430 +      // branch to do all cutoff group pairs
1431 + #ifdef IS_MPI
1432 +      for (int j1 = 0; j1 < nGroupsInRow_; j1++) {
1433 +        for (int j2 = 0; j2 < nGroupsInCol_; j2++) {    
1434 +          dr = cgColData.position[j2] - cgRowData.position[j1];
1435 +          snap_->wrapVector(dr);
1436 +          cuts = getGroupCutoffs( j1, j2 );
1437 +          if (dr.lengthSquare() < cuts.third) {
1438 +            neighborList.push_back(make_pair(j1, j2));
1439 +          }
1440 +        }
1441 +      }      
1442 + #else
1443 +      // include all groups here.
1444 +      for (int j1 = 0; j1 < nGroups_; j1++) {
1445 +        // include self group interactions j2 == j1
1446 +        for (int j2 = j1; j2 < nGroups_; j2++) {
1447 +          dr = snap_->cgData.position[j2] - snap_->cgData.position[j1];
1448 +          snap_->wrapVector(dr);
1449 +          cuts = getGroupCutoffs( j1, j2 );
1450 +          if (dr.lengthSquare() < cuts.third) {
1451 +            neighborList.push_back(make_pair(j1, j2));
1452 +          }
1453 +        }    
1454 +      }
1455 + #endif
1456      }
1457 <
1457 >      
1458      // save the local cutoff group positions for the check that is
1459      // done on each loop:
1460      saved_CG_positions_.clear();
1461      for (int i = 0; i < nGroups_; i++)
1462        saved_CG_positions_.push_back(snap_->cgData.position[i]);
1463 <
1463 >    
1464      return neighborList;
1465    }
1466   } //end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines