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>
124 std::forward<L>(f)(n);
127template<
int MT,
typename T,
typename L>
131 std::forward<L>(f)(n);
134template <std::
integral T,
typename L >
136void For (T n, L
const& f)
noexcept
138 for (T i = 0; i < n; ++i) {
139 detail::call_f_scalar_handler(f,i);
143template <
int MT, std::
integral T,
typename L >
144void For (T n, L&& f)
noexcept
147 For(n, std::forward<L>(f));
150template <std::
integral T,
typename L >
153 For(n, std::forward<L>(f));
156template <
int MT, std::
integral T,
typename L >
160 For(n, std::forward<L>(f));
163template <std::
integral T,
typename L >
168 for (T i = 0; i < n; ++i) {
169 detail::call_f_scalar_handler(f,i);
173template <
int MT, std::
integral T,
typename L >
180template <std::
integral T,
typename L >
186template <
int MT, std::
integral T,
typename L >
196template <
int idim,
typename L,
int dim>
198void For_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
200 if constexpr (idim == 1) {
201 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
202 call_f_intvect_handler(f,iv);
204 }
else if constexpr (idim == 2) {
205 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
206 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
207 call_f_intvect_handler(f,iv);
209 }
else if constexpr (idim == 3) {
210 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
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);
216 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
217 For_impND<idim-1>(f, lo, hi, iv);
225template <
typename L,
int dim>
232 detail::For_impND<dim>(f, lo, hi, iv);
235template <
int MT,
typename L,
int dim>
239 For(box, std::forward<L>(f));
242template <
typename L,
int dim>
245 For(box, std::forward<L>(f));
248template <
int MT,
typename L,
int dim>
252 For(box, std::forward<L>(f));
258template <
int idim,
typename L,
int dim>
260void ParallelFor_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
262 if constexpr (idim == 1) {
264 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
265 call_f_intvect_handler(f,iv);
267 }
else if constexpr (idim == 2) {
268 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
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 == 3) {
274 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
275 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
277 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
278 call_f_intvect_handler(f,iv);
281 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
282 ParallelFor_impND<idim-1>(f, lo, hi, iv);
290template <
typename L,
int dim>
297 detail::ParallelFor_impND<dim>(f, lo, hi, iv);
300template <
int MT,
typename L,
int dim>
307template <
typename L,
int dim>
313template <
int MT,
typename L,
int dim>
323template <
int idim,
typename L,
typename T,
int dim>
325void For_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
327 if constexpr (idim == 1) {
328 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
329 call_f_intvect_ncomp_handler(f,iv,n);
331 }
else if constexpr (idim == 2) {
332 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
333 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
334 call_f_intvect_ncomp_handler(f,iv,n);
336 }
else if constexpr (idim == 3) {
337 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
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);
343 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
344 For_impND<idim-1>(f, lo, hi, iv, n);
352template <std::
integral T,
typename L,
int dim >
359 for (T n = 0; n < ncomp; ++n) {
360 detail::For_impND<dim>(f, lo, hi, iv, n);
364template <
int MT, std::
integral T,
typename L,
int dim >
368 For(box, ncomp, std::forward<L>(f));
371template <std::
integral T,
typename L,
int dim >
374 For(box, ncomp, std::forward<L>(f));
377template <
int MT, std::
integral T,
typename L,
int dim >
381 For(box, ncomp, std::forward<L>(f));
387template <
int idim,
typename L,
typename T,
int dim>
389void ParallelFor_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
391 if constexpr (idim == 1) {
393 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
394 call_f_intvect_ncomp_handler(f,iv,n);
396 }
else if constexpr (idim == 2) {
397 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
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 == 3) {
403 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
404 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
406 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
407 call_f_intvect_ncomp_handler(f,iv,n);
410 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
411 ParallelFor_impND<idim-1>(f, lo, hi, iv, n);
419template <std::
integral T,
typename L,
int dim >
426 for (T n = 0; n < ncomp; ++n) {
427 detail::ParallelFor_impND<dim>(f, lo, hi, iv, n);
431template <
int MT, std::
integral T,
typename L,
int dim >
438template <std::
integral T,
typename L,
int dim >
444template <
int MT, std::
integral T,
typename L,
int dim >
451template <
typename L1,
typename L2,
int dim>
454 For(box1, std::forward<L1>(f1));
455 For(box2, std::forward<L2>(f2));
458template <
int MT,
typename L1,
typename L2,
int dim>
462 For(box1, std::forward<L1>(f1));
463 For(box2, std::forward<L2>(f2));
466template <
typename L1,
typename L2,
int dim>
469 For (box1, box2, std::forward<L1>(f1), std::forward<L2>(f2));
472template <
int MT,
typename L1,
typename L2,
int dim>
476 For (box1, box2, std::forward<L1>(f1), std::forward<L2>(f2));
479template <
typename L1,
typename L2,
typename L3,
int dim>
482 For(box1, std::forward<L1>(f1));
483 For(box2, std::forward<L2>(f2));
484 For(box3, std::forward<L3>(f3));
487template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
491 For(box1, std::forward<L1>(f1));
492 For(box2, std::forward<L2>(f2));
493 For(box3, std::forward<L3>(f3));
496template <
typename L1,
typename L2,
typename L3,
int dim>
499 For(box1, box2, box3, std::forward<L1>(f1), std::forward<L2>(f2), std::forward<L3>(f3));
502template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
506 For(box1, box2, box3, std::forward<L1>(f1), std::forward<L2>(f2), std::forward<L3>(f3));
509template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
511 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
513 For(box1, ncomp1, std::forward<L1>(f1));
514 For(box2, ncomp2, std::forward<L2>(f2));
517template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
519 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
522 For(box1, ncomp1, std::forward<L1>(f1));
523 For(box2, ncomp2, std::forward<L2>(f2));
526template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
529 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
531 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
534template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
537 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
540 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
543template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
546 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
548 For(box1, ncomp1, std::forward<L1>(f1));
549 For(box2, ncomp2, std::forward<L2>(f2));
550 For(box3, ncomp3, std::forward<L3>(f3));
553template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
556 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
559 For(box1, ncomp1, std::forward<L1>(f1));
560 For(box2, ncomp2, std::forward<L2>(f2));
561 For(box3, ncomp3, std::forward<L3>(f3));
564template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
568 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
570 For(box1,ncomp1,std::forward<L1>(f1),
571 box2,ncomp2,std::forward<L2>(f2),
572 box3,ncomp3,std::forward<L3>(f3));
575template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
579 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
582 For(box1,ncomp1,std::forward<L1>(f1),
583 box2,ncomp2,std::forward<L2>(f2),
584 box3,ncomp3,std::forward<L3>(f3));
587template <
typename L1,
typename L2,
int dim>
594template <
int MT,
typename L1,
typename L2,
int dim>
602template <
typename L1,
typename L2,
int dim>
605 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
608template <
int MT,
typename L1,
typename L2,
int dim>
612 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
615template <
typename L1,
typename L2,
typename L3,
int dim>
623template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
632template <
typename L1,
typename L2,
typename L3,
int dim>
635 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
638template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
642 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
645template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
647 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
653template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
655 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
662template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
665 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
668 box2,ncomp2,std::forward<L2>(f2));
671template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
674 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
678 box2,ncomp2,std::forward<L2>(f2));
681template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
684 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
691template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
694 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
702template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
706 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
709 box2, ncomp2, std::forward<L2>(f2),
710 box3, ncomp3, std::forward<L3>(f3));
713template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
717 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
721 box2, ncomp2, std::forward<L2>(f2),
722 box3, ncomp3, std::forward<L3>(f3));
725template <std::
integral T,
typename L >
731template <
int MT, std::
integral T,
typename L >
738template <
typename L,
int dim>
744template <
int MT,
typename L,
int dim>
751template <std::
integral T,
typename L,
int dim >
757template <
int MT, std::
integral T,
typename L,
int dim >
764template <
typename L1,
typename L2,
int dim>
767 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
770template <
int MT,
typename L1,
typename L2,
int dim>
774 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
777template <
typename L1,
typename L2,
typename L3,
int dim>
779 L1&& f1, L2&& f2, L3&& f3)
noexcept
781 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
784template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
786 L1&& f1, L2&& f2, L3&& f3)
noexcept
789 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
792template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
794 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
796 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
799template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
801 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
804 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
807template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
810 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
813 box2,ncomp2,std::forward<L2>(f2),
814 box3,ncomp3,std::forward<L3>(f3));
817template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
820 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
824 box2,ncomp2,std::forward<L2>(f2),
825 box3,ncomp3,std::forward<L3>(f3));
828template <std::
integral T,
typename L >
831 For(n,std::forward<L>(f));
834template <
int MT, std::
integral T,
typename L >
838 For(n,std::forward<L>(f));
841template <
typename L,
int dim>
844 For(box,std::forward<L>(f));
847template <
int MT,
typename L,
int dim>
851 For(box,std::forward<L>(f));
854template <std::
integral T,
typename L,
int dim >
857 For(box,ncomp,std::forward<L>(f));
860template <
int MT, std::
integral T,
int dim,
typename L >
864 For(box,ncomp,std::forward<L>(f));
867template <
typename L1,
typename L2,
int dim>
870 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
873template <
int MT,
typename L1,
typename L2,
int dim>
877 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
880template <
typename L1,
typename L2,
typename L3,
int dim>
882 L1&& f1, L2&& f2, L3&& f3)
noexcept
884 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
887template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
889 L1&& f1, L2&& f2, L3&& f3)
noexcept
892 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
895template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
897 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
899 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
902template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
904 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
907 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
910template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
913 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
915 For(box1,ncomp1,std::forward<L1>(f1),
916 box2,ncomp2,std::forward<L2>(f2),
917 box3,ncomp3,std::forward<L3>(f3));
920template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
923 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
926 For(box1,ncomp1,std::forward<L1>(f1),
927 box2,ncomp2,std::forward<L2>(f2),
928 box3,ncomp3,std::forward<L3>(f3));
931template <std::
integral T,
typename L >
937template <
int MT, std::
integral T,
typename L >
944template <
typename L,
int dim>
950template <
int MT,
typename L,
int dim>
957template <std::
integral T,
typename L,
int dim >
963template <
int MT, std::
integral T,
typename L,
int dim >
970template <
typename L1,
typename L2,
int dim>
973 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
976template <
int MT,
typename L1,
typename L2,
int dim>
980 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
983template <
typename L1,
typename L2,
typename L3,
int dim>
986 L1&& f1, L2&& f2, L3&& f3)
noexcept
988 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
991template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
994 L1&& f1, L2&& f2, L3&& f3)
noexcept
997 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1000template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
1003 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1005 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1008template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
1011 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1014 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1017template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
1021 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1024 box2,ncomp2,std::forward<L2>(f2),
1025 box3,ncomp3,std::forward<L3>(f3));
1028template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
1032 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1036 box2,ncomp2,std::forward<L2>(f2),
1037 box3,ncomp3,std::forward<L3>(f3));
1040template <std::
integral T,
typename L >
1043 For(n,std::forward<L>(f));
1046template <
int MT, std::
integral T,
typename L >
1050 For(n,std::forward<L>(f));
1053template <
typename L,
int dim>
1056 For(box,std::forward<L>(f));
1059template <
int MT,
typename L,
int dim>
1063 For(box,std::forward<L>(f));
1066template <std::
integral T,
typename L,
int dim >
1069 For(box,ncomp,std::forward<L>(f));
1072template <
int MT, std::
integral T,
typename L,
int dim >
1076 For(box,ncomp,std::forward<L>(f));
1079template <
typename L1,
typename L2,
int dim>
1082 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1085template <
int MT,
typename L1,
typename L2,
int dim>
1089 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1092template <
typename L1,
typename L2,
typename L3,
int dim>
1095 L1&& f1, L2&& f2, L3&& f3)
noexcept
1097 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1100template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
1103 L1&& f1, L2&& f2, L3&& f3)
noexcept
1106 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1109template <std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
1112 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1114 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1117template <
int MT, std::
integral T1, std::
integral T2,
typename L1,
typename L2,
int dim>
1120 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1123 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1126template <std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
1130 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1132 For(box1,ncomp1,std::forward<L1>(f1),
1133 box2,ncomp2,std::forward<L2>(f2),
1134 box3,ncomp3,std::forward<L3>(f3));
1137template <
int MT, std::
integral T1, std::
integral T2, std::
integral T3,
typename L1,
typename L2,
typename L3,
int dim>
1141 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1144 For(box1,ncomp1,std::forward<L1>(f1),
1145 box2,ncomp2,std::forward<L2>(f2),
1146 box3,ncomp3,std::forward<L3>(f3));
1149template <std::
integral T,
typename L >
1153 for (T i = 0; i < n; ++i) {
1161template <
int idim,
typename L,
int dim>
1163void ParallelForRNG_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
1165 if constexpr (idim == 1) {
1166 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1167 call_f_intvect_engine(f,iv,RandomEngine{});
1169 }
else if constexpr (idim == 2) {
1170 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1171 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1172 call_f_intvect_engine(f,iv,RandomEngine{});
1174 }
else if constexpr (idim == 3) {
1175 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
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{});
1181 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
1182 ParallelForRNG_impND<idim-1>(f, lo, hi, iv);
1187template <
int idim,
typename L,
typename T,
int dim>
1189void ParallelForRNG_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
1191 if constexpr (idim == 1) {
1192 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1193 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1195 }
else if constexpr (idim == 2) {
1196 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1197 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1198 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1200 }
else if constexpr (idim == 3) {
1201 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
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{});
1207 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
1208 ParallelForRNG_impND<idim-1>(f, lo, hi, iv, n);
1216template <
typename L,
int dim>
1223 detail::ParallelForRNG_impND<dim>(f, lo, hi, iv);
1226template <std::
integral T,
typename L,
int dim >
1233 for (T n = 0; n < ncomp; ++n) {
1234 detail::ParallelForRNG_impND<dim>(f, lo, hi, iv, n);
1238template <
typename L>
1241 std::forward<L>(f)();
#define AMREX_PRAGMA_SIMD
Definition AMReX_Extension.H:80
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_ATTRIBUTE_FLATTEN_FOR
Definition AMReX_Extension.H:151
A Rectangular Domain on an Integer Lattice.
Definition AMReX_Box.H:49
Definition AMReX_GpuKernelInfo.H:8
An Integer Vector in dim-Dimensional Space.
Definition AMReX_IntVect.H:149
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:139
void HostDeviceParallelFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:726
__host__ __device__ IntVectND< dim > lbound_iv(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1914
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:829
void launch(T const &n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:122
__host__ __device__ IntVectND< dim > ubound_iv(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1923
void single_task(L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1239
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForRNG(T n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1151
AMREX_ATTRIBUTE_FLATTEN_FOR void For(T n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:136
Definition AMReX_RandomEngine.H:72