Skip to content

Commit

Permalink
ReduceOps: reset result readiness flag
Browse files Browse the repository at this point in the history
In #3421, a change was made to avoid a common mistake of calling
ReduceData::value multiple times. Unfortunately, it breaks codes that using
one ReduceOps with multiple ReduceData objects. This PR fixes both cases.
  • Loading branch information
WeiqunZhang committed Sep 15, 2023
1 parent 5829296 commit 3c27878
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Src/Base/AMReX_Reduce.H
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public:
* m_max_blocks * sizeof(Type)))),
m_fn_value([&reduce_op,this] () -> Type { return this->value(reduce_op); })
{
reduce_op.resetResultReadiness();
static_assert(std::is_trivially_copyable<Type>(),
"ReduceData::Type must be trivially copyable");
static_assert(std::is_trivially_destructible<Type>(),
Expand Down Expand Up @@ -750,6 +751,9 @@ public:

private:
bool m_result_is_ready = false;

public:
void resetResultReadiness () { m_result_is_ready = false; }
};

namespace Reduce {
Expand Down Expand Up @@ -993,6 +997,7 @@ public:
: m_tuple(OpenMP::in_parallel() ? 1 : OpenMP::get_max_threads()),
m_fn_value([&reduce_op,this] () -> Type { return this->value(reduce_op); })
{
reduce_op.resetResultReadiness();
for (auto& t : m_tuple) {
Reduce::detail::for_each_init<0, Type, Ps...>(t);
}
Expand Down Expand Up @@ -1158,6 +1163,9 @@ public:
}

bool m_result_is_ready = false;

public:
void resetResultReadiness () { m_result_is_ready = false; }
};

namespace Reduce {
Expand Down

0 comments on commit 3c27878

Please sign in to comment.