Skip to content

Commit 704fa37

Browse files
committed
Test for mutex synchronization across boundaries of parallel regions.
1 parent f9872de commit 704fa37

10 files changed

Lines changed: 295 additions & 0 deletions
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
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Point 0 :
2+
-79.9235
3+
-225.656
4+
423.421
5+
-257.64
6+
88.8672
7+
-1.00642e+06
8+
-56792.5
9+
6832.03
10+
-137972
11+
-56792.5
12+
135177
13+
-175415
14+
-1273.13
15+
6832.03
16+
-175415
17+
1.13859e+06
18+
221700
19+
-137972
20+
-1273.13
21+
221700
22+
38738.6
23+
Point 1 :
24+
-29.7063
25+
-877.013
26+
-1758.64
27+
-1586.99
28+
-263.202
29+
591567
30+
398157
31+
1045.24
32+
33867.3
33+
398157
34+
333866
35+
77951.1
36+
2956.49
37+
1045.24
38+
77951.1
39+
60099.2
40+
-130885
41+
33867.3
42+
2956.49
43+
-130885
44+
-364572
45+
Point 2 :
46+
28.3306
47+
-302.06
48+
100.675
49+
299.426
50+
683.226
51+
-971640
52+
-777217
53+
104.041
54+
-15939.8
55+
-777217
56+
-1.80055e+06
57+
-870470
58+
-2509.74
59+
104.041
60+
-870470
61+
-642711
62+
10825.4
63+
-15939.8
64+
-2509.74
65+
10825.4
66+
27787.9

tests/tests/TestLock2.hpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* OpDiLib, an Open Multiprocessing Differentiation Library
3+
*
4+
* Copyright (C) 2020-2022 Chair for Scientific Computing (SciComp), TU Kaiserslautern
5+
* Copyright (C) 2023-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
6+
* Homepage: https://scicomp.rptu.de
7+
* Contact: Prof. Nicolas R. Gauger (opdi@scicomp.uni-kl.de)
8+
*
9+
* Lead developer: Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
10+
*
11+
* This file is part of OpDiLib (https://scicomp.rptu.de/software/opdi).
12+
*
13+
* OpDiLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
14+
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
15+
* version.
16+
*
17+
* OpDiLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
18+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19+
* details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License along with OpDiLib. If not, see
22+
* <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
#pragma once
27+
28+
#include "testBase.hpp"
29+
30+
template<typename _Case>
31+
struct TestLock2 : public TestBase<4, 1, 3, TestLock2<_Case>> {
32+
public:
33+
using Case = _Case;
34+
using Base = TestBase<4, 1, 3, TestLock2<Case>>;
35+
36+
template<typename T>
37+
static void test(std::array<T, Base::nIn> const& in, std::array<T, Base::nOut>& out) {
38+
39+
int const N = 100;
40+
T* jobResults = new T[N];
41+
omp_lock_t lock1, lock2;
42+
INIT_LOCK(&lock1);
43+
INIT_LOCK(&lock2);
44+
45+
SET_LOCK(&lock1);
46+
47+
OPDI_PARALLEL()
48+
{
49+
int nThreads = omp_get_num_threads();
50+
int start = ((N - 1) / nThreads + 1) * omp_get_thread_num();
51+
int end = std::min(N, ((N - 1) / nThreads + 1) * (omp_get_thread_num() + 1));
52+
53+
if (omp_get_thread_num() != 0) {
54+
SET_LOCK(&lock1);
55+
}
56+
57+
for (int i = start; i < end; ++i) {
58+
Base::job1(i, in, jobResults[i]);
59+
out[0] += jobResults[i];
60+
}
61+
UNSET_LOCK(&lock1);
62+
63+
OPDI_BARRIER()
64+
65+
if (omp_get_thread_num() == 0) {
66+
SET_LOCK(&lock1);
67+
SET_LOCK(&lock2);
68+
}
69+
}
70+
OPDI_END_PARALLEL
71+
72+
UNSET_LOCK(&lock2);
73+
74+
OPDI_PARALLEL()
75+
{
76+
int nThreads = omp_get_num_threads();
77+
int start = ((N - 1) / nThreads + 1) * omp_get_thread_num();
78+
int end = std::min(N, ((N - 1) / nThreads + 1) * (omp_get_thread_num() + 1));
79+
80+
if (omp_get_thread_num() != 0) {
81+
SET_LOCK(&lock1);
82+
}
83+
84+
for (int i = start; i < end; ++i) {
85+
Base::job2(i, in, jobResults[i]);
86+
out[0] += jobResults[i];
87+
}
88+
UNSET_LOCK(&lock1);
89+
}
90+
OPDI_END_PARALLEL
91+
92+
DESTROY_LOCK(&lock1);
93+
DESTROY_LOCK(&lock2);
94+
95+
delete [] jobResults;
96+
}
97+
};

0 commit comments

Comments
 (0)