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 <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
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,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
144void For (T n, L&& f)
noexcept
147 For(n, std::forward<L>(f));
150template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
153 For(n, std::forward<L>(f));
156template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
160 For(n, std::forward<L>(f));
163template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
168 for (T i = 0; i < n; ++i) {
169 detail::call_f_scalar_handler(f,i);
173template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
180template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
186template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
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 <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
359 for (T n = 0; n < ncomp; ++n) {
360 detail::For_impND<dim>(f, lo, hi, iv, n);
364template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
368 For(box, ncomp, std::forward<L>(f));
371template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
374 For(box, ncomp, std::forward<L>(f));
377template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
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 <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
426 for (T n = 0; n < ncomp; ++n) {
427 detail::ParallelFor_impND<dim>(f, lo, hi, iv, n);
431template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
438template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
444template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
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 <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
510 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
511 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
513 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
515 For(box1, ncomp1, std::forward<L1>(f1));
516 For(box2, ncomp2, std::forward<L2>(f2));
519template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
520 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
521 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
523 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
526 For(box1, ncomp1, std::forward<L1>(f1));
527 For(box2, ncomp2, std::forward<L2>(f2));
530template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
531 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
532 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
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,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
541 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
542 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
545 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
548 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
551template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
552 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
553 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
554 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
557 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 <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
565 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
566 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
567 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
570 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
573 For(box1, ncomp1, std::forward<L1>(f1));
574 For(box2, ncomp2, std::forward<L2>(f2));
575 For(box3, ncomp3, std::forward<L3>(f3));
578template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
579 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
580 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
581 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
585 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
587 For(box1,ncomp1,std::forward<L1>(f1),
588 box2,ncomp2,std::forward<L2>(f2),
589 box3,ncomp3,std::forward<L3>(f3));
592template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
593 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
594 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
595 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
599 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
602 For(box1,ncomp1,std::forward<L1>(f1),
603 box2,ncomp2,std::forward<L2>(f2),
604 box3,ncomp3,std::forward<L3>(f3));
607template <
typename L1,
typename L2,
int dim>
614template <
int MT,
typename L1,
typename L2,
int dim>
622template <
typename L1,
typename L2,
int dim>
625 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
628template <
int MT,
typename L1,
typename L2,
int dim>
632 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
635template <
typename L1,
typename L2,
typename L3,
int dim>
643template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
652template <
typename L1,
typename L2,
typename L3,
int dim>
655 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
658template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
662 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
665template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
666 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
667 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
669 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
675template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
676 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
677 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
679 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
686template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
687 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
688 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
691 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
694 box2,ncomp2,std::forward<L2>(f2));
697template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
698 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
699 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
702 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
706 box2,ncomp2,std::forward<L2>(f2));
709template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
710 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
711 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
712 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
715 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
722template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
723 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
724 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
725 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
728 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
736template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
737 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
738 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
739 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
743 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
746 box2, ncomp2, std::forward<L2>(f2),
747 box3, ncomp3, std::forward<L3>(f3));
750template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
751 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
752 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
753 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
757 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
761 box2, ncomp2, std::forward<L2>(f2),
762 box3, ncomp3, std::forward<L3>(f3));
765template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
771template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
778template <
typename L,
int dim>
784template <
int MT,
typename L,
int dim>
791template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
797template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
804template <
typename L1,
typename L2,
int dim>
807 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
810template <
int MT,
typename L1,
typename L2,
int dim>
814 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
817template <
typename L1,
typename L2,
typename L3,
int dim>
819 L1&& f1, L2&& f2, L3&& f3)
noexcept
821 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
824template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
826 L1&& f1, L2&& f2, L3&& f3)
noexcept
829 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
832template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
833 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
834 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
836 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
838 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
841template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
842 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
843 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
845 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
848 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
851template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
852 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
853 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
854 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
857 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
860 box2,ncomp2,std::forward<L2>(f2),
861 box3,ncomp3,std::forward<L3>(f3));
864template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
865 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
866 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
867 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
870 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
874 box2,ncomp2,std::forward<L2>(f2),
875 box3,ncomp3,std::forward<L3>(f3));
878template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
881 For(n,std::forward<L>(f));
884template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
888 For(n,std::forward<L>(f));
891template <
typename L,
int dim>
894 For(box,std::forward<L>(f));
897template <
int MT,
typename L,
int dim>
901 For(box,std::forward<L>(f));
904template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
907 For(box,ncomp,std::forward<L>(f));
910template <
int MT,
typename T,
int dim,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
914 For(box,ncomp,std::forward<L>(f));
917template <
typename L1,
typename L2,
int dim>
920 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
923template <
int MT,
typename L1,
typename L2,
int dim>
927 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
930template <
typename L1,
typename L2,
typename L3,
int dim>
932 L1&& f1, L2&& f2, L3&& f3)
noexcept
934 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
937template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
939 L1&& f1, L2&& f2, L3&& f3)
noexcept
942 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
945template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
946 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
947 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
949 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
951 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
954template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
955 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
956 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
958 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
961 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
964template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
965 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
966 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
967 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
970 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
972 For(box1,ncomp1,std::forward<L1>(f1),
973 box2,ncomp2,std::forward<L2>(f2),
974 box3,ncomp3,std::forward<L3>(f3));
977template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
978 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
979 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
980 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
983 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
986 For(box1,ncomp1,std::forward<L1>(f1),
987 box2,ncomp2,std::forward<L2>(f2),
988 box3,ncomp3,std::forward<L3>(f3));
991template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
997template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1004template <
typename L,
int dim>
1010template <
int MT,
typename L,
int dim>
1017template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1023template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1030template <
typename L1,
typename L2,
int dim>
1033 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1036template <
int MT,
typename L1,
typename L2,
int dim>
1040 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1043template <
typename L1,
typename L2,
typename L3,
int dim>
1046 L1&& f1, L2&& f2, L3&& f3)
noexcept
1048 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1051template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
1054 L1&& f1, L2&& f2, L3&& f3)
noexcept
1057 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1060template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
1061 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1062 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
1065 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1067 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1070template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
1071 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1072 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
1075 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1078 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1081template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1082 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1083 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1084 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1088 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1091 box2,ncomp2,std::forward<L2>(f2),
1092 box3,ncomp3,std::forward<L3>(f3));
1095template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1096 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1097 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1098 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1102 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1106 box2,ncomp2,std::forward<L2>(f2),
1107 box3,ncomp3,std::forward<L3>(f3));
1110template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1113 For(n,std::forward<L>(f));
1116template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1120 For(n,std::forward<L>(f));
1123template <
typename L,
int dim>
1126 For(box,std::forward<L>(f));
1129template <
int MT,
typename L,
int dim>
1133 For(box,std::forward<L>(f));
1136template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1139 For(box,ncomp,std::forward<L>(f));
1142template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1146 For(box,ncomp,std::forward<L>(f));
1149template <
typename L1,
typename L2,
int dim>
1152 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1155template <
int MT,
typename L1,
typename L2,
int dim>
1159 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1162template <
typename L1,
typename L2,
typename L3,
int dim>
1165 L1&& f1, L2&& f2, L3&& f3)
noexcept
1167 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1170template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
1173 L1&& f1, L2&& f2, L3&& f3)
noexcept
1176 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1179template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
1180 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1181 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
1184 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1186 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1189template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
1190 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1191 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
1194 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1197 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1200template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1201 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1202 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1203 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1207 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1209 For(box1,ncomp1,std::forward<L1>(f1),
1210 box2,ncomp2,std::forward<L2>(f2),
1211 box3,ncomp3,std::forward<L3>(f3));
1214template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1215 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1216 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1217 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1221 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1224 For(box1,ncomp1,std::forward<L1>(f1),
1225 box2,ncomp2,std::forward<L2>(f2),
1226 box3,ncomp3,std::forward<L3>(f3));
1229template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1233 for (T i = 0; i < n; ++i) {
1241template <
int idim,
typename L,
int dim>
1243void ParallelForRNG_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
1245 if constexpr (idim == 1) {
1246 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1247 call_f_intvect_engine(f,iv,RandomEngine{});
1249 }
else if constexpr (idim == 2) {
1250 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1251 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1252 call_f_intvect_engine(f,iv,RandomEngine{});
1254 }
else if constexpr (idim == 3) {
1255 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
1256 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1257 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1258 call_f_intvect_engine(f,iv,RandomEngine{});
1261 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
1262 ParallelForRNG_impND<idim-1>(f, lo, hi, iv);
1267template <
int idim,
typename L,
typename T,
int dim>
1269void ParallelForRNG_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
1271 if constexpr (idim == 1) {
1272 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1273 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1275 }
else if constexpr (idim == 2) {
1276 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1277 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1278 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1280 }
else if constexpr (idim == 3) {
1281 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
1282 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1283 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1284 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1287 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
1288 ParallelForRNG_impND<idim-1>(f, lo, hi, iv, n);
1296template <
typename L,
int dim>
1303 detail::ParallelForRNG_impND<dim>(f, lo, hi, iv);
1306template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1313 for (T n = 0; n < ncomp; ++n) {
1314 detail::ParallelForRNG_impND<dim>(f, lo, hi, iv, n);
1318template <
typename L>
1321 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:57
Definition AMReX_Amr.cpp:49
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:139
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
__host__ __device__ IntVectND< dim > lbound_iv(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1905
void launch(T const &n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:122
void HostDeviceFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:879
void HostDeviceParallelFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:766
__host__ __device__ IntVectND< dim > ubound_iv(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1914
void single_task(L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1319
AMREX_ATTRIBUTE_FLATTEN_FOR void For(T n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:136
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForRNG(T n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1231
Definition AMReX_RandomEngine.H:72