From 05ba86520f2112bf0ffc61ccb3b5af895359e00c Mon Sep 17 00:00:00 2001
From: Chris Maffeo <cmaffeo2@illinois.edu>
Date: Thu, 21 Jul 2022 17:15:30 -0500
Subject: [PATCH] Fix crashes caused by unneccesary updateParticleList call
 prior to RB attached particle update and improper initialization of atomic
 indicies for RB attached particles

---
 src/GrandBrownTown.cu | 28 ++++++++++++++--------------
 src/RigidBodyType.cu  |  2 +-
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/GrandBrownTown.cu b/src/GrandBrownTown.cu
index fe55aad..3f0fc8c 100644
--- a/src/GrandBrownTown.cu
+++ b/src/GrandBrownTown.cu
@@ -566,19 +566,20 @@ void GrandBrownTown::run()
     wkf_timer_start(timer0);
     wkf_timer_start(timerS);
 
-    if (fullLongRange == 0)
-    {
-        // cudaSetDevice(0);
-        internal->decompose();
-        gpuErrchk(cudaDeviceSynchronize());
-        #ifdef _OPENMP
-        omp_set_num_threads(4);
-        #endif
-        #pragma omp parallel for
-        for(int i = 0; i < numReplicas; ++i)
-            RBC[i]->updateParticleLists( (internal->getPos_d()[0])+i*(num+conf.num_rb_attached_particles), sys_d);
-        gpuErrchk(cudaDeviceSynchronize());
-    }
+    //// Happens at step 1 later anyway!
+    // if (fullLongRange == 0)
+    // {
+    //     // cudaSetDevice(0);
+    //     internal->decompose();
+    //     gpuErrchk(cudaDeviceSynchronize());
+    //     #ifdef _OPENMP
+    //     omp_set_num_threads(4);
+    //     #endif
+    //     #pragma omp parallel for
+    //     for(int i = 0; i < numReplicas; ++i)
+    //         RBC[i]->updateParticleLists( (internal->getPos_d()[0])+i*(num+conf.num_rb_attached_particles), sys_d);
+    //     gpuErrchk(cudaDeviceSynchronize());
+    // }
 
     float t; // simulation time
 
@@ -643,7 +644,6 @@ void GrandBrownTown::run()
                     switch (fullLongRange)
                     {
                         case 0: // [ N*log(N) ] interactions, + cutoff | decomposition
-                            if (s % decompPeriod == 0)
                             {
                                 // cudaSetDevice(0);
                                  internal -> decompose();
diff --git a/src/RigidBodyType.cu b/src/RigidBodyType.cu
index 2137160..45d9187 100644
--- a/src/RigidBodyType.cu
+++ b/src/RigidBodyType.cu
@@ -217,7 +217,7 @@ void RigidBodyType::initializeParticleLists() {
 			// Build temporary id array of type j particles
 			int tmp[conf->numPartsOfType[j]];
 			int currId = 0;
-			for (int aid = 0; aid < conf->num; ++aid) {
+			for (int aid = 0; aid < conf->num + conf->num_rb_attached_particles ; ++aid) {
 			    if (conf->type[aid] == j)
 				tmp[currId++] = aid;
 			}
-- 
GitLab