@@ -252,7 +252,7 @@ namespace AD{
252252
253253 /* !
254254 * \brief Start a passive region, i.e. stop recording.
255- * \return True is tape was active.
255+ * \return True if tape was active.
256256 */
257257 inline bool BeginPassive () { return false ; }
258258
@@ -262,6 +262,28 @@ namespace AD{
262262 */
263263 inline void EndPassive (bool wasActive) {}
264264
265+ /* !
266+ * \brief Pause the use of preaccumulation.
267+ * \return True if preaccumulation was active.
268+ */
269+ inline bool PausePreaccumulation () { return false ; }
270+
271+ /* !
272+ * \brief Resume the use of preaccumulation.
273+ * \param[in] wasActive - Whether preaccumulation was active before pausing.
274+ */
275+ inline void ResumePreaccumulation (bool wasActive) {}
276+
277+ /* !
278+ * \brief Begin a hybrid parallel adjoint evaluation mode that assumes an inherently safe reverse path.
279+ */
280+ inline void StartNoSharedReading () {}
281+
282+ /* !
283+ * \brief End the "no shared reading" adjoint evaluation mode.
284+ */
285+ inline void EndNoSharedReading () {}
286+
265287#else
266288 using CheckpointHandler = codi::DataStore;
267289
@@ -271,9 +293,10 @@ namespace AD{
271293
272294 extern ExtFuncHelper* FuncHelper;
273295
274- extern bool Status;
275-
276296 extern bool PreaccActive;
297+ #ifdef HAVE_OPDI
298+ SU2_OMP (threadprivate(PreaccActive))
299+ #endif
277300
278301 extern bool PreaccEnabled;
279302
@@ -290,6 +313,9 @@ namespace AD{
290313 extern std::vector<TapePosition> TapePositions;
291314
292315 extern codi::PreaccumulationHelper<su2double> PreaccHelper;
316+ #ifdef HAVE_OPDI
317+ SU2_OMP (threadprivate(PreaccHelper))
318+ #endif
293319
294320 /* --- Reference to the tape. ---*/
295321
@@ -446,6 +472,7 @@ namespace AD{
446472 FORCEINLINE void EndPreacc (){
447473 if (PreaccActive) {
448474 PreaccHelper.finish (false );
475+ PreaccActive = false ;
449476 }
450477 }
451478
@@ -522,6 +549,39 @@ namespace AD{
522549
523550 FORCEINLINE void EndPassive (bool wasActive) { if (wasActive) StartRecording (); }
524551
552+ FORCEINLINE bool PausePreaccumulation () {
553+ const auto current = PreaccEnabled;
554+ if (!current) return false ;
555+ SU2_OMP_BARRIER
556+ SU2_OMP_MASTER
557+ PreaccEnabled = false ;
558+ END_SU2_OMP_MASTER
559+ SU2_OMP_BARRIER
560+ return true ;
561+ }
562+
563+ FORCEINLINE void ResumePreaccumulation (bool wasActive) {
564+ if (!wasActive) return ;
565+ SU2_OMP_BARRIER
566+ SU2_OMP_MASTER
567+ PreaccEnabled = true ;
568+ END_SU2_OMP_MASTER
569+ SU2_OMP_BARRIER
570+ }
571+
572+ FORCEINLINE void StartNoSharedReading () {
573+ #ifdef HAVE_OPDI
574+ opdi::logic->setAdjointAccessMode (opdi::LogicInterface::AdjointAccessMode::Classical);
575+ opdi::logic->addReverseBarrier ();
576+ #endif
577+ }
578+
579+ FORCEINLINE void EndNoSharedReading () {
580+ #ifdef HAVE_OPDI
581+ opdi::logic->setAdjointAccessMode (opdi::LogicInterface::AdjointAccessMode::Atomic);
582+ opdi::logic->addReverseBarrier ();
583+ #endif
584+ }
525585#endif // CODI_REVERSE_TYPE
526586
527587} // namespace AD
0 commit comments