1#ifndef AMREX_GPU_LAUNCH_FUNCTS_C_H_
2#define AMREX_GPU_LAUNCH_FUNCTS_C_H_
3#include <AMReX_Config.H>
15template<
int WIDTH,
class N=
int>
19 static constexpr int width = WIDTH;
30 template <
typename F,
typename N>
32 auto call_f_scalar_handler (
F const& f, N i)
33 noexcept ->
decltype(f(0))
38 template <
typename F,
typename N>
40 auto call_f_scalar_handler (F
const& f, N i)
41 noexcept ->
decltype(f(0,Gpu::Handler{}))
48 template <
typename F, std::size_t...Ns,
class...Args>
50 auto call_f_intvect_inner (std::index_sequence<Ns...>, F
const& f, IntVectND<1> iv, Args...args)
51 noexcept -> decltype(f(0, 0, 0, args...))
53 f(iv[0], 0, 0, args...);
56 template <
typename F, std::size_t...Ns,
class...Args>
58 auto call_f_intvect_inner (std::index_sequence<Ns...>, F
const& f, IntVectND<2> iv, Args...args)
59 noexcept -> decltype(f(0, 0, 0, args...))
61 f(iv[0], iv[1], 0, args...);
64 template <
typename F,
int dim, std::size_t...Ns,
class...Args>
66 auto call_f_intvect_inner (std::index_sequence<Ns...>, F
const& f, IntVectND<dim> iv, Args...args)
67 noexcept -> decltype(f(iv, args...))
72 template <
typename F,
int dim, std::size_t...Ns,
class...Args>
74 auto call_f_intvect_inner (std::index_sequence<Ns...>, F
const& f, IntVectND<dim> iv, Args...args)
75 noexcept -> decltype(f(iv[Ns]..., args...))
77 f(iv[Ns]..., args...);
82 template <
typename F,
int dim>
84 auto call_f_intvect_engine (F
const& f, IntVectND<dim> iv, RandomEngine engine)
85 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, engine))
87 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, engine);
92 template <
typename F,
int dim>
94 auto call_f_intvect_handler (F
const& f, IntVectND<dim> iv)
95 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv))
97 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv);
100 template <
typename F,
int dim>
102 auto call_f_intvect_handler (F
const& f, IntVectND<dim> iv)
103 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, Gpu::Handler{}))
105 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, Gpu::Handler{});
110 template <
typename F,
typename T,
int dim>
112 auto call_f_intvect_ncomp_engine (F
const& f, IntVectND<dim> iv, T n, RandomEngine engine)
113 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, engine))
115 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, engine);
120 template <
typename F,
typename T,
int dim>
122 auto call_f_intvect_ncomp_handler (F
const& f, IntVectND<dim> iv, T n)
123 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n))
125 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n);
128 template <
typename F,
typename T,
int dim>
130 auto call_f_intvect_ncomp_handler (F
const& f, IntVectND<dim> iv, T n)
131 noexcept ->
decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, Gpu::Handler{}))
133 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, Gpu::Handler{});
139template<
typename T,
typename L>
142 std::forward<L>(f)(n);
145template<
int MT,
typename T,
typename L>
149 std::forward<L>(f)(n);
152template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
154void For (T n, L
const& f)
noexcept
156 for (T i = 0; i < n; ++i) {
157 detail::call_f_scalar_handler(f,i);
161template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
162void For (T n, L&& f)
noexcept
165 For(n, std::forward<L>(f));
168template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
171 For(n, std::forward<L>(f));
174template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
178 For(n, std::forward<L>(f));
181template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
186 for (T i = 0; i < n; ++i) {
187 detail::call_f_scalar_handler(f,i);
191template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
206template <
int WIDTH,
typename N,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<N>> >
212 for (; i + WIDTH <= n; i+=WIDTH) {
223template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
229template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
239template <
int idim,
typename L,
int dim>
241void For_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
243 if constexpr (idim == 1) {
244 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
245 call_f_intvect_handler(f,iv);
247 }
else if constexpr (idim == 2) {
248 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
249 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
250 call_f_intvect_handler(f,iv);
252 }
else if constexpr (idim == 3) {
253 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
254 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
255 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
256 call_f_intvect_handler(f,iv);
259 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
260 For_impND<idim-1>(f, lo, hi, iv);
268template <
typename L,
int dim>
275 detail::For_impND<dim>(f, lo, hi, iv);
278template <
int MT,
typename L,
int dim>
282 For(box, std::forward<L>(f));
285template <
typename L,
int dim>
288 For(box, std::forward<L>(f));
291template <
int MT,
typename L,
int dim>
295 For(box, std::forward<L>(f));
301template <
int idim,
typename L,
int dim>
303void ParallelFor_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
305 if constexpr (idim == 1) {
307 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
308 call_f_intvect_handler(f,iv);
310 }
else if constexpr (idim == 2) {
311 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
313 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
314 call_f_intvect_handler(f,iv);
316 }
else if constexpr (idim == 3) {
317 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
318 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
320 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
321 call_f_intvect_handler(f,iv);
324 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
325 ParallelFor_impND<idim-1>(f, lo, hi, iv);
333template <
typename L,
int dim>
340 detail::ParallelFor_impND<dim>(f, lo, hi, iv);
343template <
int MT,
typename L,
int dim>
350template <
typename L,
int dim>
356template <
int MT,
typename L,
int dim>
366template <
int idim,
typename L,
typename T,
int dim>
368void For_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
370 if constexpr (idim == 1) {
371 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
372 call_f_intvect_ncomp_handler(f,iv,n);
374 }
else if constexpr (idim == 2) {
375 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
376 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
377 call_f_intvect_ncomp_handler(f,iv,n);
379 }
else if constexpr (idim == 3) {
380 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
381 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
382 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
383 call_f_intvect_ncomp_handler(f,iv,n);
386 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
387 For_impND<idim-1>(f, lo, hi, iv, n);
395template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
402 for (T n = 0; n < ncomp; ++n) {
403 detail::For_impND<dim>(f, lo, hi, iv, n);
407template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
411 For(box, ncomp, std::forward<L>(f));
414template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
417 For(box, ncomp, std::forward<L>(f));
420template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
424 For(box, ncomp, std::forward<L>(f));
430template <
int idim,
typename L,
typename T,
int dim>
432void ParallelFor_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
434 if constexpr (idim == 1) {
436 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
437 call_f_intvect_ncomp_handler(f,iv,n);
439 }
else if constexpr (idim == 2) {
440 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
442 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
443 call_f_intvect_ncomp_handler(f,iv,n);
445 }
else if constexpr (idim == 3) {
446 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
447 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
449 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
450 call_f_intvect_ncomp_handler(f,iv,n);
453 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
454 ParallelFor_impND<idim-1>(f, lo, hi, iv, n);
462template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
469 for (T n = 0; n < ncomp; ++n) {
470 detail::ParallelFor_impND<dim>(f, lo, hi, iv, n);
474template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
481template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
487template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
494template <
typename L1,
typename L2,
int dim>
497 For(box1, std::forward<L1>(f1));
498 For(box2, std::forward<L2>(f2));
501template <
int MT,
typename L1,
typename L2,
int dim>
505 For(box1, std::forward<L1>(f1));
506 For(box2, std::forward<L2>(f2));
509template <
typename L1,
typename L2,
int dim>
512 For (box1, box2, std::forward<L1>(f1), std::forward<L2>(f2));
515template <
int MT,
typename L1,
typename L2,
int dim>
519 For (box1, box2, std::forward<L1>(f1), std::forward<L2>(f2));
522template <
typename L1,
typename L2,
typename L3,
int dim>
525 For(box1, std::forward<L1>(f1));
526 For(box2, std::forward<L2>(f2));
527 For(box3, std::forward<L3>(f3));
530template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
534 For(box1, std::forward<L1>(f1));
535 For(box2, std::forward<L2>(f2));
536 For(box3, std::forward<L3>(f3));
539template <
typename L1,
typename L2,
typename L3,
int dim>
542 For(box1, box2, box3, std::forward<L1>(f1), std::forward<L2>(f2), std::forward<L3>(f3));
545template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
549 For(box1, box2, box3, std::forward<L1>(f1), std::forward<L2>(f2), std::forward<L3>(f3));
552template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
553 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
554 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
556 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
558 For(box1, ncomp1, std::forward<L1>(f1));
559 For(box2, ncomp2, std::forward<L2>(f2));
562template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
563 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
564 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
566 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
569 For(box1, ncomp1, std::forward<L1>(f1));
570 For(box2, ncomp2, std::forward<L2>(f2));
573template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
574 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
575 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
578 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
580 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
583template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
584 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
585 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
588 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
591 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
594template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
595 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
596 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
597 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
600 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
602 For(box1, ncomp1, std::forward<L1>(f1));
603 For(box2, ncomp2, std::forward<L2>(f2));
604 For(box3, ncomp3, std::forward<L3>(f3));
607template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
608 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
609 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
610 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
613 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
616 For(box1, ncomp1, std::forward<L1>(f1));
617 For(box2, ncomp2, std::forward<L2>(f2));
618 For(box3, ncomp3, std::forward<L3>(f3));
621template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
622 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
623 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
624 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
628 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
630 For(box1,ncomp1,std::forward<L1>(f1),
631 box2,ncomp2,std::forward<L2>(f2),
632 box3,ncomp3,std::forward<L3>(f3));
635template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
636 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
637 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
638 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
642 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
645 For(box1,ncomp1,std::forward<L1>(f1),
646 box2,ncomp2,std::forward<L2>(f2),
647 box3,ncomp3,std::forward<L3>(f3));
650template <
typename L1,
typename L2,
int dim>
657template <
int MT,
typename L1,
typename L2,
int dim>
665template <
typename L1,
typename L2,
int dim>
668 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
671template <
int MT,
typename L1,
typename L2,
int dim>
675 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
678template <
typename L1,
typename L2,
typename L3,
int dim>
686template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
695template <
typename L1,
typename L2,
typename L3,
int dim>
698 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
701template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
705 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
708template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
709 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
710 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
712 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
718template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
719 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
720 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
722 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
729template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
730 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
731 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
734 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
737 box2,ncomp2,std::forward<L2>(f2));
740template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
741 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
742 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
745 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
749 box2,ncomp2,std::forward<L2>(f2));
752template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
753 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
754 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
755 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
758 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
765template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
766 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
767 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
768 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
771 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
779template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
780 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
781 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
782 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
786 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
789 box2, ncomp2, std::forward<L2>(f2),
790 box3, ncomp3, std::forward<L3>(f3));
793template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
794 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
795 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
796 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
800 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
804 box2, ncomp2, std::forward<L2>(f2),
805 box3, ncomp3, std::forward<L3>(f3));
808template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
814template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
821template <
typename L,
int dim>
827template <
int MT,
typename L,
int dim>
834template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
840template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
847template <
typename L1,
typename L2,
int dim>
850 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
853template <
int MT,
typename L1,
typename L2,
int dim>
857 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
860template <
typename L1,
typename L2,
typename L3,
int dim>
862 L1&& f1, L2&& f2, L3&& f3)
noexcept
864 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
867template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
869 L1&& f1, L2&& f2, L3&& f3)
noexcept
872 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
875template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
876 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
877 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
879 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
881 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
884template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
885 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
886 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
888 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
891 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
894template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
895 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
896 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
897 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
900 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
903 box2,ncomp2,std::forward<L2>(f2),
904 box3,ncomp3,std::forward<L3>(f3));
907template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
908 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
909 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
910 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
913 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
917 box2,ncomp2,std::forward<L2>(f2),
918 box3,ncomp3,std::forward<L3>(f3));
921template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
924 For(n,std::forward<L>(f));
927template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
931 For(n,std::forward<L>(f));
934template <
typename L,
int dim>
937 For(box,std::forward<L>(f));
940template <
int MT,
typename L,
int dim>
944 For(box,std::forward<L>(f));
947template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
950 For(box,ncomp,std::forward<L>(f));
953template <
int MT,
typename T,
int dim,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
957 For(box,ncomp,std::forward<L>(f));
960template <
typename L1,
typename L2,
int dim>
963 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
966template <
int MT,
typename L1,
typename L2,
int dim>
970 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
973template <
typename L1,
typename L2,
typename L3,
int dim>
975 L1&& f1, L2&& f2, L3&& f3)
noexcept
977 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
980template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
982 L1&& f1, L2&& f2, L3&& f3)
noexcept
985 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
988template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
989 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
990 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
992 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
994 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
997template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
998 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
999 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
1001 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1004 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1007template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1008 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1009 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1010 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1013 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1015 For(box1,ncomp1,std::forward<L1>(f1),
1016 box2,ncomp2,std::forward<L2>(f2),
1017 box3,ncomp3,std::forward<L3>(f3));
1020template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1021 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1022 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1023 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1026 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1029 For(box1,ncomp1,std::forward<L1>(f1),
1030 box2,ncomp2,std::forward<L2>(f2),
1031 box3,ncomp3,std::forward<L3>(f3));
1034template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1040template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1047template <
typename L,
int dim>
1053template <
int MT,
typename L,
int dim>
1060template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1066template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1073template <
typename L1,
typename L2,
int dim>
1076 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1079template <
int MT,
typename L1,
typename L2,
int dim>
1083 ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1086template <
typename L1,
typename L2,
typename L3,
int dim>
1089 L1&& f1, L2&& f2, L3&& f3)
noexcept
1091 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1094template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
1097 L1&& f1, L2&& f2, L3&& f3)
noexcept
1100 ParallelFor(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1103template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
1104 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1105 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
1108 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1110 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1113template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
1114 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1115 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
1118 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1121 ParallelFor(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1124template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1125 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1126 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1127 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1131 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1134 box2,ncomp2,std::forward<L2>(f2),
1135 box3,ncomp3,std::forward<L3>(f3));
1138template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1139 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1140 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1141 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1145 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1149 box2,ncomp2,std::forward<L2>(f2),
1150 box3,ncomp3,std::forward<L3>(f3));
1153template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1156 For(n,std::forward<L>(f));
1159template <
int MT,
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1163 For(n,std::forward<L>(f));
1166template <
typename L,
int dim>
1169 For(box,std::forward<L>(f));
1172template <
int MT,
typename L,
int dim>
1176 For(box,std::forward<L>(f));
1179template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1182 For(box,ncomp,std::forward<L>(f));
1185template <
int MT,
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1189 For(box,ncomp,std::forward<L>(f));
1192template <
typename L1,
typename L2,
int dim>
1195 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1198template <
int MT,
typename L1,
typename L2,
int dim>
1202 For(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1205template <
typename L1,
typename L2,
typename L3,
int dim>
1208 L1&& f1, L2&& f2, L3&& f3)
noexcept
1210 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1213template <
int MT,
typename L1,
typename L2,
typename L3,
int dim>
1216 L1&& f1, L2&& f2, L3&& f3)
noexcept
1219 For(box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1222template <
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
1223 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1224 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
1227 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1229 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1232template <
int MT,
typename T1,
typename T2,
typename L1,
typename L2,
int dim,
1233 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1234 typename M2=std::enable_if_t<std::is_integral_v<T2>> >
1237 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
noexcept
1240 For(box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1243template <
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1244 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1245 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1246 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1250 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1252 For(box1,ncomp1,std::forward<L1>(f1),
1253 box2,ncomp2,std::forward<L2>(f2),
1254 box3,ncomp3,std::forward<L3>(f3));
1257template <
int MT,
typename T1,
typename T2,
typename T3,
typename L1,
typename L2,
typename L3,
int dim,
1258 typename M1=std::enable_if_t<std::is_integral_v<T1>>,
1259 typename M2=std::enable_if_t<std::is_integral_v<T2>>,
1260 typename M3=std::enable_if_t<std::is_integral_v<T3>> >
1264 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
noexcept
1267 For(box1,ncomp1,std::forward<L1>(f1),
1268 box2,ncomp2,std::forward<L2>(f2),
1269 box3,ncomp3,std::forward<L3>(f3));
1272template <
typename T,
typename L,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1276 for (T i = 0; i < n; ++i) {
1284template <
int idim,
typename L,
int dim>
1286void ParallelForRNG_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv)
noexcept
1288 if constexpr (idim == 1) {
1289 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1290 call_f_intvect_engine(f,iv,RandomEngine{});
1292 }
else if constexpr (idim == 2) {
1293 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1294 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1295 call_f_intvect_engine(f,iv,RandomEngine{});
1297 }
else if constexpr (idim == 3) {
1298 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
1299 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1300 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1301 call_f_intvect_engine(f,iv,RandomEngine{});
1304 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
1305 ParallelForRNG_impND<idim-1>(f, lo, hi, iv);
1310template <
int idim,
typename L,
typename T,
int dim>
1312void ParallelForRNG_impND (L
const& f, IntVectND<dim>
const lo, IntVectND<dim>
const hi, IntVectND<dim> iv, T n)
noexcept
1314 if constexpr (idim == 1) {
1315 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1316 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1318 }
else if constexpr (idim == 2) {
1319 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1320 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1321 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1323 }
else if constexpr (idim == 3) {
1324 for (
int i2 = lo[2], h2 = hi[2]; i2 <= h2; ++i2) { iv[2] = i2;
1325 for (
int i1 = lo[1], h1 = hi[1]; i1 <= h1; ++i1) { iv[1] = i1;
1326 for (
int i0 = lo[0], h0 = hi[0]; i0 <= h0; ++i0) { iv[0] = i0;
1327 call_f_intvect_ncomp_engine(f,iv,n,RandomEngine{});
1330 for (
int id = lo[idim-1], hd = hi[idim-1];
id <= hd; ++id) { iv[idim-1] = id;
1331 ParallelForRNG_impND<idim-1>(f, lo, hi, iv, n);
1339template <
typename L,
int dim>
1346 detail::ParallelForRNG_impND<dim>(f, lo, hi, iv);
1349template <
typename T,
typename L,
int dim,
typename M=std::enable_if_t<std::is_
integral_v<T>> >
1356 for (T n = 0; n < ncomp; ++n) {
1357 detail::ParallelForRNG_impND<dim>(f, lo, hi, iv, n);
1361template <
typename L>
1364 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:138
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:140
void HostDeviceFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:922
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForSIMD(N n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:208
void HostDeviceParallelFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:809
__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:1362
AMREX_ATTRIBUTE_FLATTEN_FOR void For(T n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:154
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForRNG(T n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1274
Definition AMReX_RandomEngine.H:72
Definition AMReX_GpuLaunchFunctsC.H:17
static constexpr int width
Definition AMReX_GpuLaunchFunctsC.H:19
N index
Definition AMReX_GpuLaunchFunctsC.H:22