Skip to content

Commit 9416b42

Browse files
authored
Merge pull request #2146 from su2code/ad_updates
CoDiPack Update and Explicit Adjoints Locking
2 parents 6530c8a + c68c8d5 commit 9416b42

7 files changed

Lines changed: 28 additions & 2 deletions

File tree

Common/include/basic_types/ad_structure.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ inline void RegisterOutput(su2double& data) {}
7878
*/
7979
inline void ResizeAdjoints() {}
8080

81+
/*!
82+
* \brief Declare that the adjoints are being used, to protect against resizing.
83+
*
84+
* Should be used together with AD::EndUseAdjoints() to protect AD::SetDerivative() and AD::GetDerivative() calls,
85+
* multiple at once if possible.
86+
*/
87+
inline void BeginUseAdjoints() {}
88+
89+
/*!
90+
* \brief Declare that the adjoints are no longer being used.
91+
*/
92+
inline void EndUseAdjoints() {}
93+
8194
/*!
8295
* \brief Sets the adjoint value at index to val
8396
* \param[in] index - Position in the adjoint vector.
@@ -375,6 +388,10 @@ FORCEINLINE void Reset() {
375388

376389
FORCEINLINE void ResizeAdjoints() { AD::getTape().resizeAdjointVector(); }
377390

391+
FORCEINLINE void BeginUseAdjoints() { AD::getTape().beginUseAdjointVector(); }
392+
393+
FORCEINLINE void EndUseAdjoints() { AD::getTape().endUseAdjointVector(); }
394+
378395
FORCEINLINE void SetIndex(int& index, const su2double& data) { index = data.getIdentifier(); }
379396

380397
// WARNING: For performance reasons, this method does not perform bounds checking.

SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,9 @@ void CDiscAdjMultizoneDriver::SetAdjObjFunction() {
781781
}
782782
if (rank == MASTER_NODE) {
783783
AD::ResizeAdjoints();
784+
AD::BeginUseAdjoints();
784785
AD::SetDerivative(ObjFunc_Index, SU2_TYPE::GetValue(seeding));
786+
AD::EndUseAdjoints();
785787
}
786788
}
787789

SU2_CFD/src/iteration/CDiscAdjFEAIteration.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ void CDiscAdjFEAIteration::InitializeAdjoint(CSolver***** solver, CGeometry****
275275
/*--- Initialize the adjoints the conservative variables ---*/
276276

277277
AD::ResizeAdjoints();
278+
AD::BeginUseAdjoints();
278279
solver[iZone][iInst][MESH_0][ADJFEA_SOL]->SetAdjoint_Output(geometry[iZone][iInst][MESH_0], config[iZone]);
280+
AD::EndUseAdjoints();
279281
}
280282

281283
bool CDiscAdjFEAIteration::Monitor(COutput* output, CIntegration**** integration, CGeometry**** geometry,

SU2_CFD/src/iteration/CDiscAdjFluidIteration.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ void CDiscAdjFluidIteration::InitializeAdjoint(CSolver***** solver, CGeometry***
361361
auto geometry0 = geometry[iZone][iInst][MESH_0];
362362

363363
AD::ResizeAdjoints();
364+
AD::BeginUseAdjoints();
364365

365366
SU2_OMP_PARALLEL_(if(solvers0[ADJFLOW_SOL]->GetHasHybridParallel())) {
366367

@@ -392,6 +393,8 @@ void CDiscAdjFluidIteration::InitializeAdjoint(CSolver***** solver, CGeometry***
392393

393394
}
394395
END_SU2_OMP_PARALLEL
396+
397+
AD::EndUseAdjoints();
395398
}
396399

397400
void CDiscAdjFluidIteration::RegisterInput(CSolver***** solver, CGeometry**** geometry, CConfig** config,

SU2_CFD/src/iteration/CDiscAdjHeatIteration.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ void CDiscAdjHeatIteration::InitializeAdjoint(CSolver***** solver, CGeometry****
159159
/*--- Initialize the adjoints the solution variables ---*/
160160

161161
AD::ResizeAdjoints();
162+
AD::BeginUseAdjoints();
162163
solver[iZone][iInst][MESH_0][ADJHEAT_SOL]->SetAdjoint_Output(geometry[iZone][iInst][MESH_0], config[iZone]);
164+
AD::EndUseAdjoints();
163165
}
164166

165167
void CDiscAdjHeatIteration::RegisterInput(CSolver***** solver, CGeometry**** geometry, CConfig** config,

meson_scripts/init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def init_submodules(
5555

5656
# This information of the modules is used if projects was not cloned using git
5757
# The sha tag must be maintained manually to point to the correct commit
58-
sha_version_codi = "8ee822a9b0bb8235a2494467b774e27fb64ff14f"
58+
sha_version_codi = "eee1b5eea2ded8126c34c1415e3b9cf15a3e70f2"
5959
github_repo_codi = "https://github.com/scicompkl/CoDiPack"
6060
sha_version_medi = "aafc2d1966ba1233640af737e71c77c1a86183fd"
6161
github_repo_medi = "https://github.com/SciCompKL/MeDiPack"

0 commit comments

Comments
 (0)