Skip to content

Commit 3131ebe

Browse files
committed
Add test driver for primal code in the presence of OpDiLib.
1 parent 47b438a commit 3131ebe

60 files changed

Lines changed: 438 additions & 6 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/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,22 @@ DRIVER_FILES = $(wildcard $(DRIVER_DIR)/Driver**.hpp)
7979
DRIVERS ?= $(patsubst $(DRIVER_DIR)/Driver%.hpp,%,$(DRIVER_FILES))
8080

8181
# exclude specific tests on a per-driver basis
82-
DRIVERS_USING_ALL_TESTS = $(filter-out FirstOrderReverseNoParallel FirstOrderForward, $(DRIVERS))
82+
DRIVERS_USING_ALL_TESTS = $(filter-out FirstOrderReverseNoParallel FirstOrderForward Primal, $(DRIVERS))
8383
$(DRIVERS_USING_ALL_TESTS) $(patsubst %,run%,$(DRIVERS_USING_ALL_TESTS)): DRIVER_TESTS = $(TESTS)
8484

8585
# without surrounding parallel constructs, privatized variables are not recognized as shared and sections are considered orphaned; hence, they need to be filtered out
8686
FirstOrderReverseNoParallel runFirstOrderReverseNoParallel: DRIVER_TESTS = $(filter-out ParallelSections ForReduction ForReductionNowait ForReductionMultiple ForFirstprivate ForLastprivate OrderedReduction SectionsReduction SectionsReductionMultiple SectionsFirstprivate SectionsLastprivate ReductionNested SingleFirstprivate, $(TESTS))
8787

8888
FirstOrderForward runFirstOrderForward: DRIVER_TESTS = $(filter-out ExternalFunctionGlobal ExternalFunctionLocal ExternalFunctionLogicCalls ParallelFirstprivate2 StateExport TaskReset, $(TESTS))
8989

90+
Primal runPrimal: DRIVER_TESTS = $(filter-out ExternalFunctionGlobal ExternalFunctionLocal ExternalFunctionLogicCalls ParallelCopyin ParallelFirstprivate ParallelFirstprivate2 PreaccumulationGlobal PreaccumulationLocal StateExport TaskReset, $(TESTS))
91+
9092
# driver-specific compilation flags
9193
REVERSE_DRIVERS = FirstOrderReverse FirstOrderReverseNestedParallel FirstOrderReverseNoOpenMP FirstOrderReverseNoParallel FirstOrderReversePassive FirstOrderReverseSingleThread SecondOrderReverseForward
9294
$(REVERSE_DRIVERS): DRIVER_FLAGS = -DREVERSE_DRIVER
9395

9496
FirstOrderForward: DRIVER_FLAGS = -DFORWARD_DRIVER
97+
Primal: DRIVER_FLAGS = -DPRIMAL_DRIVER
9598

9699
# export directories for usage in shell scripts
97100
export DRIVER_DIR

tests/drivers/DriverPrimal.hpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 <cmath>
30+
#include <cstdlib>
31+
#include <iostream>
32+
33+
#ifndef BUILD_REFERENCE
34+
#ifdef OPDI_USE_MACRO_BACKEND
35+
#include "opdi/backend/macro/macroBackend.hpp"
36+
#elif OPDI_USE_OMPT_BACKEND
37+
#include "opdi/backend/ompt/omptBackend.hpp"
38+
#endif
39+
#include "opdi.hpp"
40+
#ifdef OUTPUT_INSTRUMENT
41+
#include "opdi/logic/omp/instrument/ompLogicOutputInstrument.hpp"
42+
#endif
43+
#else
44+
#include "opdi/helpers/emptyMacros.hpp"
45+
#endif
46+
47+
#include "driverBase.hpp"
48+
49+
using TestReal = double;
50+
51+
template<typename _Case>
52+
struct DriverPrimal : public DriverBase<DriverPrimal<_Case> > {
53+
public:
54+
55+
using Case = _Case;
56+
57+
static void run() {
58+
59+
#ifndef BUILD_REFERENCE
60+
#ifdef OPDI_USE_MACRO_BACKEND
61+
opdi::backend = new opdi::MacroBackend();
62+
opdi::backend->init();
63+
#else
64+
if (omp_get_num_threads() /* trigger OMPT initialization */ && opdi::backend == nullptr) {
65+
std::cout << "Could not initialize OMPT backend. Please check OMPT support." << std::endl;
66+
exit(1);
67+
}
68+
#endif
69+
#ifdef OUTPUT_INSTRUMENT
70+
opdi::ompLogicInstruments.push_back(new opdi::OmpLogicOutputInstrument);
71+
#endif
72+
opdi::logic = new opdi::OmpLogic;
73+
opdi::logic->init();
74+
assert(opdi::tool == nullptr); // tool == nullptr effectively deactivates OpDiLib
75+
#endif
76+
77+
std::array<std::array<TestReal, Case::nIn>, Case::nPoints> inputs = Case::template genPoints<TestReal>();
78+
79+
for (int p = 0; p < Case::nPoints; ++p) {
80+
std::array<TestReal, Case::nOut> outputs = {0.0};
81+
82+
Case::template test<TestReal>(inputs[p], outputs);
83+
84+
#ifndef BUILD_REFERENCE
85+
opdi::logic->reset();
86+
#endif
87+
88+
std::cout << "Point " << p << " :" << std::endl;
89+
for (int o = 0; o < Case::nOut; ++o)
90+
std::cout << outputs[o] << std::endl;
91+
}
92+
93+
#ifndef BUILD_REFERENCE
94+
assert(opdi::tool == nullptr);
95+
opdi::logic->finalize();
96+
#ifdef OUTPUT_INSTRUMENT
97+
delete opdi::ompLogicInstruments.front();
98+
opdi::ompLogicInstruments.clear();
99+
#endif
100+
opdi::backend->finalize();
101+
#ifdef OPDI_USE_MACRO_BACKEND
102+
delete opdi::backend;
103+
#endif
104+
delete opdi::logic;
105+
#endif
106+
}
107+
};
108+
109+
#ifndef BUILD_REFERENCE
110+
#include "opdi.cpp"
111+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Point 0 :
2+
-524.484
3+
Point 1 :
4+
-362.937
5+
Point 2 :
6+
398.524
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Point 0 :
2+
-524.484
3+
Point 1 :
4+
-362.937
5+
Point 2 :
6+
398.524
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Point 0 :
2+
-519.699
3+
Point 1 :
4+
-364.32
5+
Point 2 :
6+
409.667
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Point 0 :
2+
358.725
3+
Point 1 :
4+
298.759
5+
Point 2 :
6+
97.7815

tests/results/PrimalBarrier.ref

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Point 0 :
2+
595.487
3+
Point 1 :
4+
579.603
5+
Point 2 :
6+
309.709

tests/results/PrimalCritical.ref

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Point 0 :
2+
-348.826
3+
Point 1 :
4+
-336.432
5+
Point 2 :
6+
-38.4341
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Point 0 :
2+
-723.925
3+
Point 1 :
4+
-325.634
5+
Point 2 :
6+
237.233
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Point 0 :
2+
-723.925
3+
Point 1 :
4+
-325.634
5+
Point 2 :
6+
237.233

0 commit comments

Comments
 (0)