From 9fa8f2cd542c67bcad69094735ff84a368a2dde5 Mon Sep 17 00:00:00 2001
From: Chris Maffeo <cmaffeo2@illinois.edu>
Date: Tue, 13 Jun 2017 14:13:14 -0500
Subject: [PATCH] Fixed multiple bugs relating to the pairlist creation

---
 src/CellDecomposition.cu | 9 +++++----
 src/ComputeForce.cu      | 2 +-
 src/ComputeForce.cuh     | 4 ++--
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/CellDecomposition.cu b/src/CellDecomposition.cu
index a17133f..a94137c 100644
--- a/src/CellDecomposition.cu
+++ b/src/CellDecomposition.cu
@@ -141,6 +141,7 @@ void make_rangesKernel(CellDecomposition::cell_t cells[], int tmp[],
 
 	if (idx < num * numReplicas) {
 		const int repID = cells[idx].repID;
+		assert(repID == idx/num);
 		const int cellID = cells[idx].id + repID * numCells; // cellID in tmp array
 
 		// Get positions in tmp array.
@@ -156,14 +157,14 @@ void make_rangesKernel(CellDecomposition::cell_t cells[], int tmp[],
 
 		const int prev_id = idx - 1;
 		if (prev_id >= 0
-				and cellID != cells[prev_id].id
-				and cells[prev_id].repID == repID)
+		    and cells[prev_id].repID == repID
+		    and cellID != cells[prev_id].id + repID * numCells)
 			tmp[first] = idx;
 		
 		const int next_id = idx + 1;
 		if (next_id < num * numReplicas
-				and cellID != cells[next_id].id
-				and cells[next_id].repID == repID)
+		    and cells[next_id].repID == repID
+		    and cellID != cells[next_id].id + repID * numCells)
 			tmp[last] = idx + 1;
 	}
 }
diff --git a/src/ComputeForce.cu b/src/ComputeForce.cu
index 4bc3824..cd7bdcf 100644
--- a/src/ComputeForce.cu
+++ b/src/ComputeForce.cu
@@ -26,7 +26,7 @@ ComputeForce::ComputeForce(const Configuration& c, const int numReplicas = 1) :
     num(c.num), numParts(c.numParts), sys(c.sys), switchStart(c.switchStart),
     switchLen(c.switchLen), electricConst(c.coulombConst),
     cutoff2((c.switchLen + c.switchStart) * (c.switchLen + c.switchStart)),
-    decomp(c.sys->getBox(), c.sys->getOrigin(), c.switchStart + c.switchLen, numReplicas),
+    decomp(c.sys->getBox(), c.sys->getOrigin(), c.switchStart + c.switchLen + c.pairlistDistance, numReplicas),
     numBonds(c.numBonds), numTabBondFiles(c.numTabBondFiles),
     numExcludes(c.numExcludes), numAngles(c.numAngles),
     numTabAngleFiles(c.numTabAngleFiles), numDihedrals(c.numDihedrals),
diff --git a/src/ComputeForce.cuh b/src/ComputeForce.cuh
index 64ee8b1..ce5c3c1 100644
--- a/src/ComputeForce.cuh
+++ b/src/ComputeForce.cuh
@@ -262,8 +262,8 @@ void createPairlists(Vector3* __restrict__ pos, const int num, const int numRepl
 				// Vector3 posi = pos[ai];
 
 				// Same as for bonds, but for exclusions now
-				const int ex_start = (numExcludes > 0 && excludeMap != NULL) ? excludeMap[ai].x : -1;
-				const int ex_end   = (numExcludes > 0 && excludeMap != NULL) ? excludeMap[ai].y : -1;
+				const int ex_start = (numExcludes > 0 && excludeMap != NULL) ? excludeMap[ai -repID*num].x : -1;
+				const int ex_end   = (numExcludes > 0 && excludeMap != NULL) ? excludeMap[ai -repID*num].y : -1;
 				
 				for (int x = -1; x <= 1; ++x) {
 					for (int y = -1; y <= 1; ++y) {
-- 
GitLab