Skip to content

Commit 0ad658c

Browse files
committed
Shared reading optimization for safe global access macros.
1 parent d051de8 commit 0ad658c

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

Common/include/basic_types/ad_structure.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -546,18 +546,6 @@ FORCEINLINE void EndPassive(bool wasActive) {
546546
if (wasActive) AD::getTape().setActive();
547547
}
548548

549-
FORCEINLINE bool PausePreaccumulation() {
550-
const auto current = PreaccEnabled;
551-
if (!current) return false;
552-
SU2_OMP_SAFE_GLOBAL_ACCESS(PreaccEnabled = false;)
553-
return true;
554-
}
555-
556-
FORCEINLINE void ResumePreaccumulation(bool wasActive) {
557-
if (!wasActive) return;
558-
SU2_OMP_SAFE_GLOBAL_ACCESS(PreaccEnabled = true;)
559-
}
560-
561549
FORCEINLINE void StartNoSharedReading() {
562550
#ifdef HAVE_OPDI
563551
opdi::logic->setAdjointAccessMode(opdi::LogicInterface::AdjointAccessMode::Classical);
@@ -571,6 +559,19 @@ FORCEINLINE void EndNoSharedReading() {
571559
opdi::logic->addReverseBarrier();
572560
#endif
573561
}
562+
563+
FORCEINLINE bool PausePreaccumulation() {
564+
const auto current = PreaccEnabled;
565+
if (!current) return false;
566+
SU2_OMP_SAFE_GLOBAL_ACCESS(PreaccEnabled = false;)
567+
return true;
568+
}
569+
570+
FORCEINLINE void ResumePreaccumulation(bool wasActive) {
571+
if (!wasActive) return;
572+
SU2_OMP_SAFE_GLOBAL_ACCESS(PreaccEnabled = true;)
573+
}
574+
574575
#endif // CODI_REVERSE_TYPE
575576

576577
void Initialize();

Common/include/parallelization/omp_structure.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,16 @@ void omp_finalize();
188188
* thread, with all threads and memory views synchronized both beforehand and afterwards.
189189
*/
190190

191-
#define BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS \
192-
SU2_OMP_BARRIER \
191+
#define BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS \
192+
SU2_OMP_BARRIER \
193+
if (omp_in_parallel()) \
194+
AD::StartNoSharedReading(); \
193195
SU2_OMP_MASTER
194196

195-
#define END_SU2_OMP_SAFE_GLOBAL_ACCESS \
196-
END_SU2_OMP_MASTER \
197+
#define END_SU2_OMP_SAFE_GLOBAL_ACCESS \
198+
END_SU2_OMP_MASTER \
199+
if (omp_in_parallel()) \
200+
AD::EndNoSharedReading(); \
197201
SU2_OMP_BARRIER
198202

199203
#define SU2_OMP_SAFE_GLOBAL_ACCESS(...) BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS{__VA_ARGS__} END_SU2_OMP_SAFE_GLOBAL_ACCESS

0 commit comments

Comments
 (0)