Skip to content

Commit d805975

Browse files
committed
Small updates regarding mutex synchronization.
Unify waitDeleteFunc, decrementDeleteFunc. Add assertion. Test for mutex synchronization across parallel regions. Merge branch 'revisit/mutexSynchronization' into develop
2 parents 744b28c + 704fa37 commit d805975

12 files changed

Lines changed: 312 additions & 14 deletions

include/opdi/logic/omp/mutexOmpLogic.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ void opdi::MutexOmpLogic::waitReverseFunc(void* dataPtr) {
7373
#endif
7474
}
7575

76-
void opdi::MutexOmpLogic::waitDeleteFunc(void* dataPtr) {
77-
Data* data = static_cast<Data*>(dataPtr);
78-
delete data;
79-
}
80-
8176
void opdi::MutexOmpLogic::decrementReverseFunc(void* dataPtr) {
8277

8378
Data* data = static_cast<Data*>(dataPtr);
@@ -87,8 +82,18 @@ void opdi::MutexOmpLogic::decrementReverseFunc(void* dataPtr) {
8782
#endif
8883

8984
// decrement counter
90-
#pragma omp atomic update
91-
MutexOmpLogic::evaluationCounters[data->mutexKind][data->waitId] -= 1;
85+
#ifdef NDEBUG
86+
#pragma omp atomic update
87+
MutexOmpLogic::evaluationCounters[data->mutexKind][data->waitId] -= 1;
88+
#else
89+
Counter newValue;
90+
#pragma omp atomic capture
91+
{
92+
MutexOmpLogic::evaluationCounters[data->mutexKind][data->waitId] -= 1;
93+
newValue = MutexOmpLogic::evaluationCounters[data->mutexKind][data->waitId];
94+
}
95+
assert(newValue == data->counter);
96+
#endif
9297

9398
#if OPDI_OMP_LOGIC_INSTRUMENT
9499
for (auto& instrument : ompLogicInstruments) {
@@ -97,7 +102,7 @@ void opdi::MutexOmpLogic::decrementReverseFunc(void* dataPtr) {
97102
#endif
98103
}
99104

100-
void opdi::MutexOmpLogic::decrementDeleteFunc(void* dataPtr) {
105+
void opdi::MutexOmpLogic::deleteFunc(void* dataPtr) {
101106
Data* data = static_cast<Data*>(dataPtr);
102107
delete data;
103108
}
@@ -151,7 +156,7 @@ void opdi::MutexOmpLogic::onMutexAcquired(MutexKind mutexKind, WaitId waitId) {
151156
data->waitId = waitId;
152157

153158
omp_set_lock(&recordings[mutexKind].lock);
154-
data->counter = recordings[mutexKind].counters[waitId]++;
159+
data->counter = recordings[mutexKind].counters[waitId]++; // store value prior to increment
155160
localCounters[mutexKind][waitId] = recordings[mutexKind].counters[waitId]; // remember incremented counter value for the release event
156161
omp_unset_lock(&recordings[mutexKind].lock);
157162

@@ -165,7 +170,7 @@ void opdi::MutexOmpLogic::onMutexAcquired(MutexKind mutexKind, WaitId waitId) {
165170
Handle* handle = new Handle;
166171
handle->data = static_cast<void*>(data);
167172
handle->reverseFunc = MutexOmpLogic::decrementReverseFunc;
168-
handle->deleteFunc = MutexOmpLogic::decrementDeleteFunc;
173+
handle->deleteFunc = MutexOmpLogic::deleteFunc;
169174

170175
tool->pushExternalFunction(tool->getThreadLocalTape(), handle);
171176
}
@@ -206,7 +211,7 @@ void opdi::MutexOmpLogic::onMutexReleased(MutexKind mutexKind, WaitId waitId) {
206211
Handle* handle = new Handle;
207212
handle->data = static_cast<void*>(data);
208213
handle->reverseFunc = MutexOmpLogic::waitReverseFunc;
209-
handle->deleteFunc = MutexOmpLogic::waitDeleteFunc;
214+
handle->deleteFunc = MutexOmpLogic::deleteFunc;
210215

211216
tool->pushExternalFunction(tool->getThreadLocalTape(), handle);
212217
}

include/opdi/logic/omp/mutexOmpLogic.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@ namespace opdi {
8989
void checkKind(MutexKind mutexKind);
9090

9191
static void waitReverseFunc(void* dataPtr);
92-
static void waitDeleteFunc(void* dataPtr);
93-
9492
static void decrementReverseFunc(void* dataPtr);
95-
static void decrementDeleteFunc(void* dataPtr);
93+
static void deleteFunc(void* dataPtr);
9694

9795
protected:
9896

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-79.9235
3+
-225.656
4+
423.421
5+
-257.64
6+
88.8672
7+
Point 1 :
8+
-29.7063
9+
-877.013
10+
-1758.64
11+
-1586.99
12+
-263.202
13+
Point 2 :
14+
28.3306
15+
-302.06
16+
100.675
17+
299.426
18+
683.226
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-79.9235
3+
-225.656
4+
423.421
5+
-257.64
6+
88.8672
7+
Point 1 :
8+
-29.7063
9+
-877.013
10+
-1758.64
11+
-1586.99
12+
-263.202
13+
Point 2 :
14+
28.3306
15+
-302.06
16+
100.675
17+
299.426
18+
683.226
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-79.9235
3+
-225.656
4+
423.421
5+
-257.64
6+
88.8672
7+
Point 1 :
8+
-29.7063
9+
-877.013
10+
-1758.64
11+
-1586.99
12+
-263.202
13+
Point 2 :
14+
28.3306
15+
-302.06
16+
100.675
17+
299.426
18+
683.226
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-79.9235
3+
-225.656
4+
423.421
5+
-257.64
6+
88.8672
7+
Point 1 :
8+
-29.7063
9+
-877.013
10+
-1758.64
11+
-1586.99
12+
-263.202
13+
Point 2 :
14+
28.3306
15+
-302.06
16+
100.675
17+
299.426
18+
683.226
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-79.9235
3+
-225.656
4+
423.421
5+
-257.64
6+
88.8672
7+
Point 1 :
8+
-29.7063
9+
-877.013
10+
-1758.64
11+
-1586.99
12+
-263.202
13+
Point 2 :
14+
28.3306
15+
-302.06
16+
100.675
17+
299.426
18+
683.226
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-79.9235
3+
0
4+
0
5+
0
6+
0
7+
Point 1 :
8+
-29.7063
9+
0
10+
0
11+
0
12+
0
13+
Point 2 :
14+
28.3306
15+
0
16+
0
17+
0
18+
0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-79.9235
3+
-225.656
4+
423.421
5+
-257.64
6+
88.8672
7+
Point 1 :
8+
-29.7063
9+
-877.013
10+
-1758.64
11+
-1586.99
12+
-263.202
13+
Point 2 :
14+
28.3306
15+
-302.06
16+
100.675
17+
299.426
18+
683.226

tests/results/PrimalLock2.ref

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Point 0 :
2+
-79.9235
3+
Point 1 :
4+
-29.7063
5+
Point 2 :
6+
28.3306

0 commit comments

Comments
 (0)