Skip to content

Commit

Permalink
Use more lock-free accesses and explicit locking.
Browse files Browse the repository at this point in the history
  • Loading branch information
jblueh committed Nov 3, 2023
1 parent 47b3007 commit fb364ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 10 additions & 4 deletions SU2_CFD/include/variables/CVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2170,13 +2170,19 @@ class CVariable {
}

inline void GetAdjointSolution_time_n(unsigned long iPoint, su2double *adj_sol) const {
for (unsigned long iVar = 0; iVar < Solution_time_n.cols(); iVar++)
adj_sol[iVar] = SU2_TYPE::GetDerivative(Solution_time_n(iPoint,iVar));
int index = 0;
for (unsigned long iVar = 0; iVar < Solution_time_n.cols(); iVar++) {
AD::SetIndex(index, Solution_time_n(iPoint, iVar));
adj_sol[iVar] = AD::GetDerivative(index);
}
}

inline void GetAdjointSolution_time_n1(unsigned long iPoint, su2double *adj_sol) const {
for (unsigned long iVar = 0; iVar < Solution_time_n1.cols(); iVar++)
adj_sol[iVar] = SU2_TYPE::GetDerivative(Solution_time_n1(iPoint,iVar));
int index = 0;
for (unsigned long iVar = 0; iVar < Solution_time_n1.cols(); iVar++) {
AD::SetIndex(index, Solution_time_n1(iPoint, iVar));
adj_sol[iVar] = AD::GetDerivative(index);
}
}

/*!
Expand Down
4 changes: 4 additions & 0 deletions SU2_CFD/src/solvers/CDiscAdjFEASolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,15 @@ void CDiscAdjFEASolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *co
/*--- Extract and store the adjoint solution at time n (including accel. and velocity) ---*/

if (config->GetTime_Domain()) {
AD::BeginUseAdjoints();

for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
su2double Solution[MAXNVAR] = {0.0};
direct_solver->GetNodes()->GetAdjointSolution_time_n(iPoint,Solution);
nodes->Set_Solution_time_n(iPoint,Solution);
}

AD::EndUseAdjoints();
}

/*--- Set the residuals ---*/
Expand Down
8 changes: 8 additions & 0 deletions SU2_CFD/src/solvers/CDiscAdjSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,24 +359,32 @@ void CDiscAdjSolver::ExtractAdjoint_Solution(CGeometry *geometry, CConfig *confi

/*--- Extract and store the adjoint of the primal solution at time n ---*/
if (time_n_needed) {
AD::BeginUseAdjoints();

SU2_OMP_FOR_STAT(omp_chunk_size)
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
su2double Solution[MAXNVAR] = {0.0};
direct_solver->GetNodes()->GetAdjointSolution_time_n(iPoint,Solution);
nodes->Set_Solution_time_n(iPoint,Solution);
}
END_SU2_OMP_FOR

AD::EndUseAdjoints();
}

/*--- Extract and store the adjoint of the primal solution at time n-1 ---*/
if (time_n1_needed) {
AD::BeginUseAdjoints();

SU2_OMP_FOR_STAT(omp_chunk_size)
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {
su2double Solution[MAXNVAR] = {0.0};
direct_solver->GetNodes()->GetAdjointSolution_time_n1(iPoint,Solution);
nodes->Set_Solution_time_n1(iPoint,Solution);
}
END_SU2_OMP_FOR

AD::EndUseAdjoints();
}

}
Expand Down

0 comments on commit fb364ea

Please sign in to comment.