Skip to content

Commit

Permalink
ReduceOps: reset result readiness flag (#3545)
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.

## Checklist

The proposed changes:
- [x] fix a bug or incorrect behavior in AMReX
- [ ] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX
users
- [ ] include documentation in the code and/or rst files, if appropriate
  • Loading branch information
WeiqunZhang authored Sep 15, 2023
1 parent 5829296 commit 078905a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 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,8 @@ public:
}

bool m_result_is_ready = false;

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

namespace Reduce {
Expand Down

0 comments on commit 078905a

Please sign in to comment.