67template<
class T,
int N, layout L = layout::right>
77 template<
class _T_,
int _N_, layout _L_>
friend class array;
99 template<
typename... Args>
206 for (
int i = 0; i < N; i++) {
254#if defined(CS_ARRAY_DBG_BOUNDS)
275#if defined(CS_ARRAY_DBG_BOUNDS)
289 template<
typename Id1>
292 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
299#if defined(CS_ARRAY_DBG_BOUNDS)
313 template<
typename Id1>
316 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
323#if defined(CS_ARRAY_DBG_BOUNDS)
337 template<
typename Id1,
typename Id2>
340 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
348#if defined(CS_ARRAY_DBG_BOUNDS)
368 template<
typename Id1,
typename Id2>
371 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
379#if defined(CS_ARRAY_DBG_BOUNDS)
399 template<
typename... Args>
402 std::enable_if_t<
cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
409#if defined(CS_ARRAY_DBG_BOUNDS)
424 template<
typename... Args>
427 std::enable_if_t<
cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
434#if defined(CS_ARRAY_DBG_BOUNDS)
467 template<
typename... Args>
581 return reinterpret_cast<U*
>(
_data);
607 template<
typename... Args>
609 mdspan<T, N-
sizeof...(Args), L>
617 constexpr int n_idx =
sizeof...(Args);
622 for (
int i = 0; i < N - n_idx; i++)
626 for (
int i = 0; i < N - n_idx; i++)
639 template<
typename... Args>
658 template<
typename... Args>
708 assert(n_vals <=
_size);
717 data_ptr[e_id] = val;
758 assert(n_elts <= _size && n_elts >= 0);
764 if (elt_ids ==
nullptr)
770 data_ptr[elt_ids[e_id]] = val;
808 data_ptr[e_id] =
static_cast<T
>(0);
874 assert(n_vals <=
_size);
882 data_ptr[e_id] =
data[e_id];
904 assert(n_vals <=
_size);
912 data_ptr[e_id] =
data[e_id];
935 assert(loop_size <=
_size);
936 assert(loop_size <= other.
size());
940 T* o_data_ptr = other.
_data;
943 data_ptr[e_id] = o_data_ptr[e_id];
956 template<
typename... Args>
965 static_assert(
sizeof...(Args) == N,
"Wrong number of arguments");
966 static_assert(
sizeof...(Args) != 0,
"No input arguments provided...");
967 static_assert(
cs::are_integral<Args...>::value,
"Non integral input arguments.");
976 template<
typename... Args>
985 static_assert(
sizeof...(Args) < N,
"Too many input arguments.");
986 static_assert(
sizeof...(Args) != 0,
"No input arguments provided...");
987 static_assert(
cs::are_integral<Args...>::value,
"Non integral indices provided");
996 template<
typename... Args>
1005 static_assert(
sizeof...(Args) <= N &&
sizeof...(Args) > 0,
1006 "Number of indices is out of bounds");
1008 constexpr int n_idx =
sizeof...(Args);
1010 cs_lnum_t _indices[n_idx] = {indices...};
1013 for (
int i = 0; i < n_idx; i++)
1014 retval +=_indices[i] *
_offset[i];
1025 template<
typename... Args>
1034 static_assert(
sizeof...(Args) <= N &&
sizeof...(Args) > 0,
1035 "Number of indices is out of bounds");
1037 constexpr int n_idx =
sizeof...(Args);
1039 cs_lnum_t _indices[n_idx] = {indices...};
1043 for (
int i = 0; i < n_idx; i++)
1044 retval +=_indices[i] *
_offset[i];
1047 for (
int i = 0; i < n_idx; i++)
1048 retval +=_indices[i] *
_offset[N-1-i];
1071 _size = (N > 0) ? 1 : 0;
1072 for (
int i = 0; i < N; i++) {
1082 for (
int i = 0; i < N-1; i++) {
1083 for (
int j = i + 1; j < N; j++)
1088 for (
int i = N-1; i >= 1; i--) {
1089 for (
int j = i - 1; j >= 0; j--)
1101 template<
typename... Args>
1124 template<
typename... Args>
1133 bool out_of_bounds =
false;
1134 constexpr int n_idx =
sizeof...(Args);
1136 for (
int i = 0; i < n_idx; i++) {
1138 out_of_bounds =
true;
1143 if (out_of_bounds) {
1144 char err[256] =
"Error: Out of bounds access with indices [";
1145 const char *sep =
",\0";
1146 const char *closeb =
"]\0";
1147 for (
int i = 0; i < n_idx; i++) {
1156 const char *tmp2 =
" but extents are [\0";
1158 for (
int i = 0; i < n_idx; i++) {
1167#if !defined(__CUDA_ARCH__) && \
1168 !defined(SYCL_LANGUAGE_VERSION) && \
1169 !defined(__HIP_DEVICE_COMPILE__)
1170 bft_error(__FILE__,__LINE__,0,
"%s\n", err);
1172 const char *empty_str =
" ";
1173 __assert_fail(err, empty_str, 0, empty_str);
1176 return out_of_bounds;
1191template<
class T, cs::layout L = cs::layout::right>
1194template<
class T, cs::layout L = cs::layout::right>
1197template<
class T, cs::layout L = cs::layout::right>
1200template<
class T, cs::layout L = cs::layout::right>
1203template<
class T,
int N>
1206template<
class T,
int N>
void bft_error(const char *const file_name, const int line_num, const int sys_error_code, const char *const format,...)
Calls the error handler (set by bft_error_handler_set() or default).
Definition: bft_error.cpp:187
Define a templated array class (owner of data)
Definition: cs_array.h:1118
Define a templated mdspan class (non owner of data)
Definition: cs_mdspan.h:68
CS_F_HOST_DEVICE mdspan(mdspan &&other)
Move constructor.
Definition: cs_mdspan.h:153
CS_F_HOST_DEVICE friend void swap(mdspan &first, mdspan &second)
Class swap operator used for assignment or move.
Definition: cs_mdspan.h:182
CS_F_HOST void copy_data(cs_dispatch_context &ctx, T *data, const cs_lnum_t n_vals=-1)
Copy data from raw pointer, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:867
CS_F_HOST void set_to_val_on_subset(T val, const cs_lnum_t n_elts, const cs_lnum_t elt_ids[])
Set subset of values of the data array to a constant value.
Definition: cs_mdspan.h:730
CS_F_HOST void zero(cs_dispatch_context &ctx)
Set all values of the data array to 0.
Definition: cs_mdspan.h:800
CS_F_HOST void set_to_val(T val, const cs_lnum_t n_vals=-1)
Set all values of the data array to a constant value.
Definition: cs_mdspan.h:680
CS_F_HOST_DEVICE mdspan< T, 1, L > view_1d()
Get span 1D view of the array, same total size.
Definition: cs_mdspan.h:594
CS_F_HOST void copy_data(mdspan &other, const cs_lnum_t n_vals=-1)
Copy data from another mdspan, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:845
CS_F_HOST_DEVICE bool check_bounds_(Args... dims) const
Check if provided arguments are within array bounds.
Definition: cs_mdspan.h:1129
CS_F_HOST_DEVICE mdspan(T *data, const cs_lnum_t(&dims)[N])
Constructor method using dimensions.
Definition: cs_mdspan.h:120
CS_F_HOST_DEVICE U * data() const
Getter for data raw pointer with recast (casts T* to U*)
Definition: cs_mdspan.h:579
CS_F_HOST void copy_data(cs_dispatch_context &ctx, const T *data, const cs_lnum_t n_vals=-1)
Copy data from const raw pointer, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:897
CS_F_HOST_DEVICE void set_size_(const cs_lnum_t(&dims)[N])
Set size of array based on dimensions.
Definition: cs_mdspan.h:1067
CS_F_HOST_DEVICE cs_lnum_t contiguous_data_offset_(Args... indices) const
Helper function to compute value offset.
Definition: cs_mdspan.h:1030
T * _data
Definition: cs_mdspan.h:1186
CS_F_HOST_DEVICE bool empty() const
Check if object is empty or not.
Definition: cs_mdspan.h:492
CS_F_HOST_DEVICE mdspan & operator=(mdspan &&other)
Definition: cs_mdspan.h:217
static CS_F_HOST_DEVICE void check_sub_function_args_(Args...)
Helper function to static check sub-function input arguments.
Definition: cs_mdspan.h:981
CS_F_HOST_DEVICE T * sub_array(Args... indices)
Get sub array based on index.
Definition: cs_mdspan.h:643
CS_F_HOST_DEVICE cs_lnum_t size() const
Getter for total size.
Definition: cs_mdspan.h:508
CS_F_HOST_DEVICE cs_lnum_t offset(int i) const
Getter for extent along a given dimension.
Definition: cs_mdspan.h:544
CS_F_HOST void zero()
Set all values of the data array to 0.
Definition: cs_mdspan.h:784
CS_F_HOST void set_to_val_on_subset(cs_dispatch_context &ctx, T val, const cs_lnum_t n_elts, const cs_lnum_t elt_ids[])
Set a subset of values of the data array to a constant value while providing a dispatch context....
Definition: cs_mdspan.h:751
CS_F_HOST_DEVICE mdspan()
Default constructor method leading to "empty container".
Definition: cs_mdspan.h:86
cs_lnum_t _size
Definition: cs_mdspan.h:1185
CS_F_HOST_DEVICE cs_lnum_t data_offset_(Args... indices) const
Helper function to compute value offset.
Definition: cs_mdspan.h:1001
cs_lnum_t _extent[N]
Definition: cs_mdspan.h:1183
CS_F_HOST_DEVICE ~mdspan()
Desstructor method using dimensions.
Definition: cs_mdspan.h:168
static CS_F_HOST_DEVICE void check_operator_args_(Args...)
Helper function to static check operator input arguments.
Definition: cs_mdspan.h:961
CS_F_HOST_DEVICE void set_size_(Args... dims)
Set size of N indices (variadic template)
Definition: cs_mdspan.h:1105
CS_F_HOST_DEVICE void update_data(T *data_ptr, Args... dims)
Update data pointer and dimensions of span.
Definition: cs_mdspan.h:471
cs_lnum_t _offset[N]
Definition: cs_mdspan.h:1184
CS_F_HOST_DEVICE mdspan(const mdspan &other)
Constructor method using copy. May be a shallow copy.
Definition: cs_mdspan.h:137
CS_F_HOST_DEVICE T * data() const
Getter for data raw pointer.
Definition: cs_mdspan.h:561
CS_F_HOST_DEVICE mdspan< T, N-sizeof...(Args), L > sub_view(Args... indices)
Getter for a subspan based on first dimension.
Definition: cs_mdspan.h:611
CS_F_HOST_DEVICE cs_lnum_t extent(int i) const
Getter for extent along a given dimension.
Definition: cs_mdspan.h:525
CS_F_HOST void copy_data(const T *data, const cs_lnum_t n_vals=-1)
Copy data from const raw pointer, we suppose that data size is same as that of the array.
Definition: cs_mdspan.h:823
CS_F_HOST_DEVICE mdspan(T *data, Args... indices)
Constructor method using only global size (works for N=1).
Definition: cs_mdspan.h:102
CS_F_HOST void set_to_val(cs_dispatch_context &ctx, T val, const cs_lnum_t n_vals=-1)
Set all values of the data array to a constant value while providing a dispatch context....
Definition: cs_mdspan.h:701
CS_F_HOST void copy_data(cs_dispatch_context &ctx, mdspan &other, const cs_lnum_t n_vals=-1)
Copy data from another mdspan, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:926
CS_F_HOST_DEVICE void set_data_ptr(T *data_ptr) const
Set data pointer.
Definition: cs_mdspan.h:454
CS_F_HOST_DEVICE T * sub_array(Args... indices) const
Get sub array based on index.
Definition: cs_mdspan.h:662
CS_F_HOST mdspan & operator=(const mdspan &other)
Assignment operator.
Definition: cs_mdspan.h:204
auto parallel_for(cs_lnum_t n, F &&f, Args &&... args)
Definition: cs_dispatch.h:2146
Definition: cs_dispatch.h:2288
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:555
#define CS_LAMBDA
Definition: cs_defs.h:564
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
#define CS_F_HOST
Definition: cs_defs.h:553
cs_dispatch_context & default_context(void)
Definition: cs_execution_context.cpp:62
Definition: cs_algorithm.h:51
layout
Definition: cs_mdspan.h:51
CS_F_HOST_DEVICE void concatenate_char(char *dest, const char *src)
Concatenate two strings (char *)
Definition: cs_defs.h:922
CS_F_HOST_DEVICE void uint_to_char(char *dest, Id1 val)
Convert an unsigned integer to an array of char.
Definition: cs_defs.h:886
CS_F_HOST_DEVICE constexpr std::enable_if_t< std::is_move_constructible< T >::value &&std::is_move_assignable< T >::value > swap_objects(T &obj1, T &obj2)
A swap method which is callable from GPU and not only CPU.
Definition: cs_defs.h:814
Utility template which returns "true" for a given pack. This is necessary of std::enable_if_t<> when ...
Definition: cs_defs.h:798
Utility template to check if a pack of parameters is made of integral types.
Definition: cs_defs.h:775