1 #ifndef AMREX_CTO_PARALLEL_FOR_H_
2 #define AMREX_CTO_PARALLEL_FOR_H_
25 #if (__cplusplus >= 201703L)
29 template<
class F,
int... ctr>
33 template<
class... Args>
35 auto operator() (Args... args)
const noexcept
36 -> decltype(
f(args..., std::integral_constant<int, ctr>{}...)) {
37 return f(args..., std::integral_constant<int, ctr>{}...);
42 std::array<
int,
sizeof...(ctr)> GetOptions () noexcept {
47 template <
class L,
typename... As,
class... Fs>
49 AnyCTO_helper2 (
const L& l, TypeList<As...>,
50 std::array<
int,
sizeof...(As)>
const& runtime_options,
const Fs&...cto_functs)
52 if (runtime_options == std::array<
int,
sizeof...(As)>{As::value...}) {
53 if constexpr (
sizeof...(cto_functs) != 0) {
56 l(CTOWrapper<Fs, As::value...>{cto_functs}...);
67 template <
class L,
typename... PPs,
typename RO,
class...Fs>
69 AnyCTO_helper1 (
const L& l, TypeList<PPs...>,
70 RO
const& runtime_options,
const Fs&...cto_functs)
72 bool found_option = (
false || ... ||
73 AnyCTO_helper2(l, PPs{}, runtime_options, cto_functs...));
182 template <
class L,
class... Fs,
typename... CTOs>
184 std::array<
int,
sizeof...(CTOs)>
const& runtime_options,
185 L&& l, Fs&&...cto_functs)
187 #if (__cplusplus >= 201703L)
188 detail::AnyCTO_helper1(std::forward<L>(l),
191 std::forward<Fs>(cto_functs)...);
194 static_assert(std::is_integral<F>::value,
"This requires C++17");
198 template <
int MT,
typename T,
class F,
typename... CTOs>
199 std::enable_if_t<std::is_integral_v<T>>
201 std::array<
int,
sizeof...(CTOs)>
const& runtime_options,
204 AnyCTO(ctos, runtime_options,
206 ParallelFor<MT>(N, cto_func);
212 template <
int MT,
class F,
int dim,
typename... CTOs>
214 std::array<
int,
sizeof...(CTOs)>
const& runtime_options,
217 AnyCTO(ctos, runtime_options,
219 ParallelFor<MT>(box, cto_func);
225 template <
int MT,
typename T,
class F,
int dim,
typename... CTOs>
226 std::enable_if_t<std::is_integral_v<T>>
228 std::array<
int,
sizeof...(CTOs)>
const& runtime_options,
231 AnyCTO(ctos, runtime_options,
233 ParallelFor<MT>(box, ncomp, cto_func);
283 template <
typename T,
class F,
typename... CTOs>
284 std::enable_if_t<std::is_integral_v<T>>
286 std::array<
int,
sizeof...(CTOs)>
const& option,
289 ParallelFor<AMREX_GPU_MAX_THREADS>(ctos, option, N, std::forward<F>(
f));
337 template <
class F,
int dim,
typename... CTOs>
339 std::array<
int,
sizeof...(CTOs)>
const& option,
342 ParallelFor<AMREX_GPU_MAX_THREADS>(ctos, option, box, std::forward<F>(
f));
391 template <
typename T,
class F,
int dim,
typename... CTOs>
392 std::enable_if_t<std::is_integral_v<T>>
394 std::array<
int,
sizeof...(CTOs)>
const& option,
397 ParallelFor<AMREX_GPU_MAX_THREADS>(ctos, option, box, ncomp, std::forward<F>(
f));
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
A Rectangular Domain on an Integer Lattice.
Definition: AMReX_Box.H:43
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
Definition: AMReX_Amr.cpp:49
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:200
void AnyCTO([[maybe_unused]] TypeList< CTOs... > list_of_compile_time_options, std::array< int, sizeof...(CTOs)> const &runtime_options, L &&l, Fs &&...cto_functs)
Compile time optimization of kernels with run time options.
Definition: AMReX_CTOParallelForImpl.H:183
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition: AMReX.H:111
constexpr auto CartesianProduct(Ls...)
Cartesian Product of TypeLists.
Definition: AMReX_TypeList.H:150
const int[]
Definition: AMReX_BLProfiler.cpp:1664
Definition: AMReX_FabArrayCommI.H:841
Definition: AMReX_CTOParallelForImpl.H:20
Struct for holding types.
Definition: AMReX_TypeList.H:12