Gyselalib++
 
Loading...
Searching...
No Matches
pdi_helper.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3
4#include <pdi.h>
5
6namespace detail {
7
8template <class NameTuple, class OutputTuple, size_t... I>
9void PDI_get_array(
10 std::string event_name,
11 NameTuple names,
12 OutputTuple args,
13 std::integer_sequence<size_t, I...>)
14{
15 std::array<size_t, sizeof...(I)> sizes;
16 // Put sizes into PDI
17 ((PDI_share((std::get<I>(names) + "_extents").c_str(), &sizes[I], PDI_INOUT)), ...);
18 // Collect sizes from file
19 PDI_event((event_name + "_extents").c_str());
20 // Collect sizes from PDI
21 ((PDI_reclaim((std::get<I>(names) + "_extents").c_str())), ...);
22
23 // Update the size of the vectors
24 ((std::get<I>(args).resize(sizes[I])), ...);
25 // Put vector into PDI
26 ((PDI_share(std::get<I>(names).c_str(), std::get<I>(args).data(), PDI_INOUT)), ...);
27 // Collect vector from file
28 PDI_event(event_name.c_str());
29 // Collect vector from PDI
30 ((PDI_reclaim(std::get<I>(names).c_str())), ...);
31}
32
33template <class TupleType, size_t... I>
34auto get_name_tuple(TupleType input_args, std::integer_sequence<size_t, I...>)
35{
36 return std::make_tuple(std::string(std::get<I * 2>(input_args))...);
37}
38
39template <class TupleType, size_t... I>
40auto get_vector_tuple(TupleType input_args, std::integer_sequence<size_t, I...>)
41{
42 return std::tie(std::get<I * 2 + 1>(input_args)...);
43}
44
45} // namespace detail
46
50template <class T, class... Args>
51void PDI_get_arrays(
52 std::string event_name,
53 std::string name,
54 std::vector<T>& out_vector,
55 Args&... input_args)
56{
57 auto idx_sequence = std::make_index_sequence<sizeof...(Args) / 2 + 1> {};
58 auto arg_tuple = std::tie(name, out_vector, input_args...);
59 auto names = detail::get_name_tuple(arg_tuple, idx_sequence);
60 auto out_vectors = detail::get_vector_tuple(arg_tuple, idx_sequence);
61 detail::PDI_get_array(event_name, names, out_vectors, idx_sequence);
62}
63
64template <class... Grids>
65void PDI_expose_idx_range(IdxRange<Grids...> index_range, std::string name)
66{
67 IdxStep<Grids...> extents = index_range.extents();
68 Idx<Grids...> local_starts = index_range.front();
69 Idx<Grids...> global_starts(Idx<Grids> {0}...);
70 // TODO: Ghosts?
71 IdxStep<Grids...> starts = local_starts - global_starts;
72 int constexpr n_grids = sizeof...(Grids);
73 std::array<ddc::DiscreteVectorElement, n_grids> starts_arr = ddc::detail::array(starts);
74 std::array<ddc::DiscreteVectorElement, n_grids> extents_arr = ddc::detail::array(extents);
75 std::array<std::size_t, n_grids> starts_s_arr;
76 std::array<std::size_t, n_grids> extents_s_arr;
77 for (int i(0); i < n_grids; ++i) {
78 starts_s_arr[i] = std::size_t(starts_arr[i]);
79 extents_s_arr[i] = std::size_t(extents_arr[i]);
80 }
81 PDI_expose((name + "_starts").c_str(), starts_s_arr.data(), PDI_OUT);
82 PDI_expose((name + "_extents").c_str(), extents_s_arr.data(), PDI_OUT);
83}
A class which describes the real space in the temporal direction.
Definition geometry.hpp:44