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 1570 by gezelter, Thu May 26 21:56:04 2011 UTC vs.
Revision 1589 by gezelter, Sun Jul 10 16:05:34 2011 UTC

# Line 55 | Line 55 | namespace OpenMD {
55    void ForceMatrixDecomposition::distributeInitialData() {
56      snap_ = sman_->getCurrentSnapshot();
57      storageLayout_ = sman_->getStorageLayout();
58 +    ff_ = info_->getForceField();
59      nLocal_ = snap_->getNumberOfAtoms();
60 <    nGroups_ = snap_->getNumberOfCutoffGroups();
61 <
60 >    
61 >    nGroups_ = info_->getNLocalCutoffGroups();
62      // gather the information for atomtype IDs (atids):
63 <    vector<int> identsLocal = info_->getIdentArray();
63 >    idents = info_->getIdentArray();
64      AtomLocalToGlobal = info_->getGlobalAtomIndices();
65      cgLocalToGlobal = info_->getGlobalGroupIndices();
66      vector<int> globalGroupMembership = info_->getGlobalGroupMembership();
66    vector<RealType> massFactorsLocal = info_->getMassFactors();
67    PairList excludes = info_->getExcludedInteractions();
68    PairList oneTwo = info_->getOneTwoInteractions();
69    PairList oneThree = info_->getOneThreeInteractions();
70    PairList oneFour = info_->getOneFourInteractions();
71    vector<RealType> pot_local(N_INTERACTION_FAMILIES, 0.0);
67  
68 +    massFactors = info_->getMassFactors();
69 +
70 +    PairList* excludes = info_->getExcludedInteractions();
71 +    PairList* oneTwo = info_->getOneTwoInteractions();
72 +    PairList* oneThree = info_->getOneThreeInteractions();
73 +    PairList* oneFour = info_->getOneFourInteractions();
74 +
75   #ifdef IS_MPI
76  
77      AtomCommIntRow = new Communicator<Row,int>(nLocal_);
78      AtomCommRealRow = new Communicator<Row,RealType>(nLocal_);
79      AtomCommVectorRow = new Communicator<Row,Vector3d>(nLocal_);
80      AtomCommMatrixRow = new Communicator<Row,Mat3x3d>(nLocal_);
81 +    AtomCommPotRow = new Communicator<Row,potVec>(nLocal_);
82  
83      AtomCommIntColumn = new Communicator<Column,int>(nLocal_);
84      AtomCommRealColumn = new Communicator<Column,RealType>(nLocal_);
85      AtomCommVectorColumn = new Communicator<Column,Vector3d>(nLocal_);
86      AtomCommMatrixColumn = new Communicator<Column,Mat3x3d>(nLocal_);
87 +    AtomCommPotColumn = new Communicator<Column,potVec>(nLocal_);
88  
89      cgCommIntRow = new Communicator<Row,int>(nGroups_);
90      cgCommVectorRow = new Communicator<Row,Vector3d>(nGroups_);
# Line 101 | Line 105 | namespace OpenMD {
105      cgRowData.setStorageLayout(DataStorage::dslPosition);
106      cgColData.resize(nGroupsInCol_);
107      cgColData.setStorageLayout(DataStorage::dslPosition);
108 +        
109 +    identsRow.resize(nAtomsInRow_);
110 +    identsCol.resize(nAtomsInCol_);
111      
112 <    vector<vector<RealType> > pot_row(N_INTERACTION_FAMILIES,
113 <                                      vector<RealType> (nAtomsInRow_, 0.0));
107 <    vector<vector<RealType> > pot_col(N_INTERACTION_FAMILIES,
108 <                                      vector<RealType> (nAtomsInCol_, 0.0));
112 >    AtomCommIntRow->gather(idents, identsRow);
113 >    AtomCommIntColumn->gather(idents, identsCol);
114      
115 <    identsRow.reserve(nAtomsInRow_);
116 <    identsCol.reserve(nAtomsInCol_);
117 <    
118 <    AtomCommIntRow->gather(identsLocal, identsRow);
119 <    AtomCommIntColumn->gather(identsLocal, identsCol);
120 <    
115 >    // allocate memory for the parallel objects
116 >    AtomRowToGlobal.resize(nAtomsInRow_);
117 >    AtomColToGlobal.resize(nAtomsInCol_);
118 >    cgRowToGlobal.resize(nGroupsInRow_);
119 >    cgColToGlobal.resize(nGroupsInCol_);
120 >    massFactorsRow.resize(nAtomsInRow_);
121 >    massFactorsCol.resize(nAtomsInCol_);
122 >    pot_row.resize(nAtomsInRow_);
123 >    pot_col.resize(nAtomsInCol_);
124 >
125      AtomCommIntRow->gather(AtomLocalToGlobal, AtomRowToGlobal);
126      AtomCommIntColumn->gather(AtomLocalToGlobal, AtomColToGlobal);
127      
128      cgCommIntRow->gather(cgLocalToGlobal, cgRowToGlobal);
129      cgCommIntColumn->gather(cgLocalToGlobal, cgColToGlobal);
130  
131 <    AtomCommRealRow->gather(massFactorsLocal, massFactorsRow);
132 <    AtomCommRealColumn->gather(massFactorsLocal, massFactorsCol);
131 >    AtomCommRealRow->gather(massFactors, massFactorsRow);
132 >    AtomCommRealColumn->gather(massFactors, massFactorsCol);
133  
134      groupListRow_.clear();
135 <    groupListRow_.reserve(nGroupsInRow_);
135 >    groupListRow_.resize(nGroupsInRow_);
136      for (int i = 0; i < nGroupsInRow_; i++) {
137        int gid = cgRowToGlobal[i];
138        for (int j = 0; j < nAtomsInRow_; j++) {
# Line 134 | Line 143 | namespace OpenMD {
143      }
144  
145      groupListCol_.clear();
146 <    groupListCol_.reserve(nGroupsInCol_);
146 >    groupListCol_.resize(nGroupsInCol_);
147      for (int i = 0; i < nGroupsInCol_; i++) {
148        int gid = cgColToGlobal[i];
149        for (int j = 0; j < nAtomsInCol_; j++) {
# Line 144 | Line 153 | namespace OpenMD {
153        }      
154      }
155  
156 <    skipsForRowAtom.clear();
157 <    skipsForRowAtom.reserve(nAtomsInRow_);
156 >    excludesForAtom.clear();
157 >    excludesForAtom.resize(nAtomsInRow_);
158 >    toposForAtom.clear();
159 >    toposForAtom.resize(nAtomsInRow_);
160 >    topoDist.clear();
161 >    topoDist.resize(nAtomsInRow_);
162      for (int i = 0; i < nAtomsInRow_; i++) {
163 <      int iglob = AtomColToGlobal[i];
151 <      for (int j = 0; j < nAtomsInCol_; j++) {
152 <        int jglob = AtomRowToGlobal[j];        
153 <        if (excludes.hasPair(iglob, jglob))
154 <          skipsForRowAtom[i].push_back(j);      
155 <      }      
156 <    }
163 >      int iglob = AtomRowToGlobal[i];
164  
158    toposForRowAtom.clear();
159    toposForRowAtom.reserve(nAtomsInRow_);
160    for (int i = 0; i < nAtomsInRow_; i++) {
161      int iglob = AtomColToGlobal[i];
162      int nTopos = 0;
165        for (int j = 0; j < nAtomsInCol_; j++) {
166 <        int jglob = AtomRowToGlobal[j];        
167 <        if (oneTwo.hasPair(iglob, jglob)) {
168 <          toposForRowAtom[i].push_back(j);
169 <          topoDistRow[i][nTopos] = 1;
170 <          nTopos++;
166 >        int jglob = AtomColToGlobal[j];
167 >
168 >        if (excludes->hasPair(iglob, jglob))
169 >          excludesForAtom[i].push_back(j);      
170 >        
171 >        if (oneTwo->hasPair(iglob, jglob)) {
172 >          toposForAtom[i].push_back(j);
173 >          topoDist[i].push_back(1);
174 >        } else {
175 >          if (oneThree->hasPair(iglob, jglob)) {
176 >            toposForAtom[i].push_back(j);
177 >            topoDist[i].push_back(2);
178 >          } else {
179 >            if (oneFour->hasPair(iglob, jglob)) {
180 >              toposForAtom[i].push_back(j);
181 >              topoDist[i].push_back(3);
182 >            }
183 >          }
184          }
170        if (oneThree.hasPair(iglob, jglob)) {
171          toposForRowAtom[i].push_back(j);
172          topoDistRow[i][nTopos] = 2;
173          nTopos++;
174        }
175        if (oneFour.hasPair(iglob, jglob)) {
176          toposForRowAtom[i].push_back(j);
177          topoDistRow[i][nTopos] = 3;
178          nTopos++;
179        }
185        }      
186      }
187  
188   #endif
189  
190      groupList_.clear();
191 <    groupList_.reserve(nGroups_);
191 >    groupList_.resize(nGroups_);
192      for (int i = 0; i < nGroups_; i++) {
193        int gid = cgLocalToGlobal[i];
194        for (int j = 0; j < nLocal_; j++) {
195          int aid = AtomLocalToGlobal[j];
196 <        if (globalGroupMembership[aid] == gid)
196 >        if (globalGroupMembership[aid] == gid) {
197            groupList_[i].push_back(j);
198 +        }
199        }      
200      }
201  
202 <    skipsForLocalAtom.clear();
203 <    skipsForLocalAtom.reserve(nLocal_);
202 >    excludesForAtom.clear();
203 >    excludesForAtom.resize(nLocal_);
204 >    toposForAtom.clear();
205 >    toposForAtom.resize(nLocal_);
206 >    topoDist.clear();
207 >    topoDist.resize(nLocal_);
208  
209      for (int i = 0; i < nLocal_; i++) {
210        int iglob = AtomLocalToGlobal[i];
211 +
212        for (int j = 0; j < nLocal_; j++) {
213 <        int jglob = AtomLocalToGlobal[j];        
214 <        if (excludes.hasPair(iglob, jglob))
215 <          skipsForLocalAtom[i].push_back(j);      
213 >        int jglob = AtomLocalToGlobal[j];
214 >
215 >        if (excludes->hasPair(iglob, jglob))
216 >          excludesForAtom[i].push_back(j);              
217 >        
218 >        if (oneTwo->hasPair(iglob, jglob)) {
219 >          toposForAtom[i].push_back(j);
220 >          topoDist[i].push_back(1);
221 >        } else {
222 >          if (oneThree->hasPair(iglob, jglob)) {
223 >            toposForAtom[i].push_back(j);
224 >            topoDist[i].push_back(2);
225 >          } else {
226 >            if (oneFour->hasPair(iglob, jglob)) {
227 >              toposForAtom[i].push_back(j);
228 >              topoDist[i].push_back(3);
229 >            }
230 >          }
231 >        }
232        }      
233      }
234 +    
235 +    createGtypeCutoffMap();
236  
237 <    toposForLocalAtom.clear();
238 <    toposForLocalAtom.reserve(nLocal_);
239 <    for (int i = 0; i < nLocal_; i++) {
240 <      int iglob = AtomLocalToGlobal[i];
241 <      int nTopos = 0;
242 <      for (int j = 0; j < nLocal_; j++) {
243 <        int jglob = AtomLocalToGlobal[j];        
244 <        if (oneTwo.hasPair(iglob, jglob)) {
245 <          toposForLocalAtom[i].push_back(j);
246 <          topoDistLocal[i][nTopos] = 1;
247 <          nTopos++;
237 >  }
238 >  
239 >  void ForceMatrixDecomposition::createGtypeCutoffMap() {
240 >    
241 >    RealType tol = 1e-6;
242 >    RealType rc;
243 >    int atid;
244 >    set<AtomType*> atypes = info_->getSimulatedAtomTypes();
245 >    map<int, RealType> atypeCutoff;
246 >      
247 >    for (set<AtomType*>::iterator at = atypes.begin();
248 >         at != atypes.end(); ++at){
249 >      atid = (*at)->getIdent();
250 >      if (userChoseCutoff_)
251 >        atypeCutoff[atid] = userCutoff_;
252 >      else
253 >        atypeCutoff[atid] = interactionMan_->getSuggestedCutoffRadius(*at);
254 >    }
255 >
256 >    vector<RealType> gTypeCutoffs;
257 >    // first we do a single loop over the cutoff groups to find the
258 >    // largest cutoff for any atypes present in this group.
259 > #ifdef IS_MPI
260 >    vector<RealType> groupCutoffRow(nGroupsInRow_, 0.0);
261 >    groupRowToGtype.resize(nGroupsInRow_);
262 >    for (int cg1 = 0; cg1 < nGroupsInRow_; cg1++) {
263 >      vector<int> atomListRow = getAtomsInGroupRow(cg1);
264 >      for (vector<int>::iterator ia = atomListRow.begin();
265 >           ia != atomListRow.end(); ++ia) {            
266 >        int atom1 = (*ia);
267 >        atid = identsRow[atom1];
268 >        if (atypeCutoff[atid] > groupCutoffRow[cg1]) {
269 >          groupCutoffRow[cg1] = atypeCutoff[atid];
270          }
271 <        if (oneThree.hasPair(iglob, jglob)) {
272 <          toposForLocalAtom[i].push_back(j);
273 <          topoDistLocal[i][nTopos] = 2;
274 <          nTopos++;
271 >      }
272 >
273 >      bool gTypeFound = false;
274 >      for (int gt = 0; gt < gTypeCutoffs.size(); gt++) {
275 >        if (abs(groupCutoffRow[cg1] - gTypeCutoffs[gt]) < tol) {
276 >          groupRowToGtype[cg1] = gt;
277 >          gTypeFound = true;
278 >        }
279 >      }
280 >      if (!gTypeFound) {
281 >        gTypeCutoffs.push_back( groupCutoffRow[cg1] );
282 >        groupRowToGtype[cg1] = gTypeCutoffs.size() - 1;
283 >      }
284 >      
285 >    }
286 >    vector<RealType> groupCutoffCol(nGroupsInCol_, 0.0);
287 >    groupColToGtype.resize(nGroupsInCol_);
288 >    for (int cg2 = 0; cg2 < nGroupsInCol_; cg2++) {
289 >      vector<int> atomListCol = getAtomsInGroupColumn(cg2);
290 >      for (vector<int>::iterator jb = atomListCol.begin();
291 >           jb != atomListCol.end(); ++jb) {            
292 >        int atom2 = (*jb);
293 >        atid = identsCol[atom2];
294 >        if (atypeCutoff[atid] > groupCutoffCol[cg2]) {
295 >          groupCutoffCol[cg2] = atypeCutoff[atid];
296          }
297 <        if (oneFour.hasPair(iglob, jglob)) {
298 <          toposForLocalAtom[i].push_back(j);
299 <          topoDistLocal[i][nTopos] = 3;
300 <          nTopos++;
297 >      }
298 >      bool gTypeFound = false;
299 >      for (int gt = 0; gt < gTypeCutoffs.size(); gt++) {
300 >        if (abs(groupCutoffCol[cg2] - gTypeCutoffs[gt]) < tol) {
301 >          groupColToGtype[cg2] = gt;
302 >          gTypeFound = true;
303 >        }
304 >      }
305 >      if (!gTypeFound) {
306 >        gTypeCutoffs.push_back( groupCutoffCol[cg2] );
307 >        groupColToGtype[cg2] = gTypeCutoffs.size() - 1;
308 >      }
309 >    }
310 > #else
311 >
312 >    vector<RealType> groupCutoff(nGroups_, 0.0);
313 >    groupToGtype.resize(nGroups_);
314 >    for (int cg1 = 0; cg1 < nGroups_; cg1++) {
315 >
316 >      groupCutoff[cg1] = 0.0;
317 >      vector<int> atomList = getAtomsInGroupRow(cg1);
318 >
319 >      for (vector<int>::iterator ia = atomList.begin();
320 >           ia != atomList.end(); ++ia) {            
321 >        int atom1 = (*ia);
322 >        atid = idents[atom1];
323 >        if (atypeCutoff[atid] > groupCutoff[cg1]) {
324 >          groupCutoff[cg1] = atypeCutoff[atid];
325          }
326 +      }
327 +
328 +      bool gTypeFound = false;
329 +      for (int gt = 0; gt < gTypeCutoffs.size(); gt++) {
330 +        if (abs(groupCutoff[cg1] - gTypeCutoffs[gt]) < tol) {
331 +          groupToGtype[cg1] = gt;
332 +          gTypeFound = true;
333 +        }
334 +      }
335 +      if (!gTypeFound) {
336 +        gTypeCutoffs.push_back( groupCutoff[cg1] );
337 +        groupToGtype[cg1] = gTypeCutoffs.size() - 1;
338        }      
339      }
340 + #endif
341 +
342 +    // Now we find the maximum group cutoff value present in the simulation
343 +
344 +    RealType groupMax = *max_element(gTypeCutoffs.begin(), gTypeCutoffs.end());
345 +
346 + #ifdef IS_MPI
347 +    MPI::COMM_WORLD.Allreduce(&groupMax, &groupMax, 1, MPI::REALTYPE, MPI::MAX);
348 + #endif
349 +    
350 +    RealType tradRcut = groupMax;
351 +
352 +    for (int i = 0; i < gTypeCutoffs.size();  i++) {
353 +      for (int j = 0; j < gTypeCutoffs.size();  j++) {      
354 +        RealType thisRcut;
355 +        switch(cutoffPolicy_) {
356 +        case TRADITIONAL:
357 +          thisRcut = tradRcut;
358 +          break;
359 +        case MIX:
360 +          thisRcut = 0.5 * (gTypeCutoffs[i] + gTypeCutoffs[j]);
361 +          break;
362 +        case MAX:
363 +          thisRcut = max(gTypeCutoffs[i], gTypeCutoffs[j]);
364 +          break;
365 +        default:
366 +          sprintf(painCave.errMsg,
367 +                  "ForceMatrixDecomposition::createGtypeCutoffMap "
368 +                  "hit an unknown cutoff policy!\n");
369 +          painCave.severity = OPENMD_ERROR;
370 +          painCave.isFatal = 1;
371 +          simError();
372 +          break;
373 +        }
374 +
375 +        pair<int,int> key = make_pair(i,j);
376 +        gTypeCutoffMap[key].first = thisRcut;
377 +
378 +        if (thisRcut > largestRcut_) largestRcut_ = thisRcut;
379 +
380 +        gTypeCutoffMap[key].second = thisRcut*thisRcut;
381 +        
382 +        gTypeCutoffMap[key].third = pow(thisRcut + skinThickness_, 2);
383 +
384 +        // sanity check
385 +        
386 +        if (userChoseCutoff_) {
387 +          if (abs(gTypeCutoffMap[key].first - userCutoff_) > 0.0001) {
388 +            sprintf(painCave.errMsg,
389 +                    "ForceMatrixDecomposition::createGtypeCutoffMap "
390 +                    "user-specified rCut (%lf) does not match computed group Cutoff\n", userCutoff_);
391 +            painCave.severity = OPENMD_ERROR;
392 +            painCave.isFatal = 1;
393 +            simError();            
394 +          }
395 +        }
396 +      }
397 +    }
398    }
399 <  
399 >
400 >
401 >  groupCutoffs ForceMatrixDecomposition::getGroupCutoffs(int cg1, int cg2) {
402 >    int i, j;  
403 > #ifdef IS_MPI
404 >    i = groupRowToGtype[cg1];
405 >    j = groupColToGtype[cg2];
406 > #else
407 >    i = groupToGtype[cg1];
408 >    j = groupToGtype[cg2];
409 > #endif    
410 >    return gTypeCutoffMap[make_pair(i,j)];
411 >  }
412 >
413 >  int ForceMatrixDecomposition::getTopologicalDistance(int atom1, int atom2) {
414 >    for (int j = 0; j < toposForAtom[atom1].size(); j++) {
415 >      if (toposForAtom[atom1][j] == atom2)
416 >        return topoDist[atom1][j];
417 >    }
418 >    return 0;
419 >  }
420 >
421 >  void ForceMatrixDecomposition::zeroWorkArrays() {
422 >    pairwisePot = 0.0;
423 >    embeddingPot = 0.0;
424 >
425 > #ifdef IS_MPI
426 >    if (storageLayout_ & DataStorage::dslForce) {
427 >      fill(atomRowData.force.begin(), atomRowData.force.end(), V3Zero);
428 >      fill(atomColData.force.begin(), atomColData.force.end(), V3Zero);
429 >    }
430 >
431 >    if (storageLayout_ & DataStorage::dslTorque) {
432 >      fill(atomRowData.torque.begin(), atomRowData.torque.end(), V3Zero);
433 >      fill(atomColData.torque.begin(), atomColData.torque.end(), V3Zero);
434 >    }
435 >    
436 >    fill(pot_row.begin(), pot_row.end(),
437 >         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
438 >
439 >    fill(pot_col.begin(), pot_col.end(),
440 >         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));  
441 >
442 >    if (storageLayout_ & DataStorage::dslParticlePot) {    
443 >      fill(atomRowData.particlePot.begin(), atomRowData.particlePot.end(), 0.0);
444 >      fill(atomColData.particlePot.begin(), atomColData.particlePot.end(), 0.0);
445 >    }
446 >
447 >    if (storageLayout_ & DataStorage::dslDensity) {      
448 >      fill(atomRowData.density.begin(), atomRowData.density.end(), 0.0);
449 >      fill(atomColData.density.begin(), atomColData.density.end(), 0.0);
450 >    }
451 >
452 >    if (storageLayout_ & DataStorage::dslFunctional) {  
453 >      fill(atomRowData.functional.begin(), atomRowData.functional.end(), 0.0);
454 >      fill(atomColData.functional.begin(), atomColData.functional.end(), 0.0);
455 >    }
456 >
457 >    if (storageLayout_ & DataStorage::dslFunctionalDerivative) {      
458 >      fill(atomRowData.functionalDerivative.begin(),
459 >           atomRowData.functionalDerivative.end(), 0.0);
460 >      fill(atomColData.functionalDerivative.begin(),
461 >           atomColData.functionalDerivative.end(), 0.0);
462 >    }
463 >
464 >    if (storageLayout_ & DataStorage::dslSkippedCharge) {      
465 >      fill(atomRowData.skippedCharge.begin(),
466 >           atomRowData.skippedCharge.end(), 0.0);
467 >      fill(atomColData.skippedCharge.begin(),
468 >           atomColData.skippedCharge.end(), 0.0);
469 >    }
470 >
471 > #else
472 >    
473 >    if (storageLayout_ & DataStorage::dslParticlePot) {      
474 >      fill(snap_->atomData.particlePot.begin(),
475 >           snap_->atomData.particlePot.end(), 0.0);
476 >    }
477 >    
478 >    if (storageLayout_ & DataStorage::dslDensity) {      
479 >      fill(snap_->atomData.density.begin(),
480 >           snap_->atomData.density.end(), 0.0);
481 >    }
482 >    if (storageLayout_ & DataStorage::dslFunctional) {
483 >      fill(snap_->atomData.functional.begin(),
484 >           snap_->atomData.functional.end(), 0.0);
485 >    }
486 >    if (storageLayout_ & DataStorage::dslFunctionalDerivative) {      
487 >      fill(snap_->atomData.functionalDerivative.begin(),
488 >           snap_->atomData.functionalDerivative.end(), 0.0);
489 >    }
490 >    if (storageLayout_ & DataStorage::dslSkippedCharge) {      
491 >      fill(snap_->atomData.skippedCharge.begin(),
492 >           snap_->atomData.skippedCharge.end(), 0.0);
493 >    }
494 > #endif
495 >    
496 >  }
497 >
498 >
499    void ForceMatrixDecomposition::distributeData()  {
500      snap_ = sman_->getCurrentSnapshot();
501      storageLayout_ = sman_->getStorageLayout();
# Line 266 | Line 531 | namespace OpenMD {
531   #endif      
532    }
533    
534 +  /* collects information obtained during the pre-pair loop onto local
535 +   * data structures.
536 +   */
537    void ForceMatrixDecomposition::collectIntermediateData() {
538      snap_ = sman_->getCurrentSnapshot();
539      storageLayout_ = sman_->getStorageLayout();
# Line 277 | Line 545 | namespace OpenMD {
545                                 snap_->atomData.density);
546        
547        int n = snap_->atomData.density.size();
548 <      std::vector<RealType> rho_tmp(n, 0.0);
548 >      vector<RealType> rho_tmp(n, 0.0);
549        AtomCommRealColumn->scatter(atomColData.density, rho_tmp);
550        for (int i = 0; i < n; i++)
551          snap_->atomData.density[i] += rho_tmp[i];
552      }
553   #endif
554    }
555 <  
555 >
556 >  /*
557 >   * redistributes information obtained during the pre-pair loop out to
558 >   * row and column-indexed data structures
559 >   */
560    void ForceMatrixDecomposition::distributeIntermediateData() {
561      snap_ = sman_->getCurrentSnapshot();
562      storageLayout_ = sman_->getStorageLayout();
# Line 326 | Line 598 | namespace OpenMD {
598      
599      if (storageLayout_ & DataStorage::dslTorque) {
600  
601 <      int nt = snap_->atomData.force.size();
601 >      int nt = snap_->atomData.torque.size();
602        vector<Vector3d> trq_tmp(nt, V3Zero);
603  
604        AtomCommVectorRow->scatter(atomRowData.torque, trq_tmp);
605 <      for (int i = 0; i < n; i++) {
605 >      for (int i = 0; i < nt; i++) {
606          snap_->atomData.torque[i] += trq_tmp[i];
607          trq_tmp[i] = 0.0;
608        }
609        
610        AtomCommVectorColumn->scatter(atomColData.torque, trq_tmp);
611 <      for (int i = 0; i < n; i++)
611 >      for (int i = 0; i < nt; i++)
612          snap_->atomData.torque[i] += trq_tmp[i];
613      }
614 +
615 +    if (storageLayout_ & DataStorage::dslSkippedCharge) {
616 +
617 +      int ns = snap_->atomData.skippedCharge.size();
618 +      vector<RealType> skch_tmp(ns, 0.0);
619 +
620 +      AtomCommRealRow->scatter(atomRowData.skippedCharge, skch_tmp);
621 +      for (int i = 0; i < ns; i++) {
622 +        snap_->atomData.skippedCharge[i] = skch_tmp[i];
623 +        skch_tmp[i] = 0.0;
624 +      }
625 +      
626 +      AtomCommRealColumn->scatter(atomColData.skippedCharge, skch_tmp);
627 +      for (int i = 0; i < ns; i++)
628 +        snap_->atomData.skippedCharge[i] += skch_tmp[i];
629 +    }
630      
631      nLocal_ = snap_->getNumberOfAtoms();
632  
633 <    vector<vector<RealType> > pot_temp(N_INTERACTION_FAMILIES,
634 <                                       vector<RealType> (nLocal_, 0.0));
633 >    vector<potVec> pot_temp(nLocal_,
634 >                            Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
635 >
636 >    // scatter/gather pot_row into the members of my column
637 >          
638 >    AtomCommPotRow->scatter(pot_row, pot_temp);
639 >
640 >    for (int ii = 0;  ii < pot_temp.size(); ii++ )
641 >      pairwisePot += pot_temp[ii];
642      
643 <    for (int i = 0; i < N_INTERACTION_FAMILIES; i++) {
644 <      AtomCommRealRow->scatter(pot_row[i], pot_temp[i]);
645 <      for (int ii = 0;  ii < pot_temp[i].size(); ii++ ) {
646 <        pot_local[i] += pot_temp[i][ii];
647 <      }
648 <    }
643 >    fill(pot_temp.begin(), pot_temp.end(),
644 >         Vector<RealType, N_INTERACTION_FAMILIES> (0.0));
645 >      
646 >    AtomCommPotColumn->scatter(pot_col, pot_temp);    
647 >    
648 >    for (int ii = 0;  ii < pot_temp.size(); ii++ )
649 >      pairwisePot += pot_temp[ii];    
650   #endif
651 +
652    }
653  
654    int ForceMatrixDecomposition::getNAtomsInRow() {  
# Line 426 | Line 723 | namespace OpenMD {
723   #ifdef IS_MPI
724      return massFactorsRow[atom1];
725   #else
726 <    return massFactorsLocal[atom1];
726 >    return massFactors[atom1];
727   #endif
728    }
729  
# Line 434 | Line 731 | namespace OpenMD {
731   #ifdef IS_MPI
732      return massFactorsCol[atom2];
733   #else
734 <    return massFactorsLocal[atom2];
734 >    return massFactors[atom2];
735   #endif
736  
737    }
# Line 452 | Line 749 | namespace OpenMD {
749      return d;    
750    }
751  
752 <  vector<int> ForceMatrixDecomposition::getSkipsForRowAtom(int atom1) {
753 < #ifdef IS_MPI
457 <    return skipsForRowAtom[atom1];
458 < #else
459 <    return skipsForLocalAtom[atom1];
460 < #endif
752 >  vector<int> ForceMatrixDecomposition::getExcludesForAtom(int atom1) {
753 >    return excludesForAtom[atom1];
754    }
755  
756    /**
757 <   * there are a number of reasons to skip a pair or a particle mostly
758 <   * we do this to exclude atoms who are involved in short range
466 <   * interactions (bonds, bends, torsions), but we also need to
467 <   * exclude some overcounted interactions that result from the
468 <   * parallel decomposition.
757 >   * We need to exclude some overcounted interactions that result from
758 >   * the parallel decomposition.
759     */
760    bool ForceMatrixDecomposition::skipAtomPair(int atom1, int atom2) {
761      int unique_id_1, unique_id_2;
# Line 484 | Line 774 | namespace OpenMD {
774      } else {
775        if ((unique_id_1 + unique_id_2) % 2 == 1) return true;
776      }
487 #else
488    // in the normal loop, the atom numbers are unique
489    unique_id_1 = atom1;
490    unique_id_2 = atom2;
777   #endif
778 <    
493 < #ifdef IS_MPI
494 <    for (vector<int>::iterator i = skipsForRowAtom[atom1].begin();
495 <         i != skipsForRowAtom[atom1].end(); ++i) {
496 <      if ( (*i) == unique_id_2 ) return true;
497 <    }    
498 < #else
499 <    for (vector<int>::iterator i = skipsForLocalAtom[atom1].begin();
500 <         i != skipsForLocalAtom[atom1].end(); ++i) {
501 <      if ( (*i) == unique_id_2 ) return true;
502 <    }    
503 < #endif
778 >    return false;
779    }
780  
781 <  int ForceMatrixDecomposition::getTopoDistance(int atom1, int atom2) {
781 >  /**
782 >   * We need to handle the interactions for atoms who are involved in
783 >   * the same rigid body as well as some short range interactions
784 >   * (bonds, bends, torsions) differently from other interactions.
785 >   * We'll still visit the pairwise routines, but with a flag that
786 >   * tells those routines to exclude the pair from direct long range
787 >   * interactions.  Some indirect interactions (notably reaction
788 >   * field) must still be handled for these pairs.
789 >   */
790 >  bool ForceMatrixDecomposition::excludeAtomPair(int atom1, int atom2) {
791 >    int unique_id_2;
792      
793   #ifdef IS_MPI
794 <    for (int i = 0; i < toposForRowAtom[atom1].size(); i++) {
795 <      if ( toposForRowAtom[atom1][i] == atom2 ) return topoDistRow[atom1][i];
511 <    }
794 >    // in MPI, we have to look up the unique IDs for the row atom.
795 >    unique_id_2 = AtomColToGlobal[atom2];
796   #else
797 <    for (int i = 0; i < toposForLocalAtom[atom1].size(); i++) {
798 <      if ( toposForLocalAtom[atom1][i] == atom2 ) return topoDistLocal[atom1][i];
515 <    }
797 >    // in the normal loop, the atom numbers are unique
798 >    unique_id_2 = atom2;
799   #endif
800 +    
801 +    for (vector<int>::iterator i = excludesForAtom[atom1].begin();
802 +         i != excludesForAtom[atom1].end(); ++i) {
803 +      if ( (*i) == unique_id_2 ) return true;
804 +    }
805  
806 <    // zero is default for unconnected (i.e. normal) pair interactions
519 <    return 0;
806 >    return false;
807    }
808  
809 +
810    void ForceMatrixDecomposition::addForceToAtomRow(int atom1, Vector3d fg){
811   #ifdef IS_MPI
812      atomRowData.force[atom1] += fg;
# Line 536 | Line 824 | namespace OpenMD {
824    }
825  
826      // filling interaction blocks with pointers
827 <  InteractionData ForceMatrixDecomposition::fillInteractionData(int atom1, int atom2) {    
828 <    InteractionData idat;
827 >  void ForceMatrixDecomposition::fillInteractionData(InteractionData &idat,
828 >                                                     int atom1, int atom2) {
829  
830 +    idat.excluded = excludeAtomPair(atom1, atom2);
831 +  
832   #ifdef IS_MPI
833 +    
834 +    idat.atypes = make_pair( ff_->getAtomType(identsRow[atom1]),
835 +                             ff_->getAtomType(identsCol[atom2]) );
836 +    
837      if (storageLayout_ & DataStorage::dslAmat) {
838        idat.A1 = &(atomRowData.aMat[atom1]);
839        idat.A2 = &(atomColData.aMat[atom2]);
# Line 560 | Line 854 | namespace OpenMD {
854        idat.rho2 = &(atomColData.density[atom2]);
855      }
856  
857 +    if (storageLayout_ & DataStorage::dslFunctional) {
858 +      idat.frho1 = &(atomRowData.functional[atom1]);
859 +      idat.frho2 = &(atomColData.functional[atom2]);
860 +    }
861 +
862      if (storageLayout_ & DataStorage::dslFunctionalDerivative) {
863        idat.dfrho1 = &(atomRowData.functionalDerivative[atom1]);
864        idat.dfrho2 = &(atomColData.functionalDerivative[atom2]);
865      }
866  
867 +    if (storageLayout_ & DataStorage::dslParticlePot) {
868 +      idat.particlePot1 = &(atomRowData.particlePot[atom1]);
869 +      idat.particlePot2 = &(atomColData.particlePot[atom2]);
870 +    }
871 +
872 +    if (storageLayout_ & DataStorage::dslSkippedCharge) {              
873 +      idat.skippedCharge1 = &(atomRowData.skippedCharge[atom1]);
874 +      idat.skippedCharge2 = &(atomColData.skippedCharge[atom2]);
875 +    }
876 +
877   #else
878 +
879 +    idat.atypes = make_pair( ff_->getAtomType(idents[atom1]),
880 +                             ff_->getAtomType(idents[atom2]) );
881 +
882      if (storageLayout_ & DataStorage::dslAmat) {
883        idat.A1 = &(snap_->atomData.aMat[atom1]);
884        idat.A2 = &(snap_->atomData.aMat[atom2]);
# Line 581 | Line 894 | namespace OpenMD {
894        idat.t2 = &(snap_->atomData.torque[atom2]);
895      }
896  
897 <    if (storageLayout_ & DataStorage::dslDensity) {
897 >    if (storageLayout_ & DataStorage::dslDensity) {    
898        idat.rho1 = &(snap_->atomData.density[atom1]);
899        idat.rho2 = &(snap_->atomData.density[atom2]);
900      }
901  
902 +    if (storageLayout_ & DataStorage::dslFunctional) {
903 +      idat.frho1 = &(snap_->atomData.functional[atom1]);
904 +      idat.frho2 = &(snap_->atomData.functional[atom2]);
905 +    }
906 +
907      if (storageLayout_ & DataStorage::dslFunctionalDerivative) {
908        idat.dfrho1 = &(snap_->atomData.functionalDerivative[atom1]);
909        idat.dfrho2 = &(snap_->atomData.functionalDerivative[atom2]);
910      }
593 #endif
594    return idat;
595  }
911  
912 <  InteractionData ForceMatrixDecomposition::fillSkipData(int atom1, int atom2){
913 <
914 <    InteractionData idat;
600 < #ifdef IS_MPI
601 <    if (storageLayout_ & DataStorage::dslElectroFrame) {
602 <      idat.eFrame1 = &(atomRowData.electroFrame[atom1]);
603 <      idat.eFrame2 = &(atomColData.electroFrame[atom2]);
604 <    }
605 <    if (storageLayout_ & DataStorage::dslTorque) {
606 <      idat.t1 = &(atomRowData.torque[atom1]);
607 <      idat.t2 = &(atomColData.torque[atom2]);
912 >    if (storageLayout_ & DataStorage::dslParticlePot) {
913 >      idat.particlePot1 = &(snap_->atomData.particlePot[atom1]);
914 >      idat.particlePot2 = &(snap_->atomData.particlePot[atom2]);
915      }
916 <    if (storageLayout_ & DataStorage::dslForce) {
917 <      idat.t1 = &(atomRowData.force[atom1]);
918 <      idat.t2 = &(atomColData.force[atom2]);
916 >
917 >    if (storageLayout_ & DataStorage::dslSkippedCharge) {
918 >      idat.skippedCharge1 = &(snap_->atomData.skippedCharge[atom1]);
919 >      idat.skippedCharge2 = &(snap_->atomData.skippedCharge[atom2]);
920      }
613 #else
614    if (storageLayout_ & DataStorage::dslElectroFrame) {
615      idat.eFrame1 = &(snap_->atomData.electroFrame[atom1]);
616      idat.eFrame2 = &(snap_->atomData.electroFrame[atom2]);
617    }
618    if (storageLayout_ & DataStorage::dslTorque) {
619      idat.t1 = &(snap_->atomData.torque[atom1]);
620      idat.t2 = &(snap_->atomData.torque[atom2]);
621    }
622    if (storageLayout_ & DataStorage::dslForce) {
623      idat.t1 = &(snap_->atomData.force[atom1]);
624      idat.t2 = &(snap_->atomData.force[atom2]);
625    }
921   #endif
627    
922    }
923  
924 +  
925 +  void ForceMatrixDecomposition::unpackInteractionData(InteractionData &idat, int atom1, int atom2) {    
926 + #ifdef IS_MPI
927 +    pot_row[atom1] += 0.5 *  *(idat.pot);
928 +    pot_col[atom2] += 0.5 *  *(idat.pot);
929  
930 +    atomRowData.force[atom1] += *(idat.f1);
931 +    atomColData.force[atom2] -= *(idat.f1);
932 + #else
933 +    pairwisePot += *(idat.pot);
934  
935 +    snap_->atomData.force[atom1] += *(idat.f1);
936 +    snap_->atomData.force[atom2] -= *(idat.f1);
937 + #endif
938 +    
939 +  }
940  
941    /*
942     * buildNeighborList
# Line 639 | Line 947 | namespace OpenMD {
947    vector<pair<int, int> > ForceMatrixDecomposition::buildNeighborList() {
948        
949      vector<pair<int, int> > neighborList;
950 +    groupCutoffs cuts;
951 +    bool doAllPairs = false;
952 +
953   #ifdef IS_MPI
954      cellListRow_.clear();
955      cellListCol_.clear();
# Line 646 | Line 957 | namespace OpenMD {
957      cellList_.clear();
958   #endif
959  
960 <    // dangerous to not do error checking.
650 <    RealType rCut_;
651 <
652 <    RealType rList_ = (rCut_ + skinThickness_);
960 >    RealType rList_ = (largestRcut_ + skinThickness_);
961      RealType rl2 = rList_ * rList_;
962      Snapshot* snap_ = sman_->getCurrentSnapshot();
963      Mat3x3d Hmat = snap_->getHmat();
# Line 661 | Line 969 | namespace OpenMD {
969      nCells_.y() = (int) ( Hy.length() )/ rList_;
970      nCells_.z() = (int) ( Hz.length() )/ rList_;
971  
972 +    // handle small boxes where the cell offsets can end up repeating cells
973 +    
974 +    if (nCells_.x() < 3) doAllPairs = true;
975 +    if (nCells_.y() < 3) doAllPairs = true;
976 +    if (nCells_.z() < 3) doAllPairs = true;
977 +
978      Mat3x3d invHmat = snap_->getInvHmat();
979      Vector3d rs, scaled, dr;
980      Vector3i whichCell;
981      int cellIndex;
982 +    int nCtot = nCells_.x() * nCells_.y() * nCells_.z();
983  
984   #ifdef IS_MPI
985 <    for (int i = 0; i < nGroupsInRow_; i++) {
986 <      rs = cgRowData.position[i];
672 <      // scaled positions relative to the box vectors
673 <      scaled = invHmat * rs;
674 <      // wrap the vector back into the unit box by subtracting integer box
675 <      // numbers
676 <      for (int j = 0; j < 3; j++)
677 <        scaled[j] -= roundMe(scaled[j]);
678 <    
679 <      // find xyz-indices of cell that cutoffGroup is in.
680 <      whichCell.x() = nCells_.x() * scaled.x();
681 <      whichCell.y() = nCells_.y() * scaled.y();
682 <      whichCell.z() = nCells_.z() * scaled.z();
683 <
684 <      // find single index of this cell:
685 <      cellIndex = Vlinear(whichCell, nCells_);
686 <      // add this cutoff group to the list of groups in this cell;
687 <      cellListRow_[cellIndex].push_back(i);
688 <    }
689 <
690 <    for (int i = 0; i < nGroupsInCol_; i++) {
691 <      rs = cgColData.position[i];
692 <      // scaled positions relative to the box vectors
693 <      scaled = invHmat * rs;
694 <      // wrap the vector back into the unit box by subtracting integer box
695 <      // numbers
696 <      for (int j = 0; j < 3; j++)
697 <        scaled[j] -= roundMe(scaled[j]);
698 <
699 <      // find xyz-indices of cell that cutoffGroup is in.
700 <      whichCell.x() = nCells_.x() * scaled.x();
701 <      whichCell.y() = nCells_.y() * scaled.y();
702 <      whichCell.z() = nCells_.z() * scaled.z();
703 <
704 <      // find single index of this cell:
705 <      cellIndex = Vlinear(whichCell, nCells_);
706 <      // add this cutoff group to the list of groups in this cell;
707 <      cellListCol_[cellIndex].push_back(i);
708 <    }
985 >    cellListRow_.resize(nCtot);
986 >    cellListCol_.resize(nCtot);
987   #else
988 <    for (int i = 0; i < nGroups_; i++) {
711 <      rs = snap_->cgData.position[i];
712 <      // scaled positions relative to the box vectors
713 <      scaled = invHmat * rs;
714 <      // wrap the vector back into the unit box by subtracting integer box
715 <      // numbers
716 <      for (int j = 0; j < 3; j++)
717 <        scaled[j] -= roundMe(scaled[j]);
718 <
719 <      // find xyz-indices of cell that cutoffGroup is in.
720 <      whichCell.x() = nCells_.x() * scaled.x();
721 <      whichCell.y() = nCells_.y() * scaled.y();
722 <      whichCell.z() = nCells_.z() * scaled.z();
723 <
724 <      // find single index of this cell:
725 <      cellIndex = Vlinear(whichCell, nCells_);
726 <      // add this cutoff group to the list of groups in this cell;
727 <      cellList_[cellIndex].push_back(i);
728 <    }
988 >    cellList_.resize(nCtot);
989   #endif
990  
991 +    if (!doAllPairs) {
992 + #ifdef IS_MPI
993  
994 +      for (int i = 0; i < nGroupsInRow_; i++) {
995 +        rs = cgRowData.position[i];
996 +        
997 +        // scaled positions relative to the box vectors
998 +        scaled = invHmat * rs;
999 +        
1000 +        // wrap the vector back into the unit box by subtracting integer box
1001 +        // numbers
1002 +        for (int j = 0; j < 3; j++) {
1003 +          scaled[j] -= roundMe(scaled[j]);
1004 +          scaled[j] += 0.5;
1005 +        }
1006 +        
1007 +        // find xyz-indices of cell that cutoffGroup is in.
1008 +        whichCell.x() = nCells_.x() * scaled.x();
1009 +        whichCell.y() = nCells_.y() * scaled.y();
1010 +        whichCell.z() = nCells_.z() * scaled.z();
1011 +        
1012 +        // find single index of this cell:
1013 +        cellIndex = Vlinear(whichCell, nCells_);
1014 +        
1015 +        // add this cutoff group to the list of groups in this cell;
1016 +        cellListRow_[cellIndex].push_back(i);
1017 +      }
1018 +      
1019 +      for (int i = 0; i < nGroupsInCol_; i++) {
1020 +        rs = cgColData.position[i];
1021 +        
1022 +        // scaled positions relative to the box vectors
1023 +        scaled = invHmat * rs;
1024 +        
1025 +        // wrap the vector back into the unit box by subtracting integer box
1026 +        // numbers
1027 +        for (int j = 0; j < 3; j++) {
1028 +          scaled[j] -= roundMe(scaled[j]);
1029 +          scaled[j] += 0.5;
1030 +        }
1031 +        
1032 +        // find xyz-indices of cell that cutoffGroup is in.
1033 +        whichCell.x() = nCells_.x() * scaled.x();
1034 +        whichCell.y() = nCells_.y() * scaled.y();
1035 +        whichCell.z() = nCells_.z() * scaled.z();
1036 +        
1037 +        // find single index of this cell:
1038 +        cellIndex = Vlinear(whichCell, nCells_);
1039 +        
1040 +        // add this cutoff group to the list of groups in this cell;
1041 +        cellListCol_[cellIndex].push_back(i);
1042 +      }
1043 + #else
1044 +      for (int i = 0; i < nGroups_; i++) {
1045 +        rs = snap_->cgData.position[i];
1046 +        
1047 +        // scaled positions relative to the box vectors
1048 +        scaled = invHmat * rs;
1049 +        
1050 +        // wrap the vector back into the unit box by subtracting integer box
1051 +        // numbers
1052 +        for (int j = 0; j < 3; j++) {
1053 +          scaled[j] -= roundMe(scaled[j]);
1054 +          scaled[j] += 0.5;
1055 +        }
1056 +        
1057 +        // find xyz-indices of cell that cutoffGroup is in.
1058 +        whichCell.x() = nCells_.x() * scaled.x();
1059 +        whichCell.y() = nCells_.y() * scaled.y();
1060 +        whichCell.z() = nCells_.z() * scaled.z();
1061 +        
1062 +        // find single index of this cell:
1063 +        cellIndex = Vlinear(whichCell, nCells_);      
1064 +        
1065 +        // add this cutoff group to the list of groups in this cell;
1066 +        cellList_[cellIndex].push_back(i);
1067 +      }
1068 + #endif
1069  
1070 <    for (int m1z = 0; m1z < nCells_.z(); m1z++) {
1071 <      for (int m1y = 0; m1y < nCells_.y(); m1y++) {
1072 <        for (int m1x = 0; m1x < nCells_.x(); m1x++) {
1073 <          Vector3i m1v(m1x, m1y, m1z);
1074 <          int m1 = Vlinear(m1v, nCells_);
738 <
739 <          for (vector<Vector3i>::iterator os = cellOffsets_.begin();
740 <               os != cellOffsets_.end(); ++os) {
1070 >      for (int m1z = 0; m1z < nCells_.z(); m1z++) {
1071 >        for (int m1y = 0; m1y < nCells_.y(); m1y++) {
1072 >          for (int m1x = 0; m1x < nCells_.x(); m1x++) {
1073 >            Vector3i m1v(m1x, m1y, m1z);
1074 >            int m1 = Vlinear(m1v, nCells_);
1075              
1076 <            Vector3i m2v = m1v + (*os);
1077 <            
1078 <            if (m2v.x() >= nCells_.x()) {
1079 <              m2v.x() = 0;          
1080 <            } else if (m2v.x() < 0) {
1081 <              m2v.x() = nCells_.x() - 1;
1082 <            }
1083 <            
1084 <            if (m2v.y() >= nCells_.y()) {
1085 <              m2v.y() = 0;          
1086 <            } else if (m2v.y() < 0) {
1087 <              m2v.y() = nCells_.y() - 1;
1088 <            }
1089 <            
1090 <            if (m2v.z() >= nCells_.z()) {
1091 <              m2v.z() = 0;          
1092 <            } else if (m2v.z() < 0) {
1093 <              m2v.z() = nCells_.z() - 1;
1094 <            }
1095 <            
1096 <            int m2 = Vlinear (m2v, nCells_);
1097 <
1076 >            for (vector<Vector3i>::iterator os = cellOffsets_.begin();
1077 >                 os != cellOffsets_.end(); ++os) {
1078 >              
1079 >              Vector3i m2v = m1v + (*os);
1080 >              
1081 >              if (m2v.x() >= nCells_.x()) {
1082 >                m2v.x() = 0;          
1083 >              } else if (m2v.x() < 0) {
1084 >                m2v.x() = nCells_.x() - 1;
1085 >              }
1086 >              
1087 >              if (m2v.y() >= nCells_.y()) {
1088 >                m2v.y() = 0;          
1089 >              } else if (m2v.y() < 0) {
1090 >                m2v.y() = nCells_.y() - 1;
1091 >              }
1092 >              
1093 >              if (m2v.z() >= nCells_.z()) {
1094 >                m2v.z() = 0;          
1095 >              } else if (m2v.z() < 0) {
1096 >                m2v.z() = nCells_.z() - 1;
1097 >              }
1098 >              
1099 >              int m2 = Vlinear (m2v, nCells_);
1100 >              
1101   #ifdef IS_MPI
1102 <            for (vector<int>::iterator j1 = cellListRow_[m1].begin();
1103 <                 j1 != cellListRow_[m1].end(); ++j1) {
1104 <              for (vector<int>::iterator j2 = cellListCol_[m2].begin();
1105 <                   j2 != cellListCol_[m2].end(); ++j2) {
1106 <                              
1107 <                // Always do this if we're in different cells or if
1108 <                // we're in the same cell and the global index of the
1109 <                // j2 cutoff group is less than the j1 cutoff group
1110 <
1111 <                if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) {
1112 <                  dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)];
1113 <                  snap_->wrapVector(dr);
1114 <                  if (dr.lengthSquare() < rl2) {
1115 <                    neighborList.push_back(make_pair((*j1), (*j2)));
1102 >              for (vector<int>::iterator j1 = cellListRow_[m1].begin();
1103 >                   j1 != cellListRow_[m1].end(); ++j1) {
1104 >                for (vector<int>::iterator j2 = cellListCol_[m2].begin();
1105 >                     j2 != cellListCol_[m2].end(); ++j2) {
1106 >                  
1107 >                  // Always do this if we're in different cells or if
1108 >                  // we're in the same cell and the global index of the
1109 >                  // j2 cutoff group is less than the j1 cutoff group
1110 >                  
1111 >                  if (m2 != m1 || cgColToGlobal[(*j2)] < cgRowToGlobal[(*j1)]) {
1112 >                    dr = cgColData.position[(*j2)] - cgRowData.position[(*j1)];
1113 >                    snap_->wrapVector(dr);
1114 >                    cuts = getGroupCutoffs( (*j1), (*j2) );
1115 >                    if (dr.lengthSquare() < cuts.third) {
1116 >                      neighborList.push_back(make_pair((*j1), (*j2)));
1117 >                    }
1118                    }
1119                  }
1120                }
782            }
1121   #else
1122 <            for (vector<int>::iterator j1 = cellList_[m1].begin();
1123 <                 j1 != cellList_[m1].end(); ++j1) {
1124 <              for (vector<int>::iterator j2 = cellList_[m2].begin();
1125 <                   j2 != cellList_[m2].end(); ++j2) {
1126 <                              
1127 <                // Always do this if we're in different cells or if
1128 <                // we're in the same cell and the global index of the
1129 <                // j2 cutoff group is less than the j1 cutoff group
1130 <
1131 <                if (m2 != m1 || (*j2) < (*j1)) {
1132 <                  dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)];
1133 <                  snap_->wrapVector(dr);
1134 <                  if (dr.lengthSquare() < rl2) {
1135 <                    neighborList.push_back(make_pair((*j1), (*j2)));
1122 >              
1123 >              for (vector<int>::iterator j1 = cellList_[m1].begin();
1124 >                   j1 != cellList_[m1].end(); ++j1) {
1125 >                for (vector<int>::iterator j2 = cellList_[m2].begin();
1126 >                     j2 != cellList_[m2].end(); ++j2) {
1127 >                  
1128 >                  // Always do this if we're in different cells or if
1129 >                  // we're in the same cell and the global index of the
1130 >                  // j2 cutoff group is less than the j1 cutoff group
1131 >                  
1132 >                  if (m2 != m1 || (*j2) < (*j1)) {
1133 >                    dr = snap_->cgData.position[(*j2)] - snap_->cgData.position[(*j1)];
1134 >                    snap_->wrapVector(dr);
1135 >                    cuts = getGroupCutoffs( (*j1), (*j2) );
1136 >                    if (dr.lengthSquare() < cuts.third) {
1137 >                      neighborList.push_back(make_pair((*j1), (*j2)));
1138 >                    }
1139                    }
1140                  }
1141                }
801            }
1142   #endif
1143 +            }
1144            }
1145          }
1146        }
1147 +    } else {
1148 +      // branch to do all cutoff group pairs
1149 + #ifdef IS_MPI
1150 +      for (int j1 = 0; j1 < nGroupsInRow_; j1++) {
1151 +        for (int j2 = 0; j2 < nGroupsInCol_; j2++) {      
1152 +          dr = cgColData.position[j2] - cgRowData.position[j1];
1153 +          snap_->wrapVector(dr);
1154 +          cuts = getGroupCutoffs( j1, j2 );
1155 +          if (dr.lengthSquare() < cuts.third) {
1156 +            neighborList.push_back(make_pair(j1, j2));
1157 +          }
1158 +        }
1159 +      }
1160 + #else
1161 +      for (int j1 = 0; j1 < nGroups_ - 1; j1++) {
1162 +        for (int j2 = j1 + 1; j2 < nGroups_; j2++) {
1163 +          dr = snap_->cgData.position[j2] - snap_->cgData.position[j1];
1164 +          snap_->wrapVector(dr);
1165 +          cuts = getGroupCutoffs( j1, j2 );
1166 +          if (dr.lengthSquare() < cuts.third) {
1167 +            neighborList.push_back(make_pair(j1, j2));
1168 +          }
1169 +        }
1170 +      }        
1171 + #endif
1172      }
1173 <
1173 >      
1174      // save the local cutoff group positions for the check that is
1175      // done on each loop:
1176      saved_CG_positions_.clear();
1177      for (int i = 0; i < nGroups_; i++)
1178        saved_CG_positions_.push_back(snap_->cgData.position[i]);
1179 <
1179 >    
1180      return neighborList;
1181    }
1182   } //end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines