Skip to content

Commit fedfaed

Browse files
committed
Add test case.
1 parent 398d974 commit fedfaed

9 files changed

Lines changed: 310 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+
358.725
3+
7.3232e+07
4+
-3.09295e+07
5+
8.1604e+07
6+
1.74782e+07
7+
Point 1 :
8+
298.759
9+
-9.18313e+07
10+
-6.69257e+07
11+
9.5149e+06
12+
4.98709e+07
13+
Point 2 :
14+
97.7815
15+
-8.88214e+07
16+
-8.42372e+07
17+
-1.5157e+07
18+
-1.5929e+08
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
358.725
3+
7.3232e+07
4+
-3.09295e+07
5+
8.1604e+07
6+
1.74782e+07
7+
Point 1 :
8+
298.759
9+
-9.18313e+07
10+
-6.69257e+07
11+
9.5149e+06
12+
4.98709e+07
13+
Point 2 :
14+
97.7815
15+
-8.88214e+07
16+
-8.42372e+07
17+
-1.5157e+07
18+
-1.5929e+08
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
358.725
3+
7.3232e+07
4+
-3.09295e+07
5+
8.1604e+07
6+
1.74782e+07
7+
Point 1 :
8+
298.759
9+
-9.18313e+07
10+
-6.69257e+07
11+
9.5149e+06
12+
4.98709e+07
13+
Point 2 :
14+
97.7815
15+
-8.88214e+07
16+
-8.42372e+07
17+
-1.5157e+07
18+
-1.5929e+08
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
358.725
3+
7.3232e+07
4+
-3.09295e+07
5+
8.1604e+07
6+
1.74782e+07
7+
Point 1 :
8+
298.759
9+
-9.18313e+07
10+
-6.69257e+07
11+
9.5149e+06
12+
4.98709e+07
13+
Point 2 :
14+
97.7815
15+
-8.88214e+07
16+
-8.42372e+07
17+
-1.5157e+07
18+
-1.5929e+08
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
358.725
3+
0
4+
0
5+
0
6+
0
7+
Point 1 :
8+
298.759
9+
0
10+
0
11+
0
12+
0
13+
Point 2 :
14+
97.7815
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+
358.725
3+
7.3232e+07
4+
-3.09295e+07
5+
8.1604e+07
6+
1.74782e+07
7+
Point 1 :
8+
298.759
9+
-9.18313e+07
10+
-6.69257e+07
11+
9.5149e+06
12+
4.98709e+07
13+
Point 2 :
14+
97.7815
15+
-8.88214e+07
16+
-8.42372e+07
17+
-1.5157e+07
18+
-1.5929e+08
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Point 0 :
2+
358.725
3+
7.3232e+07
4+
-3.09295e+07
5+
8.1604e+07
6+
1.74782e+07
7+
3.23667e+15
8+
-6.89266e+14
9+
-3.74743e+14
10+
3.95997e+13
11+
-6.89266e+14
12+
1.06737e+15
13+
-1.31081e+15
14+
-1.44427e+13
15+
-3.74743e+14
16+
-1.31081e+15
17+
1.58106e+15
18+
-1.34562e+14
19+
3.95997e+13
20+
-1.44427e+13
21+
-1.34562e+14
22+
-3.38245e+13
23+
Point 1 :
24+
298.759
25+
-9.18313e+07
26+
-6.69257e+07
27+
9.5149e+06
28+
4.98709e+07
29+
-1.13983e+16
30+
-1.17314e+16
31+
-4.72351e+15
32+
7.88174e+14
33+
-1.17314e+16
34+
-1.34429e+16
35+
-6.5916e+15
36+
7.78496e+14
37+
-4.72351e+15
38+
-6.5916e+15
39+
-4.68849e+15
40+
-1.60599e+15
41+
7.88174e+14
42+
7.78496e+14
43+
-1.60599e+15
44+
-6.6297e+15
45+
Point 2 :
46+
97.7815
47+
-8.88214e+07
48+
-8.42372e+07
49+
-1.5157e+07
50+
-1.5929e+08
51+
7.60234e+14
52+
-2.49536e+15
53+
-2.28618e+15
54+
3.35879e+14
55+
-2.49536e+15
56+
-1.87544e+15
57+
1.02547e+14
58+
3.51518e+14
59+
-2.28618e+15
60+
1.02547e+14
61+
1.43712e+15
62+
1.91039e+14
63+
3.35879e+14
64+
3.51518e+14
65+
1.91039e+14
66+
3.91972e+15

tests/tests/TestAdjointAccessControlNested.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ struct TestAdjointAccessControlNested : public TestBase<4, 1, 3, TestAdjointAcce
9191
for (int j = innerStart; j < innerEnd; ++j) {
9292
c[j] = sin(exp(c[j]));
9393
}
94+
95+
// adjoint access mode identical at start and end of nested parallel region
9496
}
9597
OPDI_END_PARALLEL
9698

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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-2024 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 TestAdjointAccessControlNested2 : public TestBase<4, 1, 3, TestAdjointAccessControlNested2<_Case>> {
32+
public:
33+
using Case = _Case;
34+
using Base = TestBase<4, 1, 3, TestAdjointAccessControlNested2<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 = 1000;
40+
T* a = new T[N];
41+
T* b = new T[N];
42+
T* c = new T[N];
43+
44+
OPDI_PARALLEL()
45+
{
46+
int outerNThreads = omp_get_num_threads();
47+
int outerStart = ((N - 1) / outerNThreads + 1) * omp_get_thread_num();
48+
int outerEnd = std::min(N, ((N - 1) / outerNThreads + 1) * (omp_get_thread_num() + 1));
49+
50+
// shared reading of in
51+
for (int i = outerStart; i < outerEnd; ++i) {
52+
Base::job1(i, in, a[i]);
53+
}
54+
55+
#if _OPENMP
56+
opdi::logic->setAdjointAccessMode(opdi::LogicInterface::AdjointAccessMode::Classical);
57+
#endif
58+
59+
// no shared reading
60+
for (int i = outerStart; i < outerEnd; ++i) {
61+
b[i] = sin(exp(a[i]));
62+
}
63+
64+
OPDI_BARRIER()
65+
66+
OPDI_PARALLEL()
67+
{
68+
int innerNThreads = omp_get_num_threads();
69+
int innerStart = outerStart + (((outerEnd - outerStart) - 1) / innerNThreads + 1) * omp_get_thread_num();
70+
int innerEnd = std::min(outerEnd, outerStart + (((outerEnd - outerStart) - 1) / innerNThreads + 1)
71+
* (omp_get_thread_num() + 1));
72+
73+
#if _OPENMP
74+
opdi::logic->setAdjointAccessMode(opdi::LogicInterface::AdjointAccessMode::Atomic);
75+
#endif
76+
77+
// shared reading on a
78+
for (int j = innerStart; j < innerEnd; ++j) {
79+
T arg = b[j];
80+
for (int k = 0; k < 10; ++k) {
81+
arg += a[(j + k) % N];
82+
}
83+
c[j] = cos(arg);
84+
}
85+
86+
// atomic adjoint access mode to be transported out of the nested parallel region
87+
}
88+
OPDI_END_PARALLEL
89+
90+
// shared reading on a
91+
for (int i = outerStart; i < outerEnd; ++i) {
92+
T arg = c[i];
93+
for (int k = 0; k < 10; ++k) {
94+
arg += sin(exp(a[(i + k) % N]));
95+
}
96+
c[i] += arg;
97+
}
98+
99+
#if _OPENMP
100+
opdi::logic->setAdjointAccessMode(opdi::LogicInterface::AdjointAccessMode::Classical);
101+
opdi::logic->addReverseBarrier();
102+
#endif
103+
104+
// no shared reading
105+
for (int i = outerStart; i < outerEnd; ++i) {
106+
c[i] += sin(exp(c[i]));
107+
}
108+
109+
#if _OPENMP
110+
opdi::logic->setAdjointAccessMode(opdi::LogicInterface::AdjointAccessMode::Atomic);
111+
opdi::logic->addReverseBarrier();
112+
#endif
113+
114+
// shared reading on a
115+
for (int i = outerStart; i < outerEnd; ++i) {
116+
T arg = c[i];
117+
for (int j = 0; j < 10; ++j) {
118+
arg += a[(i + j) % N];
119+
}
120+
c[i] = cos(arg);
121+
}
122+
123+
}
124+
OPDI_END_PARALLEL
125+
126+
for (int i = 0; i < N; ++i) {
127+
out[0] += c[i];
128+
}
129+
130+
delete [] a;
131+
delete [] b;
132+
delete [] c;
133+
}
134+
};

0 commit comments

Comments
 (0)