Skip to content

Commit becf1fb

Browse files
committed
apply suggestions
1 parent fbef867 commit becf1fb

File tree

1 file changed

+46
-36
lines changed

1 file changed

+46
-36
lines changed

Src/Base/AMReX_Reduce.H

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,19 +1059,22 @@ public:
10591059
#ifdef AMREX_USE_OMP
10601060
#pragma omp parallel
10611061
#endif
1062-
for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) {
1063-
Box const& b = mfi.growntilebox(nghost);
1064-
const int li = mfi.LocalIndex();
1065-
auto& rr_ref = reduce_data.reference(OpenMP::get_thread_num());
1066-
auto rr = rr_ref;
1067-
const auto lo = amrex::lbound(b);
1068-
const auto hi = amrex::ubound(b);
1069-
for (int k = lo.z; k <= hi.z; ++k) {
1070-
for (int j = lo.y; j <= hi.y; ++j) {
1071-
for (int i = lo.x; i <= hi.x; ++i) {
1072-
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, f(li,i,j,k));
1073-
}}}
1074-
rr_ref = rr;
1062+
{
1063+
ReduceTuple rr;
1064+
Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
1065+
for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) {
1066+
Box const& b = mfi.growntilebox(nghost);
1067+
const int li = mfi.LocalIndex();
1068+
const auto lo = amrex::lbound(b);
1069+
const auto hi = amrex::ubound(b);
1070+
for (int k = lo.z; k <= hi.z; ++k) {
1071+
for (int j = lo.y; j <= hi.y; ++j) {
1072+
for (int i = lo.x; i <= hi.x; ++i) {
1073+
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, f(li,i,j,k));
1074+
}}}
1075+
}
1076+
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1077+
reduce_data.reference(OpenMP::get_thread_num()), rr);
10751078
}
10761079
}
10771080

@@ -1083,39 +1086,44 @@ public:
10831086
#ifdef AMREX_USE_OMP
10841087
#pragma omp parallel
10851088
#endif
1086-
for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) {
1087-
Box const& b = mfi.growntilebox(nghost);
1088-
const int li = mfi.LocalIndex();
1089-
auto& rr_ref = reduce_data.reference(OpenMP::get_thread_num());
1090-
auto rr = rr_ref;
1091-
const auto lo = amrex::lbound(b);
1092-
const auto hi = amrex::ubound(b);
1093-
for (int n = 0; n < ncomp; ++n) {
1094-
for (int k = lo.z; k <= hi.z; ++k) {
1095-
for (int j = lo.y; j <= hi.y; ++j) {
1096-
for (int i = lo.x; i <= hi.x; ++i) {
1097-
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, f(li,i,j,k,n));
1098-
}}}}
1099-
rr_ref = rr;
1089+
{
1090+
ReduceTuple rr;
1091+
Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
1092+
for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) {
1093+
Box const& b = mfi.growntilebox(nghost);
1094+
const int li = mfi.LocalIndex();
1095+
const auto lo = amrex::lbound(b);
1096+
const auto hi = amrex::ubound(b);
1097+
for (int n = 0; n < ncomp; ++n) {
1098+
for (int k = lo.z; k <= hi.z; ++k) {
1099+
for (int j = lo.y; j <= hi.y; ++j) {
1100+
for (int i = lo.x; i <= hi.x; ++i) {
1101+
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, f(li,i,j,k,n));
1102+
}}}}
1103+
}
1104+
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1105+
reduce_data.reference(OpenMP::get_thread_num()), rr);
11001106
}
11011107
}
11021108

11031109
template <typename D, typename F>
11041110
void eval (Box const& box, D & reduce_data, F&& f)
11051111
{
1106-
auto& rr_ref = reduce_data.reference(OpenMP::get_thread_num());
1107-
auto rr = rr_ref;
1112+
using ReduceTuple = typename D::Type;
1113+
ReduceTuple rr;
1114+
Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
11081115
call_f<D>(box, rr, std::forward<F>(f));
1109-
rr_ref = rr;
1116+
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1117+
reduce_data.reference(OpenMP::get_thread_num()), rr);
11101118
}
11111119

11121120
template <typename N, typename D, typename F,
11131121
typename M=std::enable_if_t<std::is_integral_v<N>> >
11141122
void eval (Box const& box, N ncomp, D & reduce_data, F const& f)
11151123
{
11161124
using ReduceTuple = typename D::Type;
1117-
auto& rr_ref = reduce_data.reference(OpenMP::get_thread_num());
1118-
auto rr = rr_ref;
1125+
ReduceTuple rr;
1126+
Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
11191127
const auto lo = amrex::lbound(box);
11201128
const auto hi = amrex::ubound(box);
11211129
for (N n = 0; n < ncomp; ++n) {
@@ -1124,20 +1132,22 @@ public:
11241132
for (int i = lo.x; i <= hi.x; ++i) {
11251133
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, f(i,j,k,n));
11261134
}}}}
1127-
rr_ref = rr;
1135+
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1136+
reduce_data.reference(OpenMP::get_thread_num()), rr);
11281137
}
11291138

11301139
template <typename N, typename D, typename F,
11311140
typename M=std::enable_if_t<std::is_integral_v<N>> >
11321141
void eval (N n, D & reduce_data, F const& f)
11331142
{
11341143
using ReduceTuple = typename D::Type;
1135-
auto& rr_ref = reduce_data.reference(OpenMP::get_thread_num());
1136-
auto rr = rr_ref;
1144+
ReduceTuple rr;
1145+
Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
11371146
for (N i = 0; i < n; ++i) {
11381147
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, f(i));
11391148
}
1140-
rr_ref = rr;
1149+
Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1150+
reduce_data.reference(OpenMP::get_thread_num()), rr);
11411151
}
11421152

11431153
template <typename D>

0 commit comments

Comments
 (0)