Skip to content

Commit 4dd3fe6

Browse files
committed
Driver for tests with vector mode.
Adapt all drivers to not use atomics in serial parts. Merge branch 'feature/vectorModeTests' into develop
2 parents 62f6b5f + ded95d1 commit 4dd3fe6

70 files changed

Lines changed: 1322 additions & 5 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/drivers/DriverFirstOrderReverse.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#ifdef BUILD_REFERENCE
5151
using TestReal = codi::RealReverseIndex;
5252
#else
53-
using TestReal = codi::RealReverseIndexOpenMP;
53+
using TestReal = codi::RealReverseIndexOpenMPGen<double, double>;
5454

5555
OPDI_DECLARE_REDUCTION(+, TestReal, +, 0.0);
5656
OPDI_DECLARE_REDUCTION(*, TestReal, *, 1.0);

tests/drivers/DriverFirstOrderReverseNestedParallel.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#ifdef BUILD_REFERENCE
5151
using TestReal = codi::RealReverseIndex;
5252
#else
53-
using TestReal = codi::RealReverseIndexOpenMP;
53+
using TestReal = codi::RealReverseIndexOpenMPGen<double, double>;
5454

5555
OPDI_DECLARE_REDUCTION(+, TestReal, +, 0.0);
5656
OPDI_DECLARE_REDUCTION(*, TestReal, *, 1.0);

tests/drivers/DriverFirstOrderReverseNoOpenMP.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#ifdef BUILD_REFERENCE
5252
using TestReal = codi::RealReverseIndex;
5353
#else
54-
using TestReal = codi::RealReverseIndexOpenMP;
54+
using TestReal = codi::RealReverseIndexOpenMPGen<double, double>;
5555

5656
OPDI_DECLARE_REDUCTION(+, TestReal, +, 0.0);
5757
OPDI_DECLARE_REDUCTION(*, TestReal, *, 1.0);

tests/drivers/DriverFirstOrderReversePassive.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#ifdef BUILD_REFERENCE
5151
using TestReal = codi::RealReverseIndex;
5252
#else
53-
using TestReal = codi::RealReverseIndexOpenMP;
53+
using TestReal = codi::RealReverseIndexOpenMPGen<double, double>;
5454

5555
OPDI_DECLARE_REDUCTION(+, TestReal, +, 0.0);
5656
OPDI_DECLARE_REDUCTION(*, TestReal, *, 1.0);
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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 <array>
29+
#include <cstdlib>
30+
#include <iostream>
31+
32+
#include "codi.hpp"
33+
34+
#ifndef BUILD_REFERENCE
35+
#ifdef OPDI_USE_MACRO_BACKEND
36+
#include "opdi/backend/macro/macroBackend.hpp"
37+
#elif OPDI_USE_OMPT_BACKEND
38+
#include "opdi/backend/ompt/omptBackend.hpp"
39+
#endif
40+
#include "opdi.hpp"
41+
#ifdef OUTPUT_INSTRUMENT
42+
#include "opdi/logic/omp/instrument/ompLogicOutputInstrument.hpp"
43+
#endif
44+
#else
45+
#include "opdi/helpers/emptyMacros.hpp"
46+
#endif
47+
48+
#include "driverBase.hpp"
49+
50+
#ifdef BUILD_REFERENCE
51+
using TestReal = codi::RealReverseIndexVec<2>;
52+
#else
53+
using TestReal = codi::RealReverseIndexOpenMPGen<double, codi::Direction<double, 2>>;
54+
55+
OPDI_DECLARE_REDUCTION(+, TestReal, +, 0.0);
56+
OPDI_DECLARE_REDUCTION(*, TestReal, *, 1.0);
57+
#endif
58+
59+
template<typename _Case>
60+
struct DriverFirstOrderReverseVector : public DriverBase<DriverFirstOrderReverseVector<_Case> > {
61+
public:
62+
63+
using Case = _Case;
64+
65+
static void run() {
66+
67+
#ifndef BUILD_REFERENCE
68+
#ifdef OPDI_USE_MACRO_BACKEND
69+
opdi::backend = new opdi::MacroBackend();
70+
opdi::backend->init();
71+
#else
72+
if (omp_get_num_threads() /* trigger OMPT initialization */ && opdi::backend == nullptr) {
73+
std::cout << "Could not initialize OMPT backend. Please check OMPT support." << std::endl;
74+
exit(1);
75+
}
76+
#endif
77+
#ifdef OUTPUT_INSTRUMENT
78+
opdi::ompLogicInstruments.push_back(new opdi::OmpLogicOutputInstrument);
79+
#endif
80+
opdi::logic = new opdi::OmpLogic;
81+
opdi::logic->init();
82+
opdi::tool = new CoDiOpDiLibTool<TestReal>;
83+
opdi::tool->init();
84+
#endif
85+
86+
std::array<std::array<TestReal, Case::nIn>, Case::nPoints> inputs = Case::template genPoints<TestReal>();
87+
88+
for (int p = 0; p < Case::nPoints; ++p) {
89+
double jacobian[Case::nOut][Case::nIn][2];
90+
double primal[Case::nOut];
91+
92+
for (int o = 0; o < Case::nOut; ++o) {
93+
TestReal::Tape& tape = TestReal::getTape();
94+
95+
std::array<TestReal, Case::nOut> outputs = {0.0};
96+
97+
tape.setActive();
98+
99+
for (int i = 0; i < Case::nIn; ++i)
100+
tape.registerInput(inputs[p][i]);
101+
102+
Case::template test<TestReal>(inputs[p], outputs);
103+
104+
tape.registerOutput(outputs[o]);
105+
106+
tape.setPassive();
107+
108+
outputs[o].gradient()[0] = 1.0;
109+
outputs[o].gradient()[1] = 1.25;
110+
111+
#ifndef BUILD_REFERENCE
112+
opdi::logic->prepareEvaluate();
113+
#endif
114+
tape.evaluate();
115+
#ifndef BUILD_REFERENCE
116+
opdi::logic->postEvaluate();
117+
#endif
118+
119+
for (int i = 0; i < Case::nIn; ++i)
120+
{
121+
jacobian[o][i][0] = inputs[p][i].getGradient()[0];
122+
jacobian[o][i][1] = inputs[p][i].getGradient()[1];
123+
inputs[p][i].gradient()[0] = 0.0;
124+
inputs[p][i].gradient()[1] = 0.0;
125+
}
126+
127+
primal[o] = outputs[o].getValue();
128+
129+
tape.reset();
130+
#ifndef BUILD_REFERENCE
131+
opdi::logic->reset();
132+
#endif
133+
}
134+
135+
std::cout << "Point " << p << " :" << std::endl;
136+
for (int o = 0; o < Case::nOut; ++o)
137+
std::cout << primal[o] << std::endl;
138+
139+
for (int o = 0; o < Case::nOut; ++o) {
140+
for (int i = 0; i < Case::nIn; ++i) {
141+
std::cout << jacobian[o][i][0] << " " << jacobian[o][i][1] << std::endl;
142+
}
143+
}
144+
}
145+
146+
#ifndef BUILD_REFERENCE
147+
opdi::tool->finalize();
148+
opdi::logic->finalize();
149+
#ifdef OUTPUT_INSTRUMENT
150+
delete opdi::ompLogicInstruments.front();
151+
opdi::ompLogicInstruments.clear();
152+
#endif
153+
opdi::backend->finalize();
154+
#ifdef OPDI_USE_MACRO_BACKEND
155+
delete opdi::backend;
156+
#endif
157+
delete opdi::tool;
158+
delete opdi::logic;
159+
#endif
160+
}
161+
};
162+
163+
#ifndef BUILD_REFERENCE
164+
#include "opdi.cpp"
165+
#endif

tests/drivers/DriverSecondOrderReverseForward.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
using TestReal = codi::RealReverseIndexGen<codi::RealForward>;
5252
using NestedReal = codi::RealForward;
5353
#else
54-
using TestReal = codi::RealReverseIndexOpenMPGen<codi::RealForward>;
54+
using TestReal = codi::RealReverseIndexOpenMPGen<codi::RealForward, codi::RealForward>;
5555
using NestedReal = codi::RealForward;
5656

5757
OPDI_DECLARE_REDUCTION(+, TestReal, +, 0.0);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-69.2206
3+
4072.98 5091.22
4+
472.851 591.064
5+
-170.998 -213.747
6+
585.639 732.049
7+
Point 1 :
8+
-22.7172
9+
109.401 136.752
10+
1062.08 1327.6
11+
2075.01 2593.77
12+
3004.49 3755.61
13+
Point 2 :
14+
34.8275
15+
1304.3 1630.38
16+
-1893.89 -2367.36
17+
-2333.22 -2916.53
18+
-3903.51 -4879.39
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-69.2206
3+
4072.98 5091.22
4+
472.851 591.064
5+
-170.998 -213.747
6+
585.639 732.049
7+
Point 1 :
8+
-22.7172
9+
109.401 136.752
10+
1062.08 1327.6
11+
2075.01 2593.77
12+
3004.49 3755.61
13+
Point 2 :
14+
34.8275
15+
1304.3 1630.38
16+
-1893.89 -2367.36
17+
-2333.22 -2916.53
18+
-3903.51 -4879.39
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
-70.4151
3+
3091.49 3864.36
4+
382.947 478.684
5+
-307.231 -384.039
6+
413.529 516.911
7+
Point 1 :
8+
-20.7305
9+
-482.314 -602.893
10+
-117.294 -146.618
11+
1144.94 1431.18
12+
3279.1 4098.87
13+
Point 2 :
14+
36.6485
15+
2698.8 3373.51
16+
-3676.77 -4595.96
17+
-4553.23 -5691.54
18+
-6264.57 -7830.71
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Point 0 :
2+
43.7971
3+
-68441.7 -85552.1
4+
-108005 -135006
5+
451425 564282
6+
63930.5 79913.1
7+
Point 1 :
8+
26.3045
9+
3.17309e+06 3.96636e+06
10+
2.9848e+06 3.731e+06
11+
1.36585e+06 1.70731e+06
12+
1.10654e+06 1.38317e+06
13+
Point 2 :
14+
4.42991
15+
-2.35929e+06 -2.94911e+06
16+
2.68921e+06 3.36151e+06
17+
3.41815e+06 4.27269e+06
18+
1.85118e+06 2.31398e+06

0 commit comments

Comments
 (0)