Skip to content

Commit efd802f

Browse files
committed
Add TestParallelCopyin.
Does not actually test copyin with gcc due to issues with gcc and threadprivate storage.
1 parent dba2032 commit efd802f

8 files changed

Lines changed: 266 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+
19.4044
3+
1.88152e+06
4+
-72463.7
5+
7448.71
6+
199533
7+
Point 1 :
8+
-22.677
9+
-2.57708e+06
10+
868308
11+
1.47639e+06
12+
-6.31777e+06
13+
Point 2 :
14+
-36.8071
15+
-805435
16+
-1.05138e+06
17+
-347778
18+
-1.36383e+06
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
19.4044
3+
1.88152e+06
4+
-72463.7
5+
7448.71
6+
199533
7+
Point 1 :
8+
-22.677
9+
-2.57708e+06
10+
868308
11+
1.47639e+06
12+
-6.31777e+06
13+
Point 2 :
14+
-36.8071
15+
-805435
16+
-1.05138e+06
17+
-347778
18+
-1.36383e+06
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
19.4044
3+
1.88152e+06
4+
-72463.7
5+
7448.71
6+
199533
7+
Point 1 :
8+
-22.677
9+
-2.57708e+06
10+
868308
11+
1.47639e+06
12+
-6.31777e+06
13+
Point 2 :
14+
-36.8071
15+
-805435
16+
-1.05138e+06
17+
-347778
18+
-1.36383e+06
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
19.4044
3+
1.88152e+06
4+
-72463.7
5+
7448.71
6+
199533
7+
Point 1 :
8+
-22.677
9+
-2.57708e+06
10+
868308
11+
1.47639e+06
12+
-6.31777e+06
13+
Point 2 :
14+
-36.8071
15+
-805435
16+
-1.05138e+06
17+
-347778
18+
-1.36383e+06
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
19.4044
3+
0
4+
0
5+
0
6+
0
7+
Point 1 :
8+
-22.677
9+
0
10+
0
11+
0
12+
0
13+
Point 2 :
14+
-36.8071
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+
19.4044
3+
1.88152e+06
4+
-72463.7
5+
7448.71
6+
199533
7+
Point 1 :
8+
-22.677
9+
-2.57708e+06
10+
868308
11+
1.47639e+06
12+
-6.31777e+06
13+
Point 2 :
14+
-36.8071
15+
-805435
16+
-1.05138e+06
17+
-347778
18+
-1.36383e+06
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Point 0 :
2+
19.4044
3+
1.88152e+06
4+
-72463.7
5+
7448.71
6+
199533
7+
4.02526e+11
8+
2.14272e+10
9+
-1.98601e+08
10+
5.54211e+10
11+
2.14272e+10
12+
1.98987e+10
13+
-3.9659e+10
14+
4.08807e+07
15+
-1.98601e+08
16+
-3.9659e+10
17+
-3.70314e+11
18+
-1.06155e+11
19+
5.54211e+10
20+
4.08807e+07
21+
-1.06155e+11
22+
-1.96777e+10
23+
Point 1 :
24+
-22.677
25+
-2.57708e+06
26+
868308
27+
1.47639e+06
28+
-6.31777e+06
29+
7.97486e+13
30+
5.90564e+13
31+
-1.59932e+10
32+
-1.95169e+13
33+
5.90564e+13
34+
-3.66321e+13
35+
-9.71445e+13
36+
-2.74306e+10
37+
-1.59932e+10
38+
-9.71445e+13
39+
-1.21982e+14
40+
1.50526e+12
41+
-1.95169e+13
42+
-2.74306e+10
43+
1.50526e+12
44+
-5.32054e+13
45+
Point 2 :
46+
-36.8071
47+
-805435
48+
-1.05138e+06
49+
-347778
50+
-1.36383e+06
51+
3.23993e+11
52+
2.59107e+11
53+
1.16115e+08
54+
2.57334e+09
55+
2.59107e+11
56+
-7.9721e+11
57+
-7.41862e+11
58+
5.11865e+08
59+
1.16115e+08
60+
-7.41862e+11
61+
-5.48368e+11
62+
-9.78774e+09
63+
2.57334e+09
64+
5.11865e+08
65+
-9.78774e+09
66+
-2.52369e+11

tests/tests/TestParallelCopyin.hpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 TestParallelCopyin : public TestBase<4, 1, 3, TestParallelCopyin<_Case>> {
32+
public:
33+
using Case = _Case;
34+
using Base = TestBase<4, 1, 3, TestParallelCopyin<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+
/* gcc refuses to compile this, so copyin is actually not tested with gcc right now */
40+
static T helper;
41+
#if !defined(__GNUC__) || defined(__clang__)
42+
#if _OPENMP
43+
#pragma omp threadprivate(helper)
44+
#endif
45+
#endif
46+
47+
int const N = 1000;
48+
T* jobResults = new T[N];
49+
50+
#ifndef BUILD_REFERENCE
51+
/* Set activity of default tapes. They might record copy operations due to firstprivate. OpDiLib's AD approach
52+
* for parallel regions moves these recordings to the correct tapes. */
53+
if (T::getTape().isActive()) {
54+
opdi::logic->beginSkippedParallelRegion();
55+
OPDI_PARALLEL()
56+
{
57+
/* due to skipping, OpDiLib has not exchanged the tapes */
58+
if (omp_get_thread_num() != 0) {
59+
T::getTape().setActive();
60+
}
61+
}
62+
OPDI_END_PARALLEL
63+
opdi::logic->endSkippedParallelRegion();
64+
}
65+
#endif
66+
67+
helper = in[0] * in[1] * in[2] * in[3];
68+
69+
#if !defined(__GNUC__) || defined(__clang__)
70+
OPDI_PARALLEL(copyin(helper))
71+
#else
72+
OPDI_PARALLEL(firstprivate(helper))
73+
#endif
74+
{
75+
int nThreads = omp_get_num_threads();
76+
int start = ((N - 1) / nThreads + 1) * omp_get_thread_num();
77+
int end = std::min(N, ((N - 1) / nThreads + 1) * (omp_get_thread_num() + 1));
78+
79+
for (int i = start; i < end; ++i) {
80+
Base::job1(i, in, jobResults[i]);
81+
jobResults[i] = sin(jobResults[i] * helper);
82+
}
83+
}
84+
OPDI_END_PARALLEL
85+
86+
for (int i = 0; i < N; ++i) {
87+
out[0] += jobResults[i];
88+
}
89+
90+
delete [] jobResults;
91+
}
92+
};

0 commit comments

Comments
 (0)