Skip to content

Commit fec99df

Browse files
committed
Additional test for parallel + firstprivate.
1 parent 16d5836 commit fec99df

8 files changed

Lines changed: 265 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+
1.88564e+06
4+
-73796.7
5+
9419.23
6+
200020
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: 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
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 TestParallelFirstprivate2 : public TestBase<4, 1, 3, TestParallelFirstprivate2<_Case>> {
32+
public:
33+
using Case = _Case;
34+
using Base = TestBase<4, 1, 3, TestParallelFirstprivate2<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* jobResults = new T[N];
41+
42+
#ifndef BUILD_REFERENCE
43+
/* This workaround ensures that firstprivate copy operations that are missed by the correct tapes
44+
* are at least recorded on the default tapes so that they can be moved later. */
45+
bool active = T::getTape().isActive();
46+
#pragma omp parallel
47+
{
48+
if (active) {
49+
T::getTape().setActive();
50+
}
51+
}
52+
#endif
53+
54+
T helper = in[0] * in[1] * in[2] * in[3];
55+
56+
T::getTape().setPassive();
57+
OPDI_PARALLEL(firstprivate(helper))
58+
{
59+
int nThreads = omp_get_num_threads();
60+
int start = ((N - 1) / nThreads + 1) * omp_get_thread_num();
61+
int end = std::min(N, ((N - 1) / nThreads + 1) * (omp_get_thread_num() + 1));
62+
63+
for (int i = start; i < end; ++i) {
64+
Base::job1(i, in, jobResults[i]);
65+
jobResults[i] = sin(jobResults[i] * helper);
66+
}
67+
}
68+
OPDI_END_PARALLEL
69+
T::getTape().setActive();
70+
71+
OPDI_PARALLEL(firstprivate(helper))
72+
{
73+
int nThreads = omp_get_num_threads();
74+
int start = ((N - 1) / nThreads + 1) * omp_get_thread_num();
75+
int end = std::min(N, ((N - 1) / nThreads + 1) * (omp_get_thread_num() + 1));
76+
77+
for (int i = start; i < end; ++i) {
78+
Base::job1(i, in, jobResults[i]);
79+
jobResults[i] = sin(jobResults[i] * helper);
80+
}
81+
}
82+
OPDI_END_PARALLEL
83+
84+
85+
for (int i = 0; i < N; ++i) {
86+
out[0] += jobResults[i];
87+
}
88+
89+
delete [] jobResults;
90+
}
91+
};

0 commit comments

Comments
 (0)