Browse code

prevent atomic from resizing and accessing at the same time

Tom Sherman authored on 21/06/2018 21:19:37
Showing4 changed files

... ...
@@ -79,6 +79,9 @@ private:
79 79
     Atom& _left(const Atom &atom);
80 80
     Atom& _right(const Atom &atom);
81 81
 
82
+    void erase(uint64_t pos);
83
+    Atom insert(uint64_t pos, float mass);
84
+
82 85
 public:
83 86
 
84 87
     void setDomainSize(uint64_t size) { mDomainSize = size; }
... ...
@@ -95,8 +98,6 @@ public:
95 98
     bool hasRight(const Atom &atom) const;
96 99
 
97 100
     // modify domain
98
-    Atom insert(uint64_t pos, float mass);
99
-    void erase(uint64_t pos);
100 101
     void cacheInsert(uint64_t pos, float mass) const;
101 102
     void cacheErase(uint64_t pos) const;
102 103
     void updateMass(uint64_t pos, float newMass);
... ...
@@ -41,6 +41,7 @@ GapsResult GapsDispatcher::run()
41 41
     if (mPrintMessages)
42 42
     {
43 43
         unsigned availableCores = omp_get_max_threads();
44
+        mNumCoresPerSet = std::min(availableCores, mNumCoresPerSet);
44 45
         gaps_printf("Running on %d out of %d available cores\n",
45 46
             mNumCoresPerSet, availableCores);
46 47
     }
... ...
@@ -300,14 +300,11 @@ unsigned col)
300 300
         : gaps::random::exponential(mLambda);
301 301
     if (mass >= gaps::algo::epsilon)
302 302
     {
303
-        mDomain.updateMass(pos, mass);
304
-        mMatrix(row, col) += mass;
305
-        impl()->updateAPMatrix(row, col, mass);
303
+        addMass(pos, mass, row, col);
306 304
         mQueue.acceptBirth();
307 305
     }
308 306
     else
309 307
     {
310
-        mDomain.cacheErase(pos);
311 308
         mQueue.rejectBirth();
312 309
     }
313 310
 }
... ...
@@ -136,7 +136,6 @@ bool ProposalQueue::birth(AtomicDomain &domain)
136 136
     mQueue.push_back(AtomicProposal('B', pos));
137 137
     mUsedIndices.insert(pos / mDimensionSize);
138 138
     mUsedPositions.insert(pos);
139
-    domain.insert(pos, 0.f);
140 139
     ++mMaxAtoms;
141 140
     return true;
142 141
 }