1#ifndef AMREX_FABARRAY_UTILITY_H_
2#define AMREX_FABARRAY_UTILITY_H_
3#include <AMReX_Config.H>
13template <
class FAB,
class F,
14 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
15typename FAB::value_type
22template <
class FAB,
class F,
23 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
24typename FAB::value_type
25ReduceSum_host (FabArray<FAB>
const& fa, IntVect
const& nghost, F
const& f)
27 using value_type =
typename FAB::value_type;
31#pragma omp parallel if (!system::regtest_reduction) reduction(+:sm)
33 for (MFIter mfi(fa,
true); mfi.isValid(); ++mfi)
35 const Box& bx = mfi.growntilebox(nghost);
36 auto const& arr = fa.const_array(mfi);
48template <
class OP,
class FAB,
class F>
49std::enable_if_t<IsBaseFab<FAB>::value,
50 std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
51 std::is_same<OP,ReduceOpLogicalOr>::value,
52 int,
typename FAB::value_type> >
53ReduceMF (FabArray<FAB>
const& fa, IntVect
const& nghost, F
const& f)
55 using T = std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
56 std::is_same<OP,ReduceOpLogicalOr>::value,
57 int,
typename FAB::value_type>;
58 auto typ = fa.ixType();
59 auto const& ma = fa.const_arrays();
60 return ParReduce(TypeList<OP>{}, TypeList<T>{}, fa, nghost,
61 [=]
AMREX_GPU_DEVICE (
int box_no,
int i,
int j,
int k)
noexcept -> GpuTuple<T>
67template <
class OP,
class FAB1,
class FAB2,
class F>
68std::enable_if_t<IsBaseFab<FAB1>::value && IsBaseFab<FAB2>::value,
69 std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
70 std::is_same<OP,ReduceOpLogicalOr>::value,
71 int,
typename FAB1::value_type> >
72ReduceMF (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2, IntVect
const& nghost, F
const& f)
74 using T = std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
75 std::is_same<OP,ReduceOpLogicalOr>::value,
76 int,
typename FAB1::value_type>;
77 auto typ = fa1.ixType();
78 auto const& ma1 = fa1.const_arrays();
79 auto const& ma2 = fa2.const_arrays();
80 return ParReduce(TypeList<OP>{}, TypeList<T>{}, fa1, nghost,
81 [=]
AMREX_GPU_DEVICE (
int box_no,
int i,
int j,
int k)
noexcept -> GpuTuple<T>
84 ma1[box_no], ma2[box_no])) };
88template <
class OP,
class FAB1,
class FAB2,
class FAB3,
class F>
89std::enable_if_t<IsBaseFab<FAB1>::value && IsBaseFab<FAB2>::value && IsBaseFab<FAB3>::value,
90 std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
91 std::is_same<OP,ReduceOpLogicalOr>::value,
92 int,
typename FAB1::value_type> >
93ReduceMF (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
94 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F
const& f)
96 using T = std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
97 std::is_same<OP,ReduceOpLogicalOr>::value,
98 int,
typename FAB1::value_type>;
99 auto typ = fa1.ixType();
100 auto const& ma1 = fa1.const_arrays();
101 auto const& ma2 = fa2.const_arrays();
102 auto const& ma3 = fa3.const_arrays();
103 return ParReduce(TypeList<OP>{}, TypeList<T>{}, fa1, nghost,
104 [=]
AMREX_GPU_DEVICE (
int box_no,
int i,
int j,
int k)
noexcept -> GpuTuple<T>
107 ma1[box_no], ma2[box_no], ma3[box_no])) };
111template <
class FAB,
class F>
112std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB::value_type>
113ReduceSum_host_wrapper (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& f)
115 return ReduceSum_host(fa,nghost,std::forward<F>(f));
118template <
class FAB,
class F>
119std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB::value_type>
120ReduceSum_host_wrapper (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& f)
123 amrex::Abort(
"ReduceSum: Launch Region is off. Device lambda cannot be called by host.");
129template <
class FAB,
class F,
130 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
131typename FAB::value_type
135 return fudetail::ReduceMF<ReduceOpSum>(fa, nghost, std::forward<F>(f));
137 return fudetail::ReduceSum_host_wrapper(fa, nghost, std::forward<F>(f));
141template <
class FAB,
class F,
142 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
143typename FAB::value_type
146 return fudetail::ReduceSum_host(fa, nghost, std::forward<F>(f));
150template <
class FAB1,
class FAB2,
class F,
151 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
152typename FAB1::value_type
160template <
class FAB1,
class FAB2,
class F,
161 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
162typename FAB1::value_type
163ReduceSum_host (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
164 IntVect
const& nghost, F
const& f)
166 using value_type =
typename FAB1::value_type;
170#pragma omp parallel if (!system::regtest_reduction) reduction(+:sm)
172 for (MFIter mfi(fa1,
true); mfi.isValid(); ++mfi)
174 const Box& bx = mfi.growntilebox(nghost);
175 const auto& arr1 = fa1.const_array(mfi);
176 const auto& arr2 = fa2.const_array(mfi);
177 sm += f(bx, arr1, arr2);
188template <
class FAB1,
class FAB2,
class F>
189std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
190ReduceSum_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
191 IntVect
const& nghost, F&& f)
193 return ReduceSum_host(fa1,fa2,nghost,std::forward<F>(f));
196template <
class FAB1,
class FAB2,
class F>
197std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
198ReduceSum_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
199 IntVect
const& nghost, F&& f)
202 amrex::Abort(
"ReduceSum: Launch Region is off. Device lambda cannot be called by host.");
208template <
class FAB1,
class FAB2,
class F,
209 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
210typename FAB1::value_type
215 return fudetail::ReduceMF<ReduceOpSum>(fa1,fa2,nghost,std::forward<F>(f));
217 return fudetail::ReduceSum_host_wrapper(fa1,fa2,nghost,std::forward<F>(f));
221template <
class FAB1,
class FAB2,
class F,
222 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
223typename FAB1::value_type
224ReduceSum (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
227 return fudetail::ReduceSum_host(fa1,fa2,nghost,std::forward<F>(f));
231template <
class FAB1,
class FAB2,
class FAB3,
class F,
232 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
233typename FAB1::value_type
242template <
class FAB1,
class FAB2,
class FAB3,
class F,
243 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
244typename FAB1::value_type
245ReduceSum_host (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
246 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F
const& f)
248 using value_type =
typename FAB1::value_type;
252#pragma omp parallel if (!system::regtest_reduction) reduction(+:sm)
254 for (MFIter mfi(fa1,
true); mfi.isValid(); ++mfi)
256 const Box& bx = mfi.growntilebox(nghost);
257 const auto& arr1 = fa1.const_array(mfi);
258 const auto& arr2 = fa2.const_array(mfi);
259 const auto& arr3 = fa3.const_array(mfi);
260 sm += f(bx, arr1, arr2, arr3);
271template <
class FAB1,
class FAB2,
class FAB3,
class F>
272std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
273ReduceSum_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
274 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F&& f)
276 return fudetail::ReduceSum_host(fa1,fa2,fa3,nghost,std::forward<F>(f));
279template <
class FAB1,
class FAB2,
class FAB3,
class F>
280std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
281ReduceSum_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
282 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F&& f)
285 amrex::Abort(
"ReduceSum: Launch Region is off. Device lambda cannot be called by host.");
291template <
class FAB1,
class FAB2,
class FAB3,
class F,
292 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
293typename FAB1::value_type
298 return fudetail::ReduceMF<ReduceOpSum>(fa1,fa2,fa3,nghost,std::forward<F>(f));
300 return fudetail::ReduceSum_host_wrapper(fa1,fa2,fa3,nghost,std::forward<F>(f));
304template <
class FAB1,
class FAB2,
class FAB3,
class F,
305 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
306typename FAB1::value_type
307ReduceSum (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
308 FabArray<FAB3>
const& fa3,
IntVect const& nghost,
F&& f)
310 return fudetail::ReduceSum_host(fa1,fa2,fa3,nghost,std::forward<F>(f));
314template <
class FAB,
class F,
315 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
316typename FAB::value_type
324template <
class FAB,
class F,
325 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
326typename FAB::value_type
327ReduceMin_host (FabArray<FAB>
const& fa, IntVect
const& nghost, F
const& f)
329 using value_type =
typename FAB::value_type;
330 value_type r = std::numeric_limits<value_type>::max();
333#pragma omp parallel reduction(min:r)
335 for (MFIter mfi(fa,
true); mfi.isValid(); ++mfi)
337 const Box& bx = mfi.growntilebox(nghost);
338 const auto& arr = fa.const_array(mfi);
339 r = std::min(r, f(bx, arr));
349template <
class FAB,
class F>
350std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB::value_type>
351ReduceMin_host_wrapper (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& f)
353 return ReduceMin_host(fa,nghost,std::forward<F>(f));
356template <
class FAB,
class F>
357std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB::value_type>
358ReduceMin_host_wrapper (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& f)
361 amrex::Abort(
"ReduceMin: Launch Region is off. Device lambda cannot be called by host.");
367template <
class FAB,
class F,
368 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
369typename FAB::value_type
373 return fudetail::ReduceMF<ReduceOpMin>(fa, nghost, std::forward<F>(f));
375 return fudetail::ReduceMin_host_wrapper(fa, nghost, std::forward<F>(f));
379template <
class FAB,
class F,
380 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
381typename FAB::value_type
384 return fudetail::ReduceMin_host(fa, nghost, std::forward<F>(f));
388template <
class FAB1,
class FAB2,
class F,
389 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
390typename FAB1::value_type
398template <
class FAB1,
class FAB2,
class F,
399 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
400typename FAB1::value_type
401ReduceMin_host (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
402 IntVect
const& nghost, F
const& f)
404 using value_type =
typename FAB1::value_type;
405 value_type r = std::numeric_limits<value_type>::max();
408#pragma omp parallel reduction(min:r)
410 for (MFIter mfi(fa1,
true); mfi.isValid(); ++mfi)
412 const Box& bx = mfi.growntilebox(nghost);
413 const auto& arr1 = fa1.const_array(mfi);
414 const auto& arr2 = fa2.const_array(mfi);
415 r = std::min(r, f(bx, arr1, arr2));
426template <
class FAB1,
class FAB2,
class F>
427std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
428ReduceMin_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
429 IntVect
const& nghost, F&& f)
431 return fudetail::ReduceMin_host(fa1,fa2,nghost,std::forward<F>(f));
434template <
class FAB1,
class FAB2,
class F>
435std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
436ReduceMin_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
437 IntVect
const& nghost, F&& f)
440 amrex::Abort(
"ReduceMin: Launch Region is off. Device lambda cannot be called by host.");
446template <
class FAB1,
class FAB2,
class F,
447 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
448typename FAB1::value_type
453 return fudetail::ReduceMF<ReduceOpMin>(fa1,fa2,nghost,std::forward<F>(f));
455 return fudetail::ReduceMin_host_wrapper(fa1,fa2,nghost,std::forward<F>(f));
459template <
class FAB1,
class FAB2,
class F,
460 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
461typename FAB1::value_type
462ReduceMin (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
465 return fudetail::ReduceMin_host(fa1,fa2,nghost,std::forward<F>(f));
469template <
class FAB1,
class FAB2,
class FAB3,
class F,
470 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
471typename FAB1::value_type
480template <
class FAB1,
class FAB2,
class FAB3,
class F,
481 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
482typename FAB1::value_type
483ReduceMin_host (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
484 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F
const& f)
486 using value_type =
typename FAB1::value_type;
487 value_type r = std::numeric_limits<value_type>::max();
490#pragma omp parallel reduction(min:r)
492 for (MFIter mfi(fa1,
true); mfi.isValid(); ++mfi)
494 const Box& bx = mfi.growntilebox(nghost);
495 const auto& arr1 = fa1.const_array(mfi);
496 const auto& arr2 = fa2.const_array(mfi);
497 const auto& arr3 = fa3.const_array(mfi);
498 r = std::min(r, f(bx, arr1, arr2, arr3));
509template <
class FAB1,
class FAB2,
class FAB3,
class F>
510std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
511ReduceMin_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
512 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F&& f)
514 return fudetail::ReduceMin_host(fa1,fa2,fa3,nghost,std::forward<F>(f));
517template <
class FAB1,
class FAB2,
class FAB3,
class F>
518std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
519ReduceMin_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
520 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F&& f)
523 amrex::Abort(
"ReduceMin: Launch Region is off. Device lambda lambda cannot be called by host.");
529template <
class FAB1,
class FAB2,
class FAB3,
class F,
530 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
531typename FAB1::value_type
536 return fudetail::ReduceMF<ReduceOpMin>(fa1,fa2,fa3,nghost,std::forward<F>(f));
538 return fudetail::ReduceMin_host_wrapper(fa1,fa2,fa3,nghost,std::forward<F>(f));
542template <
class FAB1,
class FAB2,
class FAB3,
class F,
543 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
544typename FAB1::value_type
545ReduceMin (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
546 FabArray<FAB3>
const& fa3,
IntVect const& nghost,
F&& f)
548 return fudetail::ReduceMin_host(fa1,fa2,fa3,nghost,std::forward<F>(f));
552template <
class FAB,
class F,
553 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
554typename FAB::value_type
562template <
class FAB,
class F,
563 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
564typename FAB::value_type
565ReduceMax_host (FabArray<FAB>
const& fa, IntVect
const& nghost, F
const& f)
567 using value_type =
typename FAB::value_type;
568 value_type r = std::numeric_limits<value_type>::lowest();
571#pragma omp parallel reduction(max:r)
573 for (MFIter mfi(fa,
true); mfi.isValid(); ++mfi)
575 const Box& bx = mfi.growntilebox(nghost);
576 const auto& arr = fa.const_array(mfi);
577 r = std::max(r, f(bx, arr));
588template <
class FAB,
class F>
589std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB::value_type>
590ReduceMax_host_wrapper (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& f)
592 return ReduceMax_host(fa,nghost,std::forward<F>(f));
595template <
class FAB,
class F>
596std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB::value_type>
597ReduceMax_host_wrapper (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& f)
600 amrex::Abort(
"ReduceMax: Launch Region is off. Device lambda cannot be called by host.");
606template <
class FAB,
class F,
607 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
608typename FAB::value_type
612 return fudetail::ReduceMF<ReduceOpMax>(fa,nghost,std::forward<F>(f));
614 return fudetail::ReduceMax_host_wrapper(fa,nghost,std::forward<F>(f));
618template <
class FAB,
class F,
619 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
620typename FAB::value_type
623 return fudetail::ReduceMax_host(fa,nghost,std::forward<F>(f));
627template <
class FAB1,
class FAB2,
class F,
628 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
629typename FAB1::value_type
637template <
class FAB1,
class FAB2,
class F,
638 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
639typename FAB1::value_type
640ReduceMax_host (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
641 IntVect
const& nghost, F
const& f)
643 using value_type =
typename FAB1::value_type;
644 value_type r = std::numeric_limits<value_type>::lowest();
647#pragma omp parallel reduction(max:r)
649 for (MFIter mfi(fa1,
true); mfi.isValid(); ++mfi)
651 const Box& bx = mfi.growntilebox(nghost);
652 const auto& arr1 = fa1.const_array(mfi);
653 const auto& arr2 = fa2.const_array(mfi);
654 r = std::max(r, f(bx, arr1, arr2));
665template <
class FAB1,
class FAB2,
class F>
666std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
667ReduceMax_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
668 IntVect
const& nghost, F&& f)
670 return ReduceMax_host(fa1,fa2,nghost,std::forward<F>(f));
673template <
class FAB1,
class FAB2,
class F>
674std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
675ReduceMax_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
676 IntVect
const& nghost, F&& f)
679 amrex::Abort(
"ReduceMax: Launch Region is off. Device lambda cannot be called by host.");
685template <
class FAB1,
class FAB2,
class F,
686 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
687typename FAB1::value_type
692 return fudetail::ReduceMF<ReduceOpMax>(fa1,fa2,nghost,std::forward<F>(f));
694 return fudetail::ReduceMax_host_wrapper(fa1,fa2,nghost,std::forward<F>(f));
698template <
class FAB1,
class FAB2,
class F,
699 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
700typename FAB1::value_type
701ReduceMax (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
704 return fudetail::ReduceMax_host(fa1,fa2,nghost,std::forward<F>(f));
708template <
class FAB1,
class FAB2,
class FAB3,
class F,
709 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
710typename FAB1::value_type
719template <
class FAB1,
class FAB2,
class FAB3,
class F,
720 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
721typename FAB1::value_type
722ReduceMax_host (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
723 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F
const& f)
725 using value_type =
typename FAB1::value_type;
726 value_type r = std::numeric_limits<value_type>::lowest();
729#pragma omp parallel reduction(max:r)
731 for (MFIter mfi(fa1,
true); mfi.isValid(); ++mfi)
733 const Box& bx = mfi.growntilebox(nghost);
734 const auto& arr1 = fa1.const_array(mfi);
735 const auto& arr2 = fa2.const_array(mfi);
736 const auto& arr3 = fa3.const_array(mfi);
737 r = std::max(r, f(bx, arr1, arr2, arr3));
748template <
class FAB1,
class FAB2,
class FAB3,
class F>
749std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
750ReduceMax_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
751 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F&& f)
753 return fudetail::ReduceMax_host(fa1,fa2,fa3,nghost,std::forward<F>(f));
756template <
class FAB1,
class FAB2,
class FAB3,
class F>
757std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
typename FAB1::value_type>
758ReduceMax_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
759 FabArray<FAB3>
const& fa3, IntVect
const& nghost, F&& f)
762 amrex::Abort(
"ReduceMax: Launch Region is off. Device lambda lambda cannot be called by host.");
768template <
class FAB1,
class FAB2,
class FAB3,
class F,
769 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
770typename FAB1::value_type
775 return fudetail::ReduceMF<ReduceOpMax>(fa1,fa2,fa3,nghost,std::forward<F>(f));
777 return fudetail::ReduceMax_host_wrapper(fa1,fa2,fa3,nghost,std::forward<F>(f));
781template <
class FAB1,
class FAB2,
class FAB3,
class F,
782 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
783typename FAB1::value_type
784ReduceMax (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
785 FabArray<FAB3>
const& fa3,
IntVect const& nghost,
F&& f)
787 return fudetail::ReduceMax_host(fa1,fa2,fa3,nghost,std::forward<F>(f));
791template <
class FAB,
class F,
792 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
801template <
class FAB,
class F,
802 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
804ReduceLogicalAnd_host (FabArray<FAB>
const& fa, IntVect
const& nghost, F
const& f)
809#pragma omp parallel reduction(&&:r)
811 for (MFIter mfi(fa,
true); mfi.isValid(); ++mfi)
813 const Box& bx = mfi.growntilebox(nghost);
814 const auto& arr = fa.const_array(mfi);
826template <
class FAB,
class F>
827std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
bool>
828ReduceLogicalAnd_host_wrapper (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& f)
830 return ReduceLogicalAnd_host(fa,nghost,std::forward<F>(f));
833template <
class FAB,
class F>
834std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
bool>
835ReduceLogicalAnd_host_wrapper (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& f)
838 amrex::Abort(
"ReduceLogicalAnd: Launch Region is off. Device lambda cannot be called by host.");
844template <
class FAB,
class F,
845 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
850 return fudetail::ReduceMF<ReduceOpLogicalAnd>(fa,nghost,std::forward<F>(f));
852 return fudetail::ReduceLogicalAnd_host_wrapper(fa,nghost,std::forward<F>(f));
856template <
class FAB,
class F,
857 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
861 return fudetail::ReduceLogicalAnd_host(fa,nghost,std::forward<F>(f));
865template <
class FAB1,
class FAB2,
class F,
866 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
876template <
class FAB1,
class FAB2,
class F,
877 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
879ReduceLogicalAnd_host (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
880 IntVect
const& nghost, F
const& f)
885#pragma omp parallel reduction(&&:r)
887 for (MFIter mfi(fa1,
true); mfi.isValid(); ++mfi)
889 const Box& bx = mfi.growntilebox(nghost);
890 const auto& arr1 = fa1.const_array(mfi);
891 const auto& arr2 = fa2.const_array(mfi);
892 r = r && f(bx, arr1, arr2);
903template <
class FAB1,
class FAB2,
class F>
904std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
bool>
905ReduceLogicalAnd_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
906 IntVect
const& nghost, F&& f)
908 return ReduceLogicalAnd_host(fa1,fa2,nghost,std::forward<F>(f));
911template <
class FAB1,
class FAB2,
class F>
912std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
bool>
913ReduceLogicalAnd_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
914 IntVect
const& nghost, F&& f)
917 amrex::Abort(
"ReduceLogicalAnd: Luanch Region is off. Device lambda cannot be called by host.");
923template <
class FAB1,
class FAB2,
class F,
924 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
930 return fudetail::ReduceMF<ReduceOpLogicalAnd>(fa1,fa2,nghost,std::forward<F>(f));
932 return fudetail::ReduceLogicalAnd_host_wrapper(fa1,fa2,nghost,std::forward<F>(f));
936template <
class FAB1,
class FAB2,
class F,
937 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
942 return fudetail::ReduceLogicalAnd_host(fa1,fa2,nghost,std::forward<F>(f));
946template <
class FAB,
class F,
947 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
956template <
class FAB,
class F,
957 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
959ReduceLogicalOr_host (FabArray<FAB>
const& fa, IntVect
const& nghost, F
const& f)
964#pragma omp parallel reduction(||:r)
966 for (MFIter mfi(fa,
true); mfi.isValid(); ++mfi)
968 const Box& bx = mfi.growntilebox(nghost);
969 const auto& arr = fa.const_array(mfi);
981template <
class FAB,
class F>
982std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
bool>
983ReduceLogicalOr_host_wrapper (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& f)
985 return ReduceLogicalOr_host(fa,nghost,std::forward<F>(f));
988template <
class FAB,
class F>
989std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
bool>
990ReduceLogicalOr_host (FabArray<FAB>
const& fa, IntVect
const& nghost, F&& )
993 amrex::Abort(
"ReduceLogicalOr: Launch Region is off. Device lambda cannot be called by host.");
999template <
class FAB,
class F,
1000 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1005 return fudetail::ReduceMF<ReduceOpLogicalOr>(fa,nghost,std::forward<F>(f));
1007 return fudetail::ReduceLogicalOr_host_wrapper(fa,nghost,std::forward<F>(f));
1011template <
class FAB,
class F,
1012 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1016 return fudetail::ReduceLogicalOr_host(fa,nghost,std::forward<F>(f));
1020template <
class FAB1,
class FAB2,
class F,
1021 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
1031template <
class FAB1,
class FAB2,
class F,
1032 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
1034ReduceLogicalOr_host (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
1035 IntVect
const& nghost, F
const& f)
1040#pragma omp parallel reduction(||:r)
1042 for (MFIter mfi(fa1,
true); mfi.isValid(); ++mfi)
1044 const Box& bx = mfi.growntilebox(nghost);
1045 const auto& arr1 = fa1.const_array(mfi);
1046 const auto& arr2 = fa2.const_array(mfi);
1047 r = r || f(bx, arr1, arr2);
1058template <
class FAB1,
class FAB2,
class F>
1059std::enable_if_t<!amrex::DefinitelyNotHostRunnable<F>::value,
bool>
1060ReduceLogicalOr_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
1061 IntVect
const& nghost, F&& f)
1063 return fudetail::ReduceLogicalOr_host(fa1,fa2,nghost,std::forward<F>(f));
1066template <
class FAB1,
class FAB2,
class F>
1067std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value,
bool>
1068ReduceLogicalOr_host_wrapper (FabArray<FAB1>
const& fa1, FabArray<FAB2>
const& fa2,
1069 IntVect
const& nghost, F&& f)
1072 amrex::Abort(
"ReeuceLogicalOr: Launch Region is off. Device lambda cannot be called by host.");
1078template <
class FAB1,
class FAB2,
class F,
1079 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
1085 return fudetail::ReduceMF<ReduceOpLogicalOr>(fa1,fa2,nghost,std::forward<F>(f));
1087 return fudetail::ReduceLogicalOr_host_wrapper(fa1,fa2,nghost,std::forward<F>(f));
1091template <
class FAB1,
class FAB2,
class F,
1092 class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
1097 return fudetail::ReduceLogicalOr_host(fa1,fa2,nghost,std::forward<F>(f));
1101template <class FAB, class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1110 int n = (comp >= 0) ? 1 : mf.
nComp();
1113 auto* dp = pv.
data();
1117 *dp = fab(cell, comp);
1119 for (
int i = 0; i < n; ++i) {
1120 dp[i] = fab(cell,i);
1137 <<
": " << *dp <<
'\n';
1139 std::ostringstream ss;
1141 for (
int i = 0; i < n-1; ++i)
1143 ss << dp[i] <<
", ";
1147 <<
": " << ss.str() <<
'\n';
1154 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1158 Swap(dst,src,srccomp,dstcomp,numcomp,
IntVect(nghost));
1162 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1169 bool explicit_swap =
true;
1171 if (srccomp == dstcomp && dstcomp == 0 && src.
nComp() == dst.
nComp() &&
1174 explicit_swap =
false;
1177 if (!explicit_swap) {
1179 std::swap(dst, src);
1184 auto const& dstma = dst.
arrays();
1185 auto const& srcma = src.
arrays();
1189 const auto tmp = dstma[box_no](i,j,k,n+dstcomp);
1190 dstma[box_no](i,j,k,n+dstcomp) = srcma[box_no](i,j,k,n+srccomp);
1191 srcma[box_no](i,j,k,n+srccomp) = tmp;
1200#pragma omp parallel if (Gpu::notInLaunchRegion())
1204 const Box& bx = mfi.growntilebox(nghost);
1206 auto sfab = src.
array(mfi);
1207 auto dfab = dst.
array(mfi);
1210 const auto tmp = dfab(i,j,k,n+dstcomp);
1211 dfab(i,j,k,n+dstcomp) = sfab(i,j,k,n+srccomp);
1212 sfab(i,j,k,n+srccomp) = tmp;
1221 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1229 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1235 auto const& dstfa = dst.
arrays();
1240 dstfa[box_no](i,j,k,n+dstcomp) -= srcfa[box_no](i,j,k,n+srccomp);
1249#pragma omp parallel if (Gpu::notInLaunchRegion())
1253 const Box& bx = mfi.growntilebox(nghost);
1256 auto const srcFab = src.
array(mfi);
1257 auto dstFab = dst.
array(mfi);
1260 dstFab(i,j,k,n+dstcomp) -= srcFab(i,j,k,n+srccomp);
1269 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1277 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1283 auto const& dstfa = dst.
arrays();
1288 dstfa[box_no](i,j,k,n+dstcomp) *= srcfa[box_no](i,j,k,n+srccomp);
1297#pragma omp parallel if (Gpu::notInLaunchRegion())
1301 const Box& bx = mfi.growntilebox(nghost);
1304 auto const srcFab = src.
array(mfi);
1305 auto dstFab = dst.
array(mfi);
1308 dstFab(i,j,k,n+dstcomp) *= srcFab(i,j,k,n+srccomp);
1317 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1325 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1331 auto const& dstfa = dst.
arrays();
1336 dstfa[box_no](i,j,k,n+dstcomp) /= srcfa[box_no](i,j,k,n+srccomp);
1345#pragma omp parallel if (Gpu::notInLaunchRegion())
1349 const Box& bx = mfi.growntilebox(nghost);
1352 auto const srcFab = src.
array(mfi);
1353 auto dstFab = dst.
array(mfi);
1356 dstFab(i,j,k,n+dstcomp) /= srcFab(i,j,k,n+srccomp);
1364 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1372 class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1378 auto const& fabarr = fa.
arrays();
1382 fabarr[box_no](i,j,k,n+icomp) = std::abs(fabarr[box_no](i,j,k,n+icomp));
1391#pragma omp parallel if (Gpu::notInLaunchRegion())
1395 const Box& bx = mfi.growntilebox(nghost);
1398 auto const& fab = fa.
array(mfi);
1401 fab(i,j,k,n+icomp) = std::abs(fab(i,j,k,n+icomp));
1408template <class FAB, class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1423template <class FAB, class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1439template <class FAB, class IFAB, class bar = std::enable_if_t<IsBaseFab<FAB>::value
1440 && IsBaseFab<IFAB>::value> >
1451template <class FAB, class IFAB, class bar = std::enable_if_t<IsBaseFab<FAB>::value
1452 && IsBaseFab<IFAB>::value> >
1461 const int ncomp = fa.
nComp();
1465 auto const& fabarr = fa.
arrays();
1470 if (!ifabarr[box_no](i,j,k)) { fabarr[box_no](i,j,k,n) = 0; }
1479#pragma omp parallel if (Gpu::notInLaunchRegion())
1483 const Box& bx = mfi.tilebox();
1484 auto fab = fa.
array(mfi);
1485 auto const ifab = msk.
array(mfi);
1488 if (!ifab(i,j,k)) { fab(i,j,k,n) = 0; }
1499template <class FAB, class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
1507 fa.
os_temp->ParallelCopy_finish();
1513template <class FAB, class foo = std::enable_if_t<IsBaseFab<FAB>::value> >
1516 int scomp,
int dcomp,
int ncomp)
1522 void*
pdst = dst[mfi].dataPtr(dcomp);
1523 void const* psrc = src[mfi].dataPtr(scomp);
1531template <class FAB, class foo = std::enable_if_t<IsBaseFab<FAB>::value> >
1538template <class FAB, class foo = std::enable_if_t<IsBaseFab<FAB>::value> >
1541 int scomp,
int dcomp,
int ncomp)
1547 void*
pdst = dst[mfi].dataPtr(dcomp);
1548 void const* psrc = src[mfi].dataPtr(scomp);
1556template <class FAB, class foo = std::enable_if_t<IsBaseFab<FAB>::value> >
1563template <class FAB, class foo = std::enable_if_t<IsBaseFab<FAB>::value> >
1566 typename FAB::value_type value)
1583 if (ma[box_no](i,j,k,comp) == value) {
1600 if (arr(i,j,k,comp) == value) {
1611 int const* tmp = aa.copyToHost();
1627 const Box& bx = mfi.growntilebox(nghost);
1631 if (fab(i,j,k,comp) == value) {
1642#if defined(AMREX_USE_OMP) && defined(_OPENMP) && (_OPENMP < 201307 || (defined(__NVCOMPILER) && __NVCOMPILER_MAJOR__ < 23))
1643#pragma omp critical (amrex_indexfromvalue)
1644#elif defined(AMREX_USE_OMP)
1645#pragma omp atomic capture
1652 if (old ==
false) { loc = priv_loc; }
1671template <typename FAB, std::enable_if_t<IsBaseFab<FAB>::value,
int> FOO = 0>
1672typename FAB::value_type
1674 IntVect const& nghost,
bool local =
false)
1677 BL_ASSERT(
x.DistributionMap() ==
y.DistributionMap());
1678 BL_ASSERT(
x.nGrowVect().allGE(nghost) &&
y.nGrowVect().allGE(nghost));
1682 using T =
typename FAB::value_type;
1686 auto const& xma =
x.const_arrays();
1687 auto const& yma =
y.const_arrays();
1692 auto const& xfab = xma[box_no];
1693 auto const& yfab = yma[box_no];
1694 for (
int n = 0; n < ncomp; ++n) {
1695 t += xfab(i,j,k,xcomp+n) * yfab(i,j,k,ycomp+n);
1703#pragma omp parallel if (!system::regtest_reduction) reduction(+:sm)
1707 Box const& bx = mfi.growntilebox(nghost);
1708 auto const& xfab =
x.const_array(mfi);
1709 auto const& yfab =
y.const_array(mfi);
1712 sm += xfab(i,j,k,xcomp+n) * yfab(i,j,k,ycomp+n);
1733template <typename FAB, std::enable_if_t<IsBaseFab<FAB>::value,
int> FOO = 0>
1734typename FAB::value_type
1741 using T =
typename FAB::value_type;
1745 auto const& xma =
x.const_arrays();
1750 auto const& xfab = xma[box_no];
1751 for (
int n = 0; n < ncomp; ++n) {
1752 auto v = xfab(i,j,k,xcomp+n);
1761#pragma omp parallel if (!system::regtest_reduction) reduction(+:sm)
1765 Box const& bx = mfi.growntilebox(nghost);
1766 auto const& xfab =
x.const_array(mfi);
1769 auto v = xfab(i,j,k,xcomp+n);
1794template <
typename IFAB,
typename FAB,
1795 std::enable_if_t<IsBaseFab<FAB>::value && IsBaseFab<IFAB>::value,
int> FOO = 0>
1796typename FAB::value_type
1801 BL_ASSERT(
x.boxArray() ==
y.boxArray() &&
x.boxArray() ==
mask.boxArray());
1802 BL_ASSERT(
x.DistributionMap() ==
y.DistributionMap() &&
x.DistributionMap() ==
mask.DistributionMap());
1803 BL_ASSERT(
x.nGrowVect().allGE(nghost) &&
y.nGrowVect().allGE(nghost) &&
1804 mask.nGrowVect().allGE(nghost));
1808 using T =
typename FAB::value_type;
1812 auto const& mma =
mask.const_arrays();
1813 auto const& xma =
x.const_arrays();
1814 auto const& yma =
y.const_arrays();
1819 auto m = T(mma[box_no](i,j,k));
1821 auto const& xfab = xma[box_no];
1822 auto const& yfab = yma[box_no];
1823 for (
int n = 0; n < ncomp; ++n) {
1824 t += xfab(i,j,k,xcomp+n) * yfab(i,j,k,ycomp+n);
1833#pragma omp parallel if (!system::regtest_reduction) reduction(+:sm)
1837 Box const& bx = mfi.growntilebox(nghost);
1838 auto const& mfab =
mask.const_array(mfi);
1839 auto const& xfab =
x.const_array(mfi);
1840 auto const& yfab =
y.const_array(mfi);
1843 auto m = T(mfab(i,j,k));
1844 sm += m * xfab(i,j,k,xcomp+n) * yfab(i,j,k,ycomp+n);
1866template <
typename IFAB,
typename FAB,
1867 std::enable_if_t<IsBaseFab<FAB>::value && IsBaseFab<IFAB>::value,
int> FOO = 0>
1868typename FAB::value_type
1870 IntVect const& nghost,
bool local =
false)
1874 BL_ASSERT(
x.nGrowVect().allGE(nghost) &&
mask.nGrowVect().allGE(nghost));
1878 using T =
typename FAB::value_type;
1882 auto const& mma =
mask.const_arrays();
1883 auto const& xma =
x.const_arrays();
1888 auto m = T(mma[box_no](i,j,k));
1890 auto const& xfab = xma[box_no];
1891 for (
int n = 0; n < ncomp; ++n) {
1892 auto v = xfab(i,j,k,xcomp+n);
1902#pragma omp parallel if (!system::regtest_reduction) reduction(+:sm)
1906 Box const& bx = mfi.growntilebox(nghost);
1907 auto const& mfab =
mask.const_array(mfi);
1908 auto const& xfab =
x.const_array(mfi);
1911 auto m = T(mfab(i,j,k));
1912 auto v = xfab(i,j,k,xcomp+n);
1926template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
1927void setVal (MF& dst,
typename MF::value_type val)
1933template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
1934void setBndry (MF& dst,
typename MF::value_type val,
int scomp,
int ncomp)
1936 dst.setBndry(val, scomp, ncomp);
1940template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
1941void Scale (MF& dst,
typename MF::value_type val,
int scomp,
int ncomp,
int nghost)
1943 dst.mult(val, scomp, ncomp, nghost);
1947template <
class DMF,
class SMF,
1948 std::enable_if_t<IsMultiFabLike_v<DMF> &&
1949 IsMultiFabLike_v<SMF>,
int> = 0>
1950void LocalCopy (DMF& dst, SMF
const& src,
int scomp,
int dcomp,
1951 int ncomp,
IntVect const& nghost)
1953 amrex::Copy(dst, src, scomp, dcomp, ncomp, nghost);
1957template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
1958void LocalAdd (MF& dst, MF
const& src,
int scomp,
int dcomp,
1959 int ncomp,
IntVect const& nghost)
1961 amrex::Add(dst, src, scomp, dcomp, ncomp, nghost);
1965template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
1966void Saxpy (MF& dst,
typename MF::value_type a, MF
const& src,
int scomp,
int dcomp,
1967 int ncomp,
IntVect const& nghost)
1969 MF::Saxpy(dst, a, src, scomp, dcomp, ncomp, nghost);
1973template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
1974void Xpay (MF& dst,
typename MF::value_type a, MF
const& src,
int scomp,
int dcomp,
1975 int ncomp,
IntVect const& nghost)
1977 MF::Xpay(dst, a, src, scomp, dcomp, ncomp, nghost);
1981template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
1982void Saxpy_Xpay (MF& dst,
typename MF::value_type a_saxpy, MF
const& src_saxpy,
1983 typename MF::value_type a_xpay, MF
const& src_xpay,
int scomp,
int dcomp,
1984 int ncomp,
IntVect const& nghost)
1986 MF::Saxpy_Xpay(dst, a_saxpy, src_saxpy, a_xpay, src_xpay, scomp, dcomp, ncomp, nghost);
1990template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
1991void Saxpy_Saxpy (MF& dst1,
typename MF::value_type a1, MF
const& src1,
1992 MF& dst2,
typename MF::value_type a2, MF
const& src2,
int scomp,
int dcomp,
1993 int ncomp,
IntVect const& nghost)
1995 MF::Saxpy_Saxpy(dst1, a1, src1, dst2, a2, src2, scomp, dcomp, ncomp, nghost);
1999template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2001 MF& dst2,
typename MF::value_type a2, MF
const& src,
int scomp,
int dcomp,
2002 int ncomp,
IntVect const& nghost)
2004 MF::Saypy_Saxpy(dst1, a1, dst2, a2, src, scomp, dcomp, ncomp, nghost);
2008template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2010 typename MF::value_type a, MF
const& src_a,
int acomp,
2011 typename MF::value_type b, MF
const& src_b,
int bcomp,
2012 int dcomp,
int ncomp,
IntVect const& nghost)
2014 MF::LinComb(dst, a, src_a, acomp, b, src_b, bcomp, dcomp, ncomp, nghost);
2018template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2024 dst.ParallelCopy(src, scomp, dcomp, ncomp, ng_src, ng_dst, period);
2027template <
class MF, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2028[[nodiscard]]
typename MF::value_type
2032 return mf.norminf(scomp, ncomp, nghost, local);
2036template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2039 for (
auto& mf: dst) {
2045template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2048 for (
auto& mf : dst) {
2054template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2058 for (
auto& mf : dst) {
2059 mf.
mult(val, scomp, ncomp, nghost);
2064template <
class DMF,
class SMF, std::size_t N,
2065 std::enable_if_t<IsMultiFabLike_v<DMF> &&
2066 IsMultiFabLike_v<SMF>,
int> = 0>
2068 int ncomp,
IntVect const& nghost)
2070 for (std::size_t i = 0; i < N; ++i) {
2071 amrex::Copy(dst[i], src[i], scomp, dcomp, ncomp, nghost);
2076template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2078 int ncomp,
IntVect const& nghost)
2080 for (std::size_t i = 0; i < N; ++i) {
2081 amrex::Add(dst[i], src[i], scomp, dcomp, ncomp, nghost);
2086template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2088 Array<MF,N> const& src,
int scomp,
int dcomp,
int ncomp,
2091 for (std::size_t i = 0; i < N; ++i) {
2092 MF::Saxpy(dst[i], a, src[i], scomp, dcomp, ncomp, nghost);
2097template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2099 Array<MF,N> const& src,
int scomp,
int dcomp,
int ncomp,
2102 for (std::size_t i = 0; i < N; ++i) {
2103 MF::Xpay(dst[i], a, src[i], scomp, dcomp, ncomp, nghost);
2108template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2110 typename MF::value_type a,
Array<MF,N> const& src_a,
int acomp,
2111 typename MF::value_type b,
Array<MF,N> const& src_b,
int bcomp,
2112 int dcomp,
int ncomp,
IntVect const& nghost)
2114 for (std::size_t i = 0; i < N; ++i) {
2115 MF::LinComb(dst[i], a, src_a[i], acomp, b, src_b[i], bcomp, dcomp, ncomp, nghost);
2120template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2122 int scomp,
int dcomp,
int ncomp,
2127 for (std::size_t i = 0; i < N; ++i) {
2128 dst[i].ParallelCopy(src[i], scomp, dcomp, ncomp, ng_src, ng_dst, period);
2132template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF>,
int> = 0>
2133[[nodiscard]]
typename MF::value_type
2137 auto r =
typename MF::value_type(0);
2138 for (std::size_t i = 0; i < N; ++i) {
2139 auto tmp = mf[i].norminf(scomp, ncomp, nghost,
true);
2140 r = std::max(r,tmp);
2148template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF> && (N > 0),
2152 return mf[0].nComp();
2155template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF> && (N > 0),
2159 return mf[0].nGrowVect();
2162template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF> && (N > 0),
2164[[nodiscard]] BoxArray
const&
2167 return mf[0].boxArray();
2170template <
class MF, std::
size_t N, std::enable_if_t<IsMultiFabLike_v<MF> && (N > 0),
2172[[nodiscard]] DistributionMapping
const&
2175 return mf[0].DistributionMap();
2186FabArray<BaseFab<int>>
2197 const std::vector<IntVect>& pshifts = period.
shiftIntVect();
2204#pragma omp parallel if (!run_on_gpu)
2207 std::vector< std::pair<int,Box> > isects;
2211 const Box& bx =
mask[mfi].box();
2212 auto const& arr =
mask.array(mfi);
2214 for (
const auto& iv : pshifts)
2217 for (
const auto& is : isects)
2219 Box const& b = is.second-iv;
2220 if (iv == 0 && b == bx) {
continue; }
2223 tags.push_back({arr,b});
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:551
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:37
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:111
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Real * pdst
Definition AMReX_HypreMLABecLap.cpp:1090
Array4< int const > mask
Definition AMReX_InterpFaceRegister.cpp:93
#define AMREX_LOOP_3D(bx, i, j, k, block)
Definition AMReX_Loop.nolint.H:4
#define AMREX_LOOP_4D(bx, ncomp, i, j, k, n, block)
Definition AMReX_Loop.nolint.H:16
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Print on all processors of the default communicator.
Definition AMReX_Print.H:117
virtual bool isManaged() const
Definition AMReX_Arena.cpp:88
virtual bool isDevice() const
Definition AMReX_Arena.cpp:100
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:567
std::vector< std::pair< int, Box > > intersections(const Box &bx) const
Return intersections of Box and BoxArray.
Definition AMReX_BoxArray.cpp:1186
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:212
__host__ __device__ bool ok() const noexcept
Checks if it is a proper BoxND (including a valid type).
Definition AMReX_Box.H:208
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:43
IntVect nGrowVect() const noexcept
Definition AMReX_FabArrayBase.H:80
bool isFusingCandidate() const noexcept
Is this a good candidate for kernel fusing?
Definition AMReX_FabArrayBase.cpp:2707
IndexType ixType() const noexcept
Return index type.
Definition AMReX_FabArrayBase.H:86
const DistributionMapping & DistributionMap() const noexcept
Return constant reference to associated DistributionMapping.
Definition AMReX_FabArrayBase.H:131
@ ADD
Definition AMReX_FabArrayBase.H:394
int nComp() const noexcept
Return number of variables (aka components) associated with each point.
Definition AMReX_FabArrayBase.H:83
const BoxArray & boxArray() const noexcept
Return a constant reference to the BoxArray that defines the valid region associated with this FabArr...
Definition AMReX_FabArrayBase.H:95
An Array of FortranArrayBox(FAB)-like Objects.
Definition AMReX_FabArray.H:347
Array4< typename FabArray< FAB >::value_type const > const_array(const MFIter &mfi) const noexcept
Definition AMReX_FabArray.H:587
std::unique_ptr< FabArray< FAB > > os_temp
Definition AMReX_FabArray.H:1626
const FabFactory< FAB > & Factory() const noexcept
Definition AMReX_FabArray.H:445
void prefetchToDevice(const MFIter &mfi) const noexcept
Definition AMReX_FabArray.H:553
Array4< typename FabArray< FAB >::value_type const > array(const MFIter &mfi) const noexcept
Definition AMReX_FabArray.H:563
Arena * arena() const noexcept
Definition AMReX_FabArray.H:448
void setBndry(value_type val)
Set all values in the boundary region to val.
Definition AMReX_FabArray.H:2442
void setVal(value_type val)
Set all components in the entire region of each FAB to val.
Definition AMReX_FabArray.H:2652
MultiArray4< typename FabArray< FAB >::value_type > arrays() noexcept
Definition AMReX_FabArray.H:635
void mult(value_type val, int comp, int num_comp, int nghost=0)
Definition AMReX_FabArray.H:2905
bool hasEBFabFactory() const noexcept
Definition AMReX_FabArray.H:452
MultiArray4< typename FabArray< FAB >::value_type const > const_arrays() const noexcept
Definition AMReX_FabArray.H:649
void prefetchToHost(const MFIter &mfi) const noexcept
Definition AMReX_FabArray.H:543
GPU-compatible tuple.
Definition AMReX_Tuple.H:98
Definition AMReX_GpuBuffer.H:18
T const * data() const noexcept
Definition AMReX_GpuBuffer.H:45
__host__ __device__ bool cellCentered() const noexcept
True if the IndexTypeND is CELL based in all directions.
Definition AMReX_IndexType.H:104
__host__ __device__ bool allGT(const IntVectND< dim > &rhs) const noexcept
Returns true if this is greater than argument for all components. NOTE: This is NOT a strict weak ord...
Definition AMReX_IntVect.H:426
__host__ static __device__ constexpr IntVectND< dim > TheZeroVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:680
__host__ static __device__ constexpr IntVectND< dim > TheMinVector() noexcept
Definition AMReX_IntVect.H:728
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:63
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:147
Dynamically allocated vector for trivially copyable data.
Definition AMReX_PODVector.H:308
T * data() noexcept
Definition AMReX_PODVector.H:666
This provides length of period for periodic domains. 0 means it is not periodic in that direction....
Definition AMReX_Periodicity.H:17
static const Periodicity & NonPeriodic() noexcept
Definition AMReX_Periodicity.cpp:52
std::vector< IntVect > shiftIntVect(IntVect const &nghost=IntVect(0)) const
Definition AMReX_Periodicity.cpp:8
Print & SetPrecision(int p)
Definition AMReX_Print.H:89
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Grow BoxND in all directions by given amount.
Definition AMReX_Box.H:1280
std::array< T, N > Array
Definition AMReX_Array.H:25
void Sum(T &v, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:221
void Max(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:133
__host__ __device__ AMREX_FORCE_INLINE T Exch(T *address, T val) noexcept
Definition AMReX_GpuAtomic.H:487
__host__ __device__ AMREX_FORCE_INLINE void AddNoRet(T *sum, T value) noexcept
Definition AMReX_GpuAtomic.H:283
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:263
void dtoh_memcpy_async(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:315
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:92
bool inNoSyncRegion() noexcept
Definition AMReX_GpuControl.H:152
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:301
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
Definition AMReX_Amr.cpp:49
MF::value_type norminf(MF const &mf, int scomp, int ncomp, IntVect const &nghost, bool local=false)
Definition AMReX_FabArrayUtility.H:2029
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:138
int nComp(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2854
FAB::value_type ReduceMax(FabArray< FAB > const &fa, int nghost, F &&f)
Definition AMReX_FabArrayUtility.H:555
__host__ __device__ void Swap(T &t1, T &t2) noexcept
Definition AMReX_Algorithm.H:75
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:193
DistributionMapping const & DistributionMap(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2869
void Saxpy(MF &dst, typename MF::value_type a, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst += a * src
Definition AMReX_FabArrayUtility.H:1966
IntVect nGrowVect(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2859
ReduceData< Ts... >::Type ParReduce(TypeList< Ops... > operation_list, TypeList< Ts... > type_list, FabArray< FAB > const &fa, IntVect const &nghost, F &&f)
Parallel reduce for MultiFab/FabArray. The reduce result is local and it's the user's responsibility ...
Definition AMReX_ParReduce.H:48
void LocalCopy(DMF &dst, SMF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst = src
Definition AMReX_FabArrayUtility.H:1950
void printCell(FabArray< FAB > const &mf, const IntVect &cell, int comp=-1, const IntVect &ng=IntVect::TheZeroVector())
Definition AMReX_FabArrayUtility.H:1103
bool ReduceLogicalAnd(FabArray< FAB > const &fa, int nghost, F &&f)
Definition AMReX_FabArrayUtility.H:794
void Abs(FabArray< FAB > &fa, int icomp, int numcomp, int nghost)
Definition AMReX_FabArrayUtility.H:1366
void LocalAdd(MF &dst, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst += src
Definition AMReX_FabArrayUtility.H:1958
void Copy(FabArray< DFAB > &dst, FabArray< SFAB > const &src, int srccomp, int dstcomp, int numcomp, int nghost)
Definition AMReX_FabArray.H:180
void prefetchToDevice(FabArray< FAB > const &fa, const bool synchronous=true)
Definition AMReX_FabArrayUtility.H:1425
__host__ __device__ BoxND< dim > makeSingleCellBox(int i, int j, int k, IndexTypeND< dim > typ=IndexTypeND< dim >::TheCellType())
Definition AMReX_Box.H:2134
void Subtract(FabArray< FAB > &dst, FabArray< FAB > const &src, int srccomp, int dstcomp, int numcomp, int nghost)
Definition AMReX_FabArrayUtility.H:1223
void OverrideSync(FabArray< FAB > &fa, FabArray< IFAB > const &msk, const Periodicity &period)
Definition AMReX_FabArrayUtility.H:1442
FabArray< BaseFab< int > > OverlapMask(FabArray< FAB > const &fa, IntVect const &nghost, Periodicity const &period)
Definition AMReX_FabArrayUtility.H:2187
void Saxpy_Saxpy(MF &dst1, typename MF::value_type a1, MF const &src1, MF &dst2, typename MF::value_type a2, MF const &src2, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst1 += a1 * src1 followed by dst2 += a2 * src2
Definition AMReX_FabArrayUtility.H:1991
bool isMFIterSafe(const FabArrayBase &x, const FabArrayBase &y)
Definition AMReX_MFIter.H:225
void Saypy_Saxpy(MF &dst1, typename MF::value_type a1, MF &dst2, typename MF::value_type a2, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst1 += a1 * dst2 followed by dst2 += a2 * src
Definition AMReX_FabArrayUtility.H:2000
bool ReduceLogicalOr(FabArray< FAB > const &fa, int nghost, F &&f)
Definition AMReX_FabArrayUtility.H:949
void LinComb(MF &dst, typename MF::value_type a, MF const &src_a, int acomp, typename MF::value_type b, MF const &src_b, int bcomp, int dcomp, int ncomp, IntVect const &nghost)
dst = a*src_a + b*src_b
Definition AMReX_FabArrayUtility.H:2009
FAB::value_type ReduceMin(FabArray< FAB > const &fa, int nghost, F &&f)
Definition AMReX_FabArrayUtility.H:317
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:30
void dtoh_memcpy(FabArray< FAB > &dst, FabArray< FAB > const &src, int scomp, int dcomp, int ncomp)
Definition AMReX_FabArrayUtility.H:1515
void setBndry(MF &dst, typename MF::value_type val, int scomp, int ncomp)
dst = val in ghost cells.
Definition AMReX_FabArrayUtility.H:1934
void Saxpy_Xpay(MF &dst, typename MF::value_type a_saxpy, MF const &src_saxpy, typename MF::value_type a_xpay, MF const &src_xpay, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst += a_saxpy * src_saxpy followed by dst = src_xpay + a_xpay * dst
Definition AMReX_FabArrayUtility.H:1982
void single_task(L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1362
void Divide(FabArray< FAB > &dst, FabArray< FAB > const &src, int srccomp, int dstcomp, int numcomp, int nghost)
Definition AMReX_FabArrayUtility.H:1319
void Xpay(MF &dst, typename MF::value_type a, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst = src + a * dst
Definition AMReX_FabArrayUtility.H:1974
void Scale(MF &dst, typename MF::value_type val, int scomp, int ncomp, int nghost)
dst *= val
Definition AMReX_FabArrayUtility.H:1941
void prefetchToHost(FabArray< FAB > const &fa, const bool synchronous=true)
Definition AMReX_FabArrayUtility.H:1410
bool TilingIfNotGPU() noexcept
Definition AMReX_MFIter.H:12
void Add(FabArray< FAB > &dst, FabArray< FAB > const &src, int srccomp, int dstcomp, int numcomp, int nghost)
Definition AMReX_FabArray.H:241
void LoopConcurrentOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition AMReX_Loop.H:388
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
void OverrideSync_finish(FabArray< FAB > &fa)
Definition AMReX_FabArrayUtility.H:1501
FAB::value_type Dot(FabArray< FAB > const &x, int xcomp, FabArray< FAB > const &y, int ycomp, int ncomp, IntVect const &nghost, bool local=false)
Compute dot products of two FabArrays.
Definition AMReX_FabArrayUtility.H:1673
void ParallelCopy(MF &dst, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &ng_src=IntVect(0), IntVect const &ng_dst=IntVect(0), Periodicity const &period=Periodicity::NonPeriodic())
dst = src w/ MPI communication
Definition AMReX_FabArrayUtility.H:2019
void htod_memcpy(FabArray< FAB > &dst, FabArray< FAB > const &src, int scomp, int dcomp, int ncomp)
Definition AMReX_FabArrayUtility.H:1540
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition AMReX_FabArrayUtility.H:1927
void Multiply(FabArray< FAB > &dst, FabArray< FAB > const &src, int srccomp, int dstcomp, int numcomp, int nghost)
Definition AMReX_FabArrayUtility.H:1271
FAB::value_type ReduceSum(FabArray< FAB > const &fa, int nghost, F &&f)
Definition AMReX_FabArrayUtility.H:16
IntVect indexFromValue(FabArray< FAB > const &mf, int comp, IntVect const &nghost, typename FAB::value_type value)
Definition AMReX_FabArrayUtility.H:1565
BoxArray const & boxArray(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2864
void OverrideSync_nowait(FabArray< FAB > &fa, FabArray< IFAB > const &msk, const Periodicity &period)
Definition AMReX_FabArrayUtility.H:1454
Definition AMReX_TagParallelFor.H:58
Array4< T > dfab
Definition AMReX_TagParallelFor.H:59
FabArray memory allocation information.
Definition AMReX_FabArray.H:66
Definition AMReX_MFIter.H:20
Struct for holding types.
Definition AMReX_TypeList.H:12