Skip to content

Commit 57611ae

Browse files
committed
OpDiLib release v1.7
Restructure data of parallel regions and implicit tasks - associate tapes, positions, and adjoint access modes with tasks instead of parallel regions - extend data of parallel regions by pointers to the parent task and child tasks - backend support for querying the current task's data - create task data for initial implicit tasks - track adjoint access mode entirely via tasks - support resetting tasks according to a tape position, to recover previous adjoint access modes Features - track adjoint access mode of initial implicit task - support additional sync region and worksharing types - support use of mutexes before tool initialization (OMPT backend) - support posting messages that are printed during the reverse pass Instrument - implement onSetAdjointAccessMode in OmpLogicOutputInstrument - adapt OmpLogicInstrumentInterface and OmpLogicOutputInstrument according to the other changes Tests - run build tests with enabled output instrument - tests treat non-empty output on stderr as error (can be disabled) - add tests' error output files to gitignore - add assertions to adjoint access control tests - add TestAdjointAccessControlNested2, TestTaskReset Fixes - fix transport of adjoint access mode into and out of parallel regions - fix using directive in second order test driver - fix placement of skipParallelHandling decrement Chore - update license headers for 2025 - update OpDiLib-related publications in README Merge branch 'develop'
2 parents 8d80a38 + 2d9f155 commit 57611ae

141 files changed

Lines changed: 1350 additions & 397 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.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
**/*.out
2+
**/*.err

.gitlab-ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,16 @@ test-clang-ompt:
3939
- export BACKEND=OMPT
4040
- make all
4141

42+
test-output:
43+
image: ubuntu:22.04
44+
timeout: 2h
45+
script:
46+
- apt update && apt install -y build-essential binutils git
47+
- git clone --depth 1 --branch develop https://github.com/SciCompKL/CoDiPack.git
48+
- export CODI_DIR=$(pwd)/CoDiPack/include
49+
- export OPDI_DIR=$(pwd)/include
50+
- cd tests
51+
- export CXX=g++
52+
- export OUTPUT_INSTRUMENT=yes
53+
- export STDERR_OUTPUT_IS_ERROR=no
54+
- make all

README.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,48 @@ If you have a code that is differentiated with a serial AD tool and parallelize
2323
2. **Obtain a first parallel differentiated version of your code.** If your compiler supports OMPT, it suffices to add a few lines of code for the initialization and finalization of OpDiLib. Otherwise, you have to use OpDiLib's macro backend, which involves rewriting your OpenMP constructs according to OpDiLib's macro interface. Both approaches are demonstrated in the minimal example below.
2424
3. **Optimize the performance of the parallel reverse pass.** Check your parallel forward code for parts that do not involve shared reading. Use OpDiLib's adjoint access control tools to disable atomic adjoints for these parts. You may also revise your data access patterns to eliminate additional instances of shared reading.
2525

26-
## Publication
26+
## Publications
2727

28-
For further details about OpDiLib's design, features and modes of operation, please refer to our publication
28+
For further details about OpDiLib's design, features, and modes of operation, please refer to our publication
2929
[Event-Based Automatic Differentiation of OpenMP with OpDiLib](https://doi.org/10.1145/3570159).
30-
If you use OpDiLib in one of your applications and write a paper, please cite us!
3130

3231
~~~~{.txt}
3332
@article{BluehdornSG2023,
34-
author = {Bl\"{u}hdorn, Johannes and Sagebaum, Max and Gauger, Nicolas R.},
3533
title = {{Event-Based Automatic Differentiation of OpenMP with OpDiLib}},
34+
author = {Bl\"{u}hdorn, Johannes and Sagebaum, Max and Gauger, Nicolas R.},
3635
year = {2023},
37-
issue_date = {March 2023},
38-
publisher = {Association for Computing Machinery},
39-
address = {New York, NY, USA},
36+
month = {03},
37+
journal = {ACM Trans. Math. Softw.},
4038
volume = {49},
4139
number = {1},
42-
url = {https://doi.org/10.1145/3570159},
43-
doi = {10.1145/3570159},
44-
journal = {ACM Trans. Math. Softw.},
45-
month = {mar},
46-
articleno = {3},
47-
numpages = {31}
40+
note = {Article No.: 3},
41+
pages = {1--31},
42+
publisher = {Association for Computing Machinery},
43+
address = {New York, NY, USA},
44+
doi = {10.1145/3570159}
45+
}
46+
~~~~
47+
48+
Additional details on applying OpDiLib in a large software with an advanced AD workflow are given in our publication
49+
[Hybrid parallel discrete adjoints in SU2](https://doi.org/10.1016/j.compfluid.2024.106528).
50+
51+
~~~~{.txt}
52+
@article{BluehdornGAG2025,
53+
title = {Hybrid parallel discrete adjoints in {SU2}},
54+
author = {Bl\"{u}hdorn, Johannes and Gomes, Pedro and Aehle, Max and Gauger, Nicolas R.},
55+
year = {2025},
56+
month = {01},
57+
journal = {Computers & Fluids},
58+
volume = {289},
59+
note = {Article 106528},
60+
pages = {1--18},
61+
publisher = {Elsevier},
62+
doi = {10.1016/j.compfluid.2024.106528}
4863
}
4964
~~~~
5065

66+
If you use OpDiLib in one of your applications and write a paper, please cite us!
67+
5168
## Minimal Example
5269

5370
The following minimal example assumes that [CoDiPack](https://scicomp.rptu.de/software/codi/) is used as the underlying AD tool. You need CoDiPack [version 2.1](https://github.com/SciCompKL/CoDiPack/releases/tag/v2.1.0) or newer. For additional examples, please refer to OpDiLib's test suite.

include/opdi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OpDiLib, an Open Multiprocessing Differentiation Library
33
*
44
* 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
5+
* Copyright (C) 2023-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
66
* Homepage: https://scicomp.rptu.de
77
* Contact: Prof. Nicolas R. Gauger (opdi@scicomp.uni-kl.de)
88
*

include/opdi.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OpDiLib, an Open Multiprocessing Differentiation Library
33
*
44
* 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
5+
* Copyright (C) 2023-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
66
* Homepage: https://scicomp.rptu.de
77
* Contact: Prof. Nicolas R. Gauger (opdi@scicomp.uni-kl.de)
88
*

include/opdi/backend/backendInterface.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OpDiLib, an Open Multiprocessing Differentiation Library
33
*
44
* 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
5+
* Copyright (C) 2023-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
66
* Homepage: https://scicomp.rptu.de
77
* Contact: Prof. Nicolas R. Gauger (opdi@scicomp.uni-kl.de)
88
*
@@ -42,6 +42,9 @@ namespace opdi {
4242
virtual std::size_t getNestedLockIdentifier(omp_nest_lock_t* lock) = 0;
4343

4444
virtual void* getParallelData() = 0;
45+
virtual void* getTaskData() = 0;
46+
47+
virtual void setInitialImplicitTaskData(void* data) = 0;
4548
};
4649

4750
extern BackendInterface* backend;

include/opdi/backend/macro/dataTools.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OpDiLib, an Open Multiprocessing Differentiation Library
33
*
44
* 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
5+
* Copyright (C) 2023-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
66
* Homepage: https://scicomp.rptu.de
77
* Contact: Prof. Nicolas R. Gauger (opdi@scicomp.uni-kl.de)
88
*
@@ -34,6 +34,9 @@ namespace opdi {
3434
static std::stack<void*> parallelData;
3535
#pragma omp threadprivate(parallelData)
3636

37+
static std::stack<void*> taskData;
38+
#pragma omp threadprivate(taskData)
39+
3740
public:
3841
static void pushParallelData(void* parallelData) {
3942
DataTools::parallelData.push(parallelData);
@@ -50,5 +53,21 @@ namespace opdi {
5053

5154
return DataTools::parallelData.top();
5255
}
56+
57+
static void pushTaskData(void* taskData) {
58+
DataTools::taskData.push(taskData);
59+
}
60+
61+
static void popTaskData() {
62+
DataTools::taskData.pop();
63+
}
64+
65+
static void* getTaskData() {
66+
if (DataTools::taskData.empty()) {
67+
return nullptr;
68+
}
69+
70+
return DataTools::taskData.top();
71+
}
5372
};
5473
}

include/opdi/backend/macro/implicitBarrierTools.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OpDiLib, an Open Multiprocessing Differentiation Library
33
*
44
* 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
5+
* Copyright (C) 2023-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
66
* Homepage: https://scicomp.rptu.de
77
* Contact: Prof. Nicolas R. Gauger (opdi@scicomp.uni-kl.de)
88
*

include/opdi/backend/macro/macroBackend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OpDiLib, an Open Multiprocessing Differentiation Library
33
*
44
* 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
5+
* Copyright (C) 2023-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
66
* Homepage: https://scicomp.rptu.de
77
* Contact: Prof. Nicolas R. Gauger (opdi@scicomp.uni-kl.de)
88
*
@@ -30,6 +30,7 @@
3030
// static macro backend members
3131

3232
std::stack<void*> opdi::DataTools::parallelData;
33+
std::stack<void*> opdi::DataTools::taskData;
3334

3435
std::stack<bool> opdi::ImplicitBarrierTools::implicitBarrierStack;
3536

include/opdi/backend/macro/macroBackend.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OpDiLib, an Open Multiprocessing Differentiation Library
33
*
44
* 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
5+
* Copyright (C) 2023-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
66
* Homepage: https://scicomp.rptu.de
77
* Contact: Prof. Nicolas R. Gauger (opdi@scicomp.uni-kl.de)
88
*
@@ -25,6 +25,8 @@
2525

2626
#pragma once
2727

28+
#include <cassert>
29+
2830
#include "../../config.hpp"
2931

3032
#ifdef OPDI_BACKEND
@@ -57,9 +59,15 @@ namespace opdi {
5759

5860
void init() {
5961
opdi_init_lock(&ReductionTools::globalReducerLock);
62+
63+
// task data for initial implicit task is created in the logic layer
6064
}
6165

6266
void finalize() {
67+
// pop task data associated with initial implicit task
68+
DataTools::popTaskData();
69+
assert(DataTools::getTaskData() == nullptr);
70+
6371
opdi_set_lock(&ReductionTools::globalReducerLock);
6472

6573
for (auto lock : ReductionTools::individualReducerLocks) {
@@ -74,6 +82,15 @@ namespace opdi {
7482
void* getParallelData() {
7583
return DataTools::getParallelData();
7684
}
85+
86+
void* getTaskData() {
87+
return DataTools::getTaskData();
88+
}
89+
90+
void setInitialImplicitTaskData(void* data) {
91+
assert(DataTools::getTaskData() == nullptr);
92+
DataTools::pushTaskData(data);
93+
}
7794
};
7895

7996
}

0 commit comments

Comments
 (0)