1#ifndef AMREX_GPU_LAUNCH_FUNCTS_C_H_
2#define AMREX_GPU_LAUNCH_FUNCTS_C_H_
3#include <AMReX_Config.H>
12 template <
typename F,
typename N>
14 auto call_f_scalar_handler (
F const& f, N i)
15 noexcept ->
decltype(f(0))
20 template <
typename F,
typename N>
22 auto call_f_scalar_handler (
F const& f, N i)
23 noexcept ->
decltype(f(0,Gpu::Handler{}))
25 return f(i, Gpu::Handler{});
30 template <
typename F, std::size_t...Ns,
class...Args>
32 auto call_f_intvect_inner (std::index_sequence<Ns...>,
F const& f, IntVectND<1> iv, Args...args)
33 noexcept -> decltype(f(0, 0, 0, args...))
35 return f(iv[0], 0, 0, args...);
38 template <
typename F, std::size_t...Ns,
class...Args>
40 auto call_f_intvect_inner (std::index_sequence<Ns...>,
F const& f, IntVectND<2> iv, Args...args)
41 noexcept -> decltype(f(0, 0, 0, args...))
43 return f(iv[0], iv[1], 0, args...);
46 template <
typename F,
int dim, std::size_t...Ns,
class...Args>
48 auto call_f_intvect_inner (std::index_sequence<Ns...>,
F const& f, IntVectND<dim> iv, Args...args)
49 noexcept -> decltype(f(iv, args...))
51 return f(iv, args...);
54 template <
typename F,
int dim, std::size_t...Ns,
class...Args>
56 auto call_f_intvect_inner (std::index_sequence<Ns...>,
F const& f, IntVectND<dim> iv, Args...args)
57 noexcept -> decltype(f(iv[Ns]..., args...))
59 return f(iv[Ns]..., args...);
64 template <
typename F,
int dim>
66 auto call_f_intvect_engine (
F const& f, IntVectND<dim> iv, RandomEngine engine)
67 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, engine))
69 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, engine);
74 template <
typename F,
int dim>
76 auto call_f_intvect_handler (
F const& f, IntVectND<dim> iv)
77 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv))
79 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv);
82 template <
typename F,
int dim>
84 auto call_f_intvect_handler (
F const& f, IntVectND<dim> iv)
85 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, Gpu::Handler{}))
87 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, Gpu::Handler{});
92 template <
typename F,
typename T,
int dim>
94 auto call_f_intvect_ncomp_engine (
F const& f, IntVectND<dim> iv, T n, RandomEngine engine)
95 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, engine))
97 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, engine);
102 template <
typename F,
typename T,
int dim>
104 auto call_f_intvect_ncomp_handler (
F const& f, IntVectND<dim> iv, T n)
105 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n))
107 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n);
110 template <
typename F,
typename T,
int dim>
112 auto call_f_intvect_ncomp_handler (
F const& f, IntVectND<dim> iv, T n)
113 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, Gpu::Handler{}))
115 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, Gpu::Handler{});
121template<
typename T,
typename L>
122void launch (T
const& n, L
const& f)
noexcept
131template<
int MT,
typename T,
typename L>
132void launch (T
const& n, L
const& f)
noexcept
140template <std::
integral T,
typename L >
142void For (T n, L
const& f)
noexcept
144 for (T i = 0; i < n; ++i) {
145 detail::call_f_scalar_handler(f,i);
149template <
int MT, std::
integral T,
typename L >
150void For (T n, L&& f)
noexcept
153 For(n, std::forward<L>(f));
156template <std::
integral T,
typename L >
159 For(n, std::forward<L>(f));
162template <
int MT, std::
integral T,
typename L >
166 For(n, std::forward<L>(f));
169template <std::
integral T,
typename L >
174 for (T i = 0; i < n; ++i) {
175 detail::call_f_scalar_handler(f,i);
179template <
int MT, std::
integral T,
typename L >
186template <std::
integral T,
typename L >
192template <
int MT, std::
integral T,
typename L >
202template <
int idim,
typename L,
int dim>
204void For_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
206 if constexpr (idim == 1) {
207 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
208 call_f_intvect_handler(f,iv);
210 }
else if constexpr (idim == 2) {
211 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
212 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
213 call_f_intvect_handler(f,iv);
215 }
else if constexpr (idim == 3) {
216 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
217 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
218 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
219 call_f_intvect_handler(f,iv);
222 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
223 For_impND<idim-1>(f, lo, hi, iv);
231template <
typename L,
int dim>
238 detail::For_impND<dim>(f, lo, hi, iv);
241template <
int MT,
typename L,
int dim>
245 For(box, std::forward<L>(f));
248template <
typename L,
int dim>
251 For(box, std::forward<L>(f));
254template <
int MT,
typename L,
int dim>
258 For(box, std::forward<L>(f));
264template <
int idim,
typename L,
int dim>
266void ParallelFor_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
268 if constexpr (idim == 1) {
270 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
271 call_f_intvect_handler(f,iv);
273 }
else if constexpr (idim == 2) {
274 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
276 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
277 call_f_intvect_handler(f,iv);
279 }
else if constexpr (idim == 3) {
280 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
281 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
283 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
284 call_f_intvect_handler(f,iv);
287 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
288 ParallelFor_impND<idim-1>(f, lo, hi, iv);
296template <
typename L,
int dim>
303 detail::ParallelFor_impND<dim>(f, lo, hi, iv);
306template <
int MT,
typename L,
int dim>
313template <
typename L,
int dim>
319template <
int MT,
typename L,
int dim>
329template <
int idim,
typename L,
typename T,
int dim>
331void For_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
333 if constexpr (idim == 1) {
334 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
335 call_f_intvect_ncomp_handler(f,iv,n);
337 }
else if constexpr (idim == 2) {
338 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
339 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
340 call_f_intvect_ncomp_handler(f,iv,n);
342 }
else if constexpr (idim == 3) {
343 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
344 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
345 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
346 call_f_intvect_ncomp_handler(f,iv,n);
349 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
350 For_impND<idim-1>(f, lo, hi, iv, n);
358template <std::
integral T,
typename L,
int dim >
365 for (T n = 0; n < ncomp; ++n) {
366 detail::For_impND<dim>(f, lo, hi, iv, n);
370template <
int MT, std::
integral T,
typename L,
int dim >
374 For(box, ncomp, std::forward<L>(f));
377template <std::
integral T,
typename L,
int dim >
380 For(box, ncomp, std::forward<L>(f));
383template <
int MT, std::
integral T,
typename L,
int dim >
387 For(box, ncomp, std::forward<L>(f));
393template <
int idim,
typename L,
typename T,
int dim>
395void ParallelFor_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
397 if constexpr (idim == 1) {
399 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
400 call_f_intvect_ncomp_handler(f,iv,n);
402 }
else if constexpr (idim == 2) {
403 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
405 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
406 call_f_intvect_ncomp_handler(f,iv,n);
408 }
else if constexpr (idim == 3) {
409 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
410 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
412 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
413 call_f_intvect_ncomp_handler(f,iv,n);
416 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
417 ParallelFor_impND<idim-1>(f, lo, hi, iv, n);
425template <std::
integral T,
typename L,
int dim >
432 for (T n = 0; n < ncomp; ++n) {
433 detail::ParallelFor_impND<dim>(f, lo, hi, iv, n);
437template <
int MT, std::
integral T,
typename L,
int dim >
444template <std::
integral T,
typename L,
int dim >
450template <
int MT, std::
integral T,
typename L,
int dim >
457template <
typename L1,
typename L2,
int dim>
460 For(box1, std::forward<L1>(f1));
461 For(box2, std::forward<L2>(f2));
464template <
int MT,
typename L1,
typename L2,
int dim>
468 For(box1, std::forward<L1>(f1));
469 For(box2, std::forward<L2>(f2));
472template <
typename L1,
typename L2,
int dim>
475 For (box1, box2, std::forward<L1>(f1), std::forward<L2>(f2));
478template <
int MT,
typename L1,
typename L2,
int dim>
482 For (box1, box2, std::forward<L1>(f1), std::forward<L2>(f2));
485template <
typename L1,
typename L2,
typename L3,
int dim>
488 For(box1, std::forward<L1>(f1));
489 For(box2, std::forward<L2>(f2));
490 For(box3, std::forward<L3>(f3));
493template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
497 For(box1, std::forward<L1>(f1));
498 For(box2, std::forward<L2>(f2));
499 For(box3, std::forward<L3>(f3));
502template <
typename L1,
typename L2,
typename L3,
int dim>
505 For(box1, box2, box3, std::forward<L1>(f1), std::forward<L2>(f2), std::forward<L3>(f3));
508template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
512 For(box1, box2, box3, std::forward<L1>(f1), std::forward<L2>(f2), std::forward<L3>(f3));
515template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
517 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
519 For(box1, ncomp1, std::forward<L1>(f1));
520 For(box2, ncomp2, std::forward<L2>(f2));
523template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
525 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
528 For(box1, ncomp1, std::forward<L1>(f1));
529 For(box2, ncomp2, std::forward<L2>(f2));
532template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
535 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
537 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
540template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
543 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
546 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
549template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
552 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
554 For(box1, ncomp1, std::forward<L1>(f1));
555 For(box2, ncomp2, std::forward<L2>(f2));
556 For(box3, ncomp3, std::forward<L3>(f3));
559template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
562 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
565 For(box1, ncomp1, std::forward<L1>(f1));
566 For(box2, ncomp2, std::forward<L2>(f2));
567 For(box3, ncomp3, std::forward<L3>(f3));
570template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
574 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
576 For(box1,ncomp1,std::forward<L1>(f1),
577 box2,ncomp2,std::forward<L2>(f2),
578 box3,ncomp3,std::forward<L3>(f3));
581template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
585 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
588 For(box1,ncomp1,std::forward<L1>(f1),
589 box2,ncomp2,std::forward<L2>(f2),
590 box3,ncomp3,std::forward<L3>(f3));
593template <
typename L1,
typename L2,
int dim>
600template <
int MT,
typename L1,
typename L2,
int dim>
608template <
typename L1,
typename L2,
int dim>
611 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
614template <
int MT,
typename L1,
typename L2,
int dim>
618 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
621template <
typename L1,
typename L2,
typename L3,
int dim>
629template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
638template <
typename L1,
typename L2,
typename L3,
int dim>
641 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
644template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
648 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
651template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
653 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
659template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
661 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
668template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
671 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
674 box2,ncomp2,std::forward<L2>(f2));
677template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
680 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
684 box2,ncomp2,std::forward<L2>(f2));
687template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
690 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
697template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
700 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
708template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
712 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
715 box2, ncomp2, std::forward<L2>(f2),
716 box3, ncomp3, std::forward<L3>(f3));
719template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
723 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
727 box2, ncomp2, std::forward<L2>(f2),
728 box3, ncomp3, std::forward<L3>(f3));
731template <std::
integral T,
typename L >
737template <
int MT, std::
integral T,
typename L >
744template <
typename L,
int dim>
750template <
int MT,
typename L,
int dim>
757template <std::
integral T,
typename L,
int dim >
763template <
int MT, std::
integral T,
typename L,
int dim >
770template <
typename L1,
typename L2,
int dim>
773 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
776template <
int MT,
typename L1,
typename L2,
int dim>
780 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
783template <
typename L1,
typename L2,
typename L3,
int dim>
785 L1&& f1, L2&& f2, L3&& f3)
noexcept
787 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
790template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
792 L1&& f1, L2&& f2, L3&& f3)
noexcept
795 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
798template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
800 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
802 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
805template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
807 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
810 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
813template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
816 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
819 box2,ncomp2,std::forward<L2>(f2),
820 box3,ncomp3,std::forward<L3>(f3));
823template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
826 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
830 box2,ncomp2,std::forward<L2>(f2),
831 box3,ncomp3,std::forward<L3>(f3));
834template <std::
integral T,
typename L >
837 For(n,std::forward<L>(f));
840template <
int MT, std::
integral T,
typename L >
844 For(n,std::forward<L>(f));
847template <
typename L,
int dim>
850 For(box,std::forward<L>(f));
853template <
int MT,
typename L,
int dim>
857 For(box,std::forward<L>(f));
860template <std::
integral T,
typename L,
int dim >
863 For(box,ncomp,std::forward<L>(f));
866template <
int MT, std::
integral T,
int dim,
typename L >
870 For(box,ncomp,std::forward<L>(f));
873template <
typename L1,
typename L2,
int dim>
876 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
879template <
int MT,
typename L1,
typename L2,
int dim>
883 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
886template <
typename L1,
typename L2,
typename L3,
int dim>
888 L1&& f1, L2&& f2, L3&& f3)
noexcept
890 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
893template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
895 L1&& f1, L2&& f2, L3&& f3)
noexcept
898 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
901template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
903 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
905 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
908template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
910 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
913 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
916template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
919 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
921 For(box1,ncomp1,std::forward<L1>(f1),
922 box2,ncomp2,std::forward<L2>(f2),
923 box3,ncomp3,std::forward<L3>(f3));
926template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
929 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
932 For(box1,ncomp1,std::forward<L1>(f1),
933 box2,ncomp2,std::forward<L2>(f2),
934 box3,ncomp3,std::forward<L3>(f3));
937template <std::
integral T,
typename L >
943template <
int MT, std::
integral T,
typename L >
950template <
typename L,
int dim>
956template <
int MT,
typename L,
int dim>
963template <std::
integral T,
typename L,
int dim >
969template <
int MT, std::
integral T,
typename L,
int dim >
976template <
typename L1,
typename L2,
int dim>
979 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
982template <
int MT,
typename L1,
typename L2,
int dim>
986 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
989template <
typename L1,
typename L2,
typename L3,
int dim>
992 L1&& f1, L2&& f2, L3&& f3)
noexcept
994 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
997template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
1000 L1&& f1, L2&& f2, L3&& f3)
noexcept
1003 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1006template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
1009 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1011 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1014template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
1017 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1020 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1023template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
1027 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1030 box2,ncomp2,std::forward<L2>(f2),
1031 box3,ncomp3,std::forward<L3>(f3));
1034template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
1038 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1042 box2,ncomp2,std::forward<L2>(f2),
1043 box3,ncomp3,std::forward<L3>(f3));
1046template <std::
integral T,
typename L >
1049 For(n,std::forward<L>(f));
1052template <
int MT, std::
integral T,
typename L >
1056 For(n,std::forward<L>(f));
1059template <
typename L,
int dim>
1062 For(box,std::forward<L>(f));
1065template <
int MT,
typename L,
int dim>
1069 For(box,std::forward<L>(f));
1072template <std::
integral T,
typename L,
int dim >
1075 For(box,ncomp,std::forward<L>(f));
1078template <
int MT, std::
integral T,
typename L,
int dim >
1082 For(box,ncomp,std::forward<L>(f));
1085template <
typename L1,
typename L2,
int dim>
1088 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1091template <
int MT,
typename L1,
typename L2,
int dim>
1095 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1098template <
typename L1,
typename L2,
typename L3,
int dim>
1101 L1&& f1, L2&& f2, L3&& f3)
noexcept
1103 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1106template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
1109 L1&& f1, L2&& f2, L3&& f3)
noexcept
1112 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1115template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
1118 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1120 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1123template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
1126 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1129 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1132template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
1136 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1138 For(box1,ncomp1,std::forward<L1>(f1),
1139 box2,ncomp2,std::forward<L2>(f2),
1140 box3,ncomp3,std::forward<L3>(f3));
1143template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
1147 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1150 For(box1,ncomp1,std::forward<L1>(f1),
1151 box2,ncomp2,std::forward<L2>(f2),
1152 box3,ncomp3,std::forward<L3>(f3));
1155template <std::
integral T,
typename L >
1159 for (T i = 0; i < n; ++i) {
1167template <
int idim,
typename L,
int dim>
1169void ParallelForRNG_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
1171 if constexpr (idim == 1) {
1172 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1173 call_f_intvect_engine(f,iv,RandomEngine{});
1175 }
else if constexpr (idim == 2) {
1176 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1177 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1178 call_f_intvect_engine(f,iv,RandomEngine{});
1180 }
else if constexpr (idim == 3) {
1181 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
1182 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1183 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1184 call_f_intvect_engine(f,iv,RandomEngine{});
1187 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
1188 ParallelForRNG_impND<idim-1>(f, lo, hi, iv);
1193template <
int idim,
typename L,
typename T,
int dim>
1195void ParallelForRNG_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
1197 if constexpr (idim == 1) {
1198 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1199 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1201 }
else if constexpr (idim == 2) {
1202 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1203 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1204 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1206 }
else if constexpr (idim == 3) {
1207 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
1208 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1209 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1210 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1213 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
1214 ParallelForRNG_impND<idim-1>(f, lo, hi, iv, n);
1222template <
typename L,
int dim>
1229 detail::ParallelForRNG_impND<dim>(f, lo, hi, iv);
1232template <std::
integral T,
typename L,
int dim >
1239 for (T n = 0; n < ncomp; ++n) {
1240 detail::ParallelForRNG_impND<dim>(f, lo, hi, iv, n);
1244template <
typename L>
1247 std::forward<L>(f)();
#define AMREX_PRAGMA_SIMD
Definition AMReX_Extension.H:85
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:124
#define AMREX_ATTRIBUTE_FLATTEN_FOR
Definition AMReX_Extension.H:156
A Rectangular Domain on an Integer Lattice.
Definition AMReX_Box.H:54
Definition AMReX_GpuKernelInfo.H:8
An Integer Vector in dim-Dimensional Space.
Definition AMReX_IntVect.H:149
__host__ __device__ range_detail::range_impl< T > Range(T const &b) noexcept
Definition AMReX_GpuRange.H:128
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:259
void HostDeviceParallelFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:732
void For(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:400
__host__ __device__ IntVectND< dim > lbound_iv(BoxND< dim > const &box) noexcept
Return the inclusive lower corner of box as an IntVectND.
Definition AMReX_Box.H:2065
void launch(T const &n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:122
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
void HostDeviceFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:835
__host__ __device__ IntVectND< dim > ubound_iv(BoxND< dim > const &box) noexcept
Return the inclusive upper corner of box as an IntVectND.
Definition AMReX_Box.H:2080
void single_task(L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1245
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForRNG(T n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1157
Definition AMReX_RandomEngine.H:72