Skip to content

Commit 9dba7eb

Browse files
committed
Fix data race.
1 parent aaea293 commit 9dba7eb

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

Common/include/basic_types/ad_structure.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ FORCEINLINE void SetIndex(int& index, const su2double& data) { index = data.getI
381381
// WARNING: For performance reasons, this method does not perform bounds checking.
382382
// When using it, please ensure sufficient adjoint vector size by a call to AD::ResizeAdjoints().
383383
FORCEINLINE void SetDerivative(int index, const double val) {
384+
if (index == 0) // Allow multiple threads to "set the derivative" of passive variables without causing data races.
385+
return;
386+
384387
using BoundsChecking = codi::GradientAccessTapeInterface<su2double::Gradient, su2double::Identifier>::BoundsChecking;
385388
AD::getTape().setGradient(index, val, BoundsChecking::False);
386389
}

0 commit comments

Comments
 (0)