Skip to content

Commit f774899

Browse files
committed
replace AD_BEGIN_PASSIVE macro by a function
1 parent 0deb047 commit f774899

14 files changed

Lines changed: 142 additions & 134 deletions

File tree

Common/include/basic_types/ad_structure.hpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ namespace AD{
249249
*/
250250
inline void Push_TapePosition() {}
251251

252+
/*!
253+
* \brief Start a passive region, i.e. stop recording.
254+
*/
255+
inline void BeginPassive() {}
256+
257+
/*!
258+
* \brief End a passive region, i.e. start recording if we were recording before.
259+
*/
260+
inline void EndPassive() {}
261+
252262
#else
253263
using CheckpointHandler = codi::DataStore;
254264

@@ -488,27 +498,23 @@ namespace AD{
488498

489499
FORCEINLINE void EndExtFunc() { delete FuncHelper; }
490500

491-
#endif // CODI_REVERSE_TYPE
501+
FORCEINLINE void BeginPassive() {
502+
if(AD::globalTape.isActive()) {
503+
AD::globalTape.setPassive();
504+
AD::Status = true;
505+
}
506+
}
492507

493-
} // namespace AD
508+
FORCEINLINE void EndPassive() {
509+
if(AD::Status) {
510+
AD::globalTape.setActive();
511+
AD::Status = false;
512+
}
513+
}
494514

495-
/*--- Macro to begin and end sections with a passive tape ---*/
515+
#endif // CODI_REVERSE_TYPE
496516

497-
#ifdef CODI_REVERSE_TYPE
498-
#define AD_BEGIN_PASSIVE \
499-
if(AD::globalTape.isActive()) {\
500-
AD::globalTape.setPassive();\
501-
AD::Status = true; \
502-
}
503-
#define AD_END_PASSIVE \
504-
if(AD::Status) { \
505-
AD::globalTape.setActive(); \
506-
AD::Status = false; \
507-
}
508-
#else
509-
#define AD_BEGIN_PASSIVE
510-
#define AD_END_PASSIVE
511-
#endif
517+
} // namespace AD
512518

513519

514520
/*--- If we compile under OSX we have to overload some of the operators for

Common/include/linear_algebra/CSysSolve_b.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#pragma once
2929

30+
#include "../basic_types/datatype_structure.hpp"
31+
3032
#ifdef CODI_REVERSE_TYPE
3133
template<class ScalarType>
3234
struct CSysSolve_b {

Common/src/adt_structure.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ void CADTPointsOnlyClass::DetermineNearestNode_impl(vector<unsigned long>& front
332332
unsigned long &pointID,
333333
int &rankID) const {
334334

335-
AD_BEGIN_PASSIVE
335+
AD::BeginPassive();
336336

337337
/*--------------------------------------------------------------------------*/
338338
/*--- Step 1: Initialize the nearest node to the central node of the ---*/
@@ -448,7 +448,7 @@ void CADTPointsOnlyClass::DetermineNearestNode_impl(vector<unsigned long>& front
448448
if(frontLeaves.size() == 0) break;
449449
}
450450

451-
AD_END_PASSIVE
451+
AD::EndPassive();
452452

453453
/* Recompute the distance to get the correct dependency if we use AD */
454454
coorTarget = coorPoints.data() + nDimADT*minIndex;
@@ -790,7 +790,7 @@ void CADTElemClass::DetermineNearestElement_impl(vector<CBBoxTargetClass>& BBoxT
790790
unsigned long &elemID,
791791
int &rankID) const {
792792

793-
AD_BEGIN_PASSIVE
793+
AD::BeginPassive();
794794

795795
/*----------------------------------------------------------------------------*/
796796
/*--- Step 1: Initialize the distance (squared) to the quaranteed distance ---*/
@@ -953,7 +953,7 @@ void CADTElemClass::DetermineNearestElement_impl(vector<CBBoxTargetClass>& BBoxT
953953
}
954954
}
955955

956-
AD_END_PASSIVE
956+
AD::EndPassive();
957957

958958
/* At the moment the square of the distance is stored in dist. Compute
959959
the correct value. */

Common/src/geometry/CGeometry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ void CGeometry::ComputeAirfoil_Section(su2double *Plane_P0, su2double *Plane_Nor
18901890
vector<su2double> &Zcoord_Airfoil, vector<su2double> &Variable_Airfoil,
18911891
bool original_surface, CConfig *config) {
18921892

1893-
AD_BEGIN_PASSIVE
1893+
AD::BeginPassive();
18941894

18951895
unsigned short iMarker, iNode, jNode, iDim, Index = 0;
18961896
bool intersect;
@@ -2609,7 +2609,7 @@ void CGeometry::ComputeAirfoil_Section(su2double *Plane_P0, su2double *Plane_Nor
26092609

26102610
}
26112611

2612-
AD_END_PASSIVE
2612+
AD::EndPassive();
26132613

26142614
}
26152615

Common/src/geometry/CPhysicalGeometry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7264,7 +7264,7 @@ void CPhysicalGeometry::SetMaxLength(CConfig* config) {
72647264
* neighbor, then enable it again and recompute the distance.
72657265
* This reduces the overhead of storing irrelevant computations. ---*/
72667266

7267-
AD_BEGIN_PASSIVE
7267+
AD::BeginPassive();
72687268

72697269
su2double max_delta=0;
72707270
auto max_neighbor = iPoint;
@@ -7285,7 +7285,7 @@ void CPhysicalGeometry::SetMaxLength(CConfig* config) {
72857285
}
72867286
}
72877287

7288-
AD_END_PASSIVE
7288+
AD::EndPassive();
72897289

72907290
/*--- Recompute and set. ---*/
72917291
const su2double* Coord_j = nodes->GetCoord(max_neighbor);

Common/src/interface_interpolation/CIsoparametric.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ int CIsoparametric::QuadrilateralIsoparameters(const su2double X[][3], const su2
384384

385385
/*--- Finding Xi and Eta is a "third order" effect that we do not
386386
* differentiate (also because we need to iterate). ---*/
387-
const bool tapeActive = AD::TapeActive();
388-
AD::StopRecording();
387+
388+
AD::BeginPassive();
389389

390390
for (int iter = 0; iter < NITER; ++iter) {
391391

@@ -431,7 +431,7 @@ int CIsoparametric::QuadrilateralIsoparameters(const su2double X[][3], const su2
431431
if (eps < tol) break;
432432
}
433433

434-
if (tapeActive) AD::StartRecording();
434+
AD::EndPassive();
435435

436436
int outOfBounds = 0;
437437

Common/src/linear_algebra/CSysSolve_b.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
2626
*/
2727

28-
#include "../../include/CConfig.hpp"
2928
#include "../../include/linear_algebra/CSysSolve_b.hpp"
3029
#include "../../include/linear_algebra/CSysSolve.hpp"
3130
#include "../../include/linear_algebra/CSysMatrix.hpp"

Common/src/linear_algebra/CSysVector.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@
4040
* CSysVector and do not have the same work scheduling must use a
4141
* SU2_OMP_BARRIER before using the vector.
4242
*/
43+
#ifndef _MSC_VER
44+
#define PARALLEL_FOR SU2_OMP(for simd schedule(static,omp_chunk_size) nowait)
45+
#else
46+
/*--- MSVC does not support SIMD by default. ---*/
4347
#define PARALLEL_FOR SU2_OMP(for schedule(static,omp_chunk_size) nowait)
48+
#endif
4449

4550
template<class ScalarType>
4651
CSysVector<ScalarType>::CSysVector(void) {

SU2_CFD/include/limiters/computeLimiters_impl.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,9 @@ void computeLimiters_impl(CSolver* solver,
9898
omp_get_max_threads(), OMP_MAX_CHUNK);
9999
#endif
100100

101-
bool tapeActive = false;
102-
101+
/*--- If limiters are frozen do not record the computation ---*/
103102
if (config.GetDiscrete_Adjoint() && config.GetFrozen_Limiter_Disc()) {
104-
/*--- If limiters are frozen do not record the computation ---*/
105-
tapeActive = AD::TapeActive();
106-
AD::StopRecording();
103+
AD::BeginPassive();
107104
}
108105

109106
CLimiterDetails<LimiterKind> limiterDetails;
@@ -240,6 +237,6 @@ void computeLimiters_impl(CSolver* solver,
240237
solver->CompleteComms(&geometry, &config, kindMpiComm);
241238
}
242239

243-
if (tapeActive) AD::StartRecording();
240+
AD::EndPassive();
244241

245242
}

SU2_CFD/include/solvers/CMeshSolver.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class CMeshSolver final : public CFEASolver {
3939

4040
bool stiffness_set; /*!< \brief Element-based stiffness is set. */
4141

42-
su2double MinVolume_Ref, /*!< \brief Minimum volume in reference and current (deformed) configuration. */
43-
MinVolume_Curr;
42+
unsigned long ElemCounter; /*!< \brief Error (negative volume) counter. */
4443

45-
su2double MaxVolume_Ref,
46-
MaxVolume_Curr;
47-
48-
su2double MinDistance;
49-
su2double MaxDistance;
44+
/*!
45+
* \brief Minimum/Maximum distance and volume (in reference and current (deformed) coords).
46+
*/
47+
su2double MinVolume, MinVolume_Ref, MinVolume_Curr;
48+
su2double MaxVolume, MaxVolume_Ref, MaxVolume_Curr;
49+
su2double MinDistance, MaxDistance;
5050

5151
vector<CMeshElement> element; /*!< \brief Vector which stores element information for each problem. */
5252

0 commit comments

Comments
 (0)