42#if defined (__CUDACC__)
61#define CS_ARRAY_SUBSET_NULL -1
62#define CS_ARRAY_SUBSET_IN 0
63#define CS_ARRAY_SUBSET_OUT 1
64#define CS_ARRAY_SUBSET_INOUT 2
82#if defined(__cplusplus)
101template <
typename T,
size_t stride,
typename... Arrays>
108 T* array_ptrs[] = {arrays ... };
110#if defined (__CUDACC__)
112 for (T* array : array_ptrs)
113 is_available_on_device = is_available_on_device
117 if (is_available_on_device) {
118 cudaStream_t stream_ = cs_cuda_get_stream(0);
119 cs_arrays_set_value<T, stride>(stream_,
129 for (T* array : array_ptrs)
130 memcpy(array + i_elt*stride, ref_val, stride*
sizeof(T));
136# pragma omp parallel for num_threads(n_threads)
159template <
typename T,
size_t stride,
typename... Arrays>
166 T* array_ptrs[] = {arrays ... };
168#if defined (__CUDACC__)
169 bool is_available_on_device =
true;
170 for (T* array : array_ptrs)
171 is_available_on_device = is_available_on_device
175 if (is_available_on_device) {
176 cudaStream_t stream_ = cs_cuda_get_stream(0);
177 cs_arrays_set_value<T, stride>(stream_,
187 for (T* array : array_ptrs)
188 for (
size_t k = 0;
k < stride;
k++) {
189 array[i_elt*stride +
k] = ref_val;
196# pragma omp parallel for num_threads(n_threads)
223template <
typename T,
size_t stride,
typename... Arrays>
231 T* array_ptrs[] = {arrays ... };
233#if defined (__CUDACC__)
235 cudaStream_t stream_ = ctx.cuda_stream();
236 cs_arrays_set_value<T, stride>(stream_,
246 for (T* array : array_ptrs)
247 memcpy(array + i_elt*stride, ref_val, stride*
sizeof(T));
252 int n_threads = ctx.n_cpu_threads();
255# pragma omp parallel for num_threads(n_threads)
282template <
typename T,
size_t stride,
typename... Arrays>
290 T* array_ptrs[] = {arrays ... };
292#if defined (__CUDACC__)
294 cudaStream_t stream_ = ctx.cuda_stream();
295 cs_arrays_set_value<T, stride>(stream_,
305 for (T* array : array_ptrs)
306 for (
size_t k = 0;
k < stride;
k++) {
307 array[i_elt*stride +
k] = ref_val;
313 int n_threads = ctx.n_cpu_threads();
316# pragma omp parallel for num_threads(n_threads)
341template <
typename T,
size_t stride,
typename... Arrays>
348 T* array_ptrs[] = {arrays ... };
350#if defined (__CUDACC__)
352 cudaStream_t stream_ = ctx.cuda_stream();
353 cs_arrays_set_zero<T, stride>(stream_,
361 constexpr T c =
static_cast<T
>(0);
366 int n_threads = ctx.n_cpu_threads();
369# pragma omp parallel num_threads(n_threads)
372 for (T* array : array_ptrs) {
374# pragma omp for nowait
400template <
typename T,
size_t stride,
typename... Arrays>
411 cs_arrays_set_value<T, stride>(n_elts, ref_val, arrays...);
414 T* array_ptrs[] = {arrays ... };
417 for (T* array : array_ptrs)
418 memcpy(array + i_elt*stride, ref_val, stride*
sizeof(T));
424# pragma omp parallel for num_threads(n_threads)
427 set_value(elt_ids[i]);
449template <
typename T,
size_t stride,
typename... Arrays>
460 cs_arrays_set_value<T, stride>(n_elts, ref_val, arrays...);
464 T* array_ptrs[] = {arrays ... };
467 for (T* array : array_ptrs)
468 for (
size_t k = 0;
k < stride;
k++) {
469 array[i_elt*stride +
k] = ref_val;
476# pragma omp parallel for num_threads(n_threads)
479 set_value(elt_ids[i]);
502#if defined (__CUDACC__)
506 if (is_available_on_device) {
507 cudaStream_t stream_ = cs_cuda_get_stream(0);
508 cs_array_copy<T>(stream_, size, src, dest);
515# pragma omp parallel for num_threads(n_threads)
548# pragma omp parallel for num_threads(n_threads)
1096#if defined(__cplusplus)
1110template<
class T,
int N = 1, layout L = layout::right>
1129#if !defined(__CUDA_ARCH__) && \
1130 !defined(SYCL_LANGUAGE_VERSION) && \
1131 !defined(__HIP_DEVICE_COMPILE__)
1150#
if (defined(__GNUC__) || defined(__clang__)) && \
1153 const char *file_name = __builtin_FILE(),
1154 const int line_number = __builtin_LINE()
1156 const char *file_name = __FILE__,
1157 const int line_number = __LINE__
1169 static_assert(N == 1,
1170 "Instantiation using only total size only possible for "
1171 " cs::array<T,1> or cs::array<T>");
1173 allocate_(file_name, line_number);
1187#
if (defined(__GNUC__) || defined(__clang__)) && \
1190 const char *file_name = __builtin_FILE(),
1191 const int line_number = __builtin_LINE()
1193 const char *file_name = __FILE__,
1194 const int line_number = __LINE__
1205 allocate_(file_name, line_number);
1220#
if (defined(__GNUC__) || defined(__clang__)) && \
1223 const char *file_name = __builtin_FILE(),
1224 const int line_number = __builtin_LINE()
1226 const char *file_name = __FILE__,
1227 const int line_number = __LINE__
1238 static_assert(N == 2,
1239 "Instantiation using (size1, size2) only possible for "
1242 set_size_(tmp_size);
1243 allocate_(file_name, line_number);
1259#
if (defined(__GNUC__) || defined(__clang__)) && \
1262 const char *file_name = __builtin_FILE(),
1263 const int line_number = __builtin_LINE()
1265 const char *file_name = __FILE__,
1266 const int line_number = __LINE__
1277 static_assert(N == 3,
1278 "Instantiation using (size1, size2, size3) only possible "
1279 " for cs::array<T,3>");
1280 cs_lnum_t tmp_size[N] = {size1, size2, size3};
1281 set_size_(tmp_size);
1282 allocate_(file_name, line_number);
1299#
if (defined(__GNUC__) || defined(__clang__)) && \
1302 const char *file_name = __builtin_FILE(),
1303 const int line_number = __builtin_LINE()
1305 const char *file_name = __FILE__,
1306 const int line_number = __LINE__
1317 static_assert(N == 4,
1318 "Instantiation using (size1, size2, size3, size4) only possible "
1319 " for cs::array<T,4>");
1320 cs_lnum_t tmp_size[N] = {size1, size2, size3, size4};
1321 set_size_(tmp_size);
1322 allocate_(file_name, line_number);
1331 template<
typename... Args>
1343 check_operator_args_(indices...);
1344 set_size_(indices...);
1365#if !defined(__CUDA_ARCH__) && \
1366 !defined(SYCL_LANGUAGE_VERSION) && \
1367 !defined(__HIP_DEVICE_COMPILE__)
1392 bool deep_copy=
false,
1393#
if (defined(__GNUC__) || defined(__clang__)) && \
1396 const char *file_name = __builtin_FILE(),
1397 const int line_number = __builtin_LINE()
1399 const char *file_name = __FILE__,
1400 const int line_number = __LINE__
1404 set_size_(other._extent);
1405 _mode = other._mode;
1410#if !defined(__CUDA_ARCH__) && \
1411 !defined(SYCL_LANGUAGE_VERSION) && \
1412 !defined(__HIP_DEVICE_COMPILE__)
1419#if !defined(__CUDA_ARCH__) && \
1420 !defined(SYCL_LANGUAGE_VERSION) && \
1421 !defined(__HIP_DEVICE_COMPILE__)
1424 allocate_(file_name, line_number);
1434 _data = other._data;
1483 swap(first._extent, second._extent);
1484 swap(first._offset, second._offset);
1485 swap(first._size, second._size);
1486 swap(first._owner, second._owner);
1487 swap(first._data, second._data);
1488 swap(first._mode, second._mode);
1518#if !defined(__CUDA_ARCH__) && \
1519 !defined(SYCL_LANGUAGE_VERSION) && \
1520 !defined(__HIP_DEVICE_COMPILE__)
1528 for (
int i = 0; i < N; i++) {
1557 template<
typename... Args>
1559 mdspan<T, N-
sizeof...(Args), L>
1565 check_sub_function_args_(indices...);
1567 return (this->
view()).sub_view(indices...);
1580 template<
int _N_, layout _L_ = L>
1590 for (
int i = 0; i < _N_; i++)
1594#if !defined(__CUDA_ARCH__) && \
1595 !defined(SYCL_LANGUAGE_VERSION) && \
1596 !defined(__HIP_DEVICE_COMPILE__)
1598 _(
"%s: requested span has total size of %d instead of %d "
1599 "for this array.\n"),
1600 __func__, s, _size);
1619 template<
layout _L_ = L,
typename... Args>
1621 mdspan<T,
sizeof...(Args), _L_>
1627 check_non_empty_args_(indices...);
1629 constexpr int n_vals =
sizeof...(Args);
1630 cs_lnum_t tmp_args[n_vals] = {indices...};
1632 return get_mdspan<n_vals, _L_>(tmp_args);
1649 assert(n_vals <= _size);
1651 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
1654 T* data_ptr = _data;
1659 data_ptr[e_id] = val;
1682 assert(n_vals <= _size);
1684 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
1687 T* data_ptr = _data;
1691 data_ptr[e_id] = val;
1709 assert(n_elts <= _size && n_elts >= 0);
1716 if (elt_ids ==
nullptr)
1720 T* data_ptr = _data;
1723 data_ptr[elt_ids[e_id]] = val;
1748 assert(n_elts <= _size && n_elts >= 0);
1754 if (elt_ids ==
nullptr)
1758 T* data_ptr = _data;
1761 data_ptr[elt_ids[e_id]] = val;
1779 T* data_ptr = _data;
1782 data_ptr[e_id] =
static_cast<T
>(0);
1802 T* data_ptr = _data;
1805 data_ptr[e_id] =
static_cast<T
>(0);
1835#
if (defined(__GNUC__) || defined(__clang__)) && \
1838 const char *file_name = __builtin_FILE(),
1839 const int line_number = __builtin_LINE()
1841 const char *file_name = __FILE__,
1842 const int line_number = __LINE__
1846 static_assert(N == 1,
1847 "Method reshape(size, ...) only possible for "
1848 " cs::array<T> or cs::array<T,1>");
1849 assert(new_size >= 0);
1852 if (new_size == _size)
1856 set_size_(new_size);
1857 reallocate_(file_name, line_number);
1861 _(
"%s: array cannot be reshaped if non owner, "
1862 "use mdspan instead.\n"), __func__);
1878#
if (defined(__GNUC__) || defined(__clang__)) && \
1881 const char *file_name = __builtin_FILE(),
1882 const int line_number = __builtin_LINE()
1884 const char *file_name = __FILE__,
1885 const int line_number = __LINE__
1890 "Method reshape_and_copy(size, ...) only possible for "
1891 " cs::array<T> or cs::array<T,1>");
1892 assert(new_size >= 0);
1893 assert(size_to_keep <= new_size && size_to_keep <= _size);
1896 if (new_size == _size)
1899 if (!(size_to_keep <= new_size && size_to_keep <= _size))
1901 "%s: Data cannot be saved when new size is smaller "
1902 "than size to keep.\n",
1907 set_size_(new_size);
1908 reallocate_(file_name, line_number);
1912 _(
"%s: array cannot be reshaped if non owner, "
1913 "use mdspan instead.\n"), __func__);
1926#
if (defined(__GNUC__) || defined(__clang__)) && \
1929 const char *file_name = __builtin_FILE(),
1930 const int line_number = __builtin_LINE()
1932 const char *file_name = __FILE__,
1933 const int line_number = __LINE__
1938 bool same_dim =
true;
1939 for (
int i = 0; i < N; i++)
1940 if (dims[i] != _extent[i])
1948 reallocate_(file_name, line_number);
1952 _(
"%s: array cannot be reshaped if non owner, "
1953 "use mdspan instead.\n"), __func__);
1967#
if (defined(__GNUC__) || defined(__clang__)) && \
1970 const char *file_name = __builtin_FILE(),
1971 const int line_number = __builtin_LINE()
1973 const char *file_name = __FILE__,
1974 const int line_number = __LINE__
1978 assert(size_to_keep <= dims[N-1] && size_to_keep <= _extent[N-1]);
1981 bool same_dim =
true;
1982 for (
int i = 0; i < N; i++)
1983 if (dims[i] != _extent[i])
1991 if (size_to_keep != 0) {
1997 reallocate_(file_name, line_number);
2000 cs_lnum_t new_o[N], new_e[N], old_o[N], old_e[N], max_e[N];
2002 for (
int i = 0; i < N; i++) {
2003 new_o[i] = _offset[i];
2004 new_e[i] = _extent[i];
2005 old_o[i] = tmp._offset[i];
2006 old_e[i] = tmp._extent[i];
2008 max_e[i] = (new_e[i] > old_e[i]) ? old_e[i] : new_e[i];
2010 if (max_e[N-1] > size_to_keep && size_to_keep > 0)
2011 max_e[N-1] = size_to_keep;
2013 T* old_data = tmp._data;
2014 T* new_data = _data;
2025 for (
int i = N-1; i >= 1; i--) {
2026 idx[i] = dummy % old_e[i];
2027 dummy = (dummy - idx[i]) / old_e[i];
2032 for (
int i = 0; i < N; i++) {
2033 if (idx[i] >= max_e[i]) {
2043 for (
int i = 0; i < N; i++) {
2044 o_id += idx[i] * old_o[i];
2045 n_id += idx[i] * new_o[i];
2048 new_data[n_id] = old_data[o_id];
2055 reshape(dims, file_name, line_number);
2060 _(
"%s: array cannot be reshaped if non owner, "
2061 "use mdspan instead.\n"), __func__);
2076#
if (defined(__GNUC__) || defined(__clang__)) && \
2079 const char *file_name = __builtin_FILE(),
2080 const int line_number = __builtin_LINE()
2082 const char *file_name = __FILE__,
2083 const int line_number = __LINE__
2087 static_assert(N == 2,
2088 "Method reshape(size1, size2, ...) only possible for "
2092 reshape(tmp_size, file_name, line_number);
2108#
if (defined(__GNUC__) || defined(__clang__)) && \
2111 const char *file_name = __builtin_FILE(),
2112 const int line_number = __builtin_LINE()
2114 const char *file_name = __FILE__,
2115 const int line_number = __LINE__
2119 static_assert(N == 2,
2120 "Method reshape_and_copy(size1, size2, ...) only possible for "
2140#
if (defined(__GNUC__) || defined(__clang__)) && \
2143 const char *file_name = __builtin_FILE(),
2144 const int line_number = __builtin_LINE()
2146 const char *file_name = __FILE__,
2147 const int line_number = __LINE__
2151 static_assert(N == 3,
2152 "Method reshape(size1, size2, size3, ...) only possible for "
2154 cs_lnum_t tmp_size[N] = {size1, size2, size3};
2156 reshape(tmp_size, file_name, line_number);
2173#
if (defined(__GNUC__) || defined(__clang__)) && \
2176 const char *file_name = __builtin_FILE(),
2177 const int line_number = __builtin_LINE()
2179 const char *file_name = __FILE__,
2180 const int line_number = __LINE__
2184 static_assert(N == 3,
2185 "Method reshape_and_copy(size1, size2, size3, ...) only "
2186 "possible for cs::array<T,3>");
2187 cs_lnum_t tmp_size[N] = {size1, size2, size3};
2204 if (_mode !=
mode) {
2221 template<
typename... Args>
2229 check_sub_function_args_(indices...);
2231 return _data + contiguous_data_offset_(indices...);
2242 template<
typename... Args>
2250 check_sub_function_args_(indices...);
2252 return _data + contiguous_data_offset_(indices...);
2278 template<
typename U>
2283 return reinterpret_cast<U*
>(_data);
2343 template<
typename Id1>
2346 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
2352 check_operator_args_(i);
2364 template<
typename Id1>
2367 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
2373 check_operator_args_(i);
2385 template<
typename Id1,
typename Id2>
2388 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
2395 check_operator_args_(i,j);
2398 return _data[i*_offset[0] + j];
2400 return _data[i + j*_offset[1]];
2402 return _data[i*_offset[0] + j*_offset[1]];
2413 template<
typename Id1,
typename Id2>
2416 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
2423 check_operator_args_(i,j);
2426 return _data[i*_offset[0] + j];
2428 return _data[i + j*_offset[1]];
2430 return _data[i*_offset[0] + j*_offset[1]];
2441 template<
typename... Args>
2444 std::enable_if_t<
cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
2450 check_operator_args_(indices...);
2452 return _data[data_offset_(indices...)];
2463 template<
typename... Args>
2466 std::enable_if_t<
cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
2472 check_operator_args_(indices...);
2474 return _data[data_offset_(indices...)];
2665 assert(n_vals <= _size);
2667 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
2670 T* data_ptr = _data;
2675 data_ptr[e_id] =
data[e_id];
2697 assert(n_vals <= _size);
2699 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
2702 T* data_ptr = _data;
2707 data_ptr[e_id] =
data[e_id];
2729 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
2731 assert(loop_size <= _size);
2732 assert(loop_size <= other._size);
2735 T* data_ptr = _data;
2736 T* o_data_ptr = other._data;
2741 data_ptr[e_id] = o_data_ptr[e_id];
2763 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
2765 assert(loop_size <= _size);
2766 assert(loop_size <= span._size);
2769 T* data_ptr = _data;
2770 T* s_data_ptr = span._data;
2775 data_ptr[e_id] = s_data_ptr[e_id];
2799 assert(n_vals <= _size);
2800 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
2803 T* data_ptr = _data;
2806 data_ptr[e_id] =
data[e_id];
2828 assert(n_vals <= _size);
2829 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
2832 T* data_ptr = _data;
2835 data_ptr[e_id] =
data[e_id];
2857 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
2859 assert(loop_size <= _size);
2860 assert(loop_size <= other._size);
2863 T* data_ptr = _data;
2864 T* o_data_ptr = other._data;
2867 data_ptr[e_id] = o_data_ptr[e_id];
2889 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
2891 assert(loop_size <= _size);
2892 assert(loop_size <= span._size);
2895 T* data_ptr = _data;
2896 T* s_data_ptr = span._data;
2899 data_ptr[e_id] = s_data_ptr[e_id];
2911 template<
typename... Args>
2915 check_operator_args_
2920 static_assert(
sizeof...(Args) == N,
"Wrong number of arguments");
2921 static_assert(
cs::are_integral<Args...>::value,
"Non integral input arguments.");
2930 template<
typename... Args>
2934 check_sub_function_args_
2939 static_assert(
sizeof...(Args) < N,
"Too many input arguments.");
2940 static_assert(
cs::are_integral<Args...>::value,
"Non integral input arguments.");
2949 template<
typename... Args>
2953 check_non_empty_args_
2958 static_assert(
sizeof...(Args) > 0,
"At least one input argument is needed.");
2959 static_assert(
cs::are_integral<Args...>::value,
"Non integral input arguments.");
2968 template<
typename... Args>
2977 static_assert(
sizeof...(Args) <= N &&
sizeof...(Args) > 0,
2978 "Too many or too few input arguments.");
2980 constexpr int n_idx =
sizeof...(Args);
2982 cs_lnum_t _indices[n_idx] = {indices...};
2985 for (
int i = 0; i < n_idx; i++)
2986 retval +=_indices[i] * _offset[i];
2997 template<
typename... Args>
3001 contiguous_data_offset_
3006 static_assert(
sizeof...(Args) <= N &&
sizeof...(Args) > 0,
3007 "Too many or too few input arguments.");
3009 constexpr int n_idx =
sizeof...(Args);
3011 cs_lnum_t _indices[n_idx] = {indices...};
3015 for (
int i = 0; i < n_idx; i++)
3016 retval +=_indices[i] * _offset[i];
3019 for (
int i = 0; i < n_idx; i++)
3020 retval +=_indices[i] * _offset[N-1-i];
3039 _size = (N > 0) ? 1 : 0;
3040 for (
int i = 0; i < N; i++) {
3041 _extent[i] = dims[i];
3050 for (
int i = 0; i < N-1; i++) {
3051 for (
int j = i + 1; j < N; j++)
3052 _offset[i] *= dims[j];
3056 for (
int i = N-1; i >= 1; i--) {
3057 for (
int j = i - 1; j >= 0; j--)
3058 _offset[i] *= dims[j];
3069 template<
typename... Args>
3077 check_operator_args_(dims...);
3081 set_size_(loc_dims);
3094 const char *file_name,
3095 const int line_number
3098 const char *_ptr_name =
"cs::array._data";
3099 _data =
static_cast<T *
>(cs_mem_malloc_hd(_mode,
3117 const char *file_name,
3118 const int line_number
3123 const char *_ptr_name =
"cs::array._data";
3124 _data =
static_cast<T *
>(cs_mem_realloc_hd(_data,
3156template<
class T, cs::layout L = cs::layout::right>
3159template<
class T, cs::layout L = cs::layout::right>
3162template<
class T, cs::layout L = cs::layout::right>
3165template<
class T,
int N, cs::layout L = cs::layout::right>
3168template<
class T,
int N>
3171template<
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:193
Definition: cs_array.h:1111
CS_F_HOST_DEVICE mdspan< T, _N_, _L_ > get_mdspan(const cs_lnum_t(&dims)[_N_])
Get span view of array with a given array of dimensions (extent). If total size of span is different ...
Definition: cs_array.h:1584
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_array.h:2792
CS_F_HOST void copy_data(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_array.h:2659
CS_F_HOST_DEVICE void set_alloc_mode(cs_alloc_mode_t mode)
Set memory allocation mode.
Definition: cs_array.h:2200
CS_F_HOST array(cs_lnum_t size1, cs_lnum_t size2, cs_alloc_mode_t alloc_mode=cs_alloc_mode, const char *file_name=__FILE__, const int line_number=__LINE__)
Constructor method for 2D array based on sizes.
Definition: cs_array.h:1216
CS_F_HOST_DEVICE const T * data() const
Const getter to data array.
Definition: cs_array.h:2294
CS_F_HOST_DEVICE cs_alloc_mode_t mode() const
Getter function for allocation mode.
Definition: cs_array.h:2644
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_array.h:1703
CS_F_HOST void zero(cs_dispatch_context &ctx)
Set all values of the data array to 0.
Definition: cs_array.h:1797
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_array.h:1643
CS_F_HOST_DEVICE cs_lnum_t size()
Getter function for total size.
Definition: cs_array.h:2564
CS_F_HOST friend void swap(array &first, array &second)
Class swap operator used for assignment or move.
Definition: cs_array.h:1475
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_array.h:2821
CS_F_HOST_DEVICE bool owner()
Getter function for owner status.
Definition: cs_array.h:2596
CS_F_HOST void reshape(cs_lnum_t new_size, const char *file_name=__FILE__, const int line_number=__LINE__)
Resize data array.
Definition: cs_array.h:1833
CS_F_HOST array(cs_lnum_t size, cs_alloc_mode_t alloc_mode=cs_alloc_mode, const char *file_name=__FILE__, const int line_number=__LINE__)
Constructor method using only size.
Definition: cs_array.h:1147
CS_F_HOST void reshape_and_copy(cs_lnum_t new_size, cs_lnum_t size_to_keep, const char *file_name=__FILE__, const int line_number=__LINE__)
Resize data array and copy old data.
Definition: cs_array.h:1875
CS_F_HOST_DEVICE T * sub_array(Args... indices)
Get sub array based on index.
Definition: cs_array.h:2225
CS_F_HOST_DEVICE mdspan< T, N, L > view()
Get span view of array, same dimensions as array.
Definition: cs_array.h:1544
CS_F_HOST void copy_data(mdspan< T, N, L > &span, const cs_lnum_t n_vals=-1)
Copy data from a span, we suppose that data size is same as that of the array. An assert test the siz...
Definition: cs_array.h:2757
CS_F_HOST_DEVICE cs_lnum_t size() const
Getter function for total size.
Definition: cs_array.h:2580
CS_F_HOST array & operator=(array other)
Assignment operator.
Definition: cs_array.h:1499
CS_F_HOST_DEVICE cs_lnum_t offset(int i) const
Getter function for offset per dimension.
Definition: cs_array.h:2546
CS_F_HOST array(cs_lnum_t size1, cs_lnum_t size2, cs_lnum_t size3, cs_lnum_t size4, cs_alloc_mode_t alloc_mode=cs_alloc_mode, const char *file_name=__FILE__, const int line_number=__LINE__)
Constructor method for 4D array based on sizes.
Definition: cs_array.h:1293
CS_F_HOST void reshape(const cs_lnum_t(&dims)[N], const char *file_name=__FILE__, const int line_number=__LINE__)
Resize data array and do not keep old data.
Definition: cs_array.h:1924
CS_F_HOST void reshape(const cs_lnum_t size1, const cs_lnum_t size2, const char *file_name=__FILE__, const int line_number=__LINE__)
Resize data array 2D (no explicit copy, only realloc)
Definition: cs_array.h:2073
CS_F_HOST_DEVICE cs_lnum_t extent(int i)
Getter function for size per dimension (extent).
Definition: cs_array.h:2489
CS_F_HOST void zero()
Set all values of the data array to 0.
Definition: cs_array.h:1774
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_array.h:1740
CS_F_HOST_DEVICE array()
Default constructor method leading to "empty container".
Definition: cs_array.h:1122
CS_F_HOST_DEVICE cs_lnum_t offset(int i)
Getter function for offset per dimension.
Definition: cs_array.h:2527
CS_F_HOST array(cs_lnum_t size1, cs_lnum_t size2, cs_lnum_t size3, cs_alloc_mode_t alloc_mode=cs_alloc_mode, const char *file_name=__FILE__, const int line_number=__LINE__)
Constructor method for 3D array based on sizes.
Definition: cs_array.h:1254
CS_F_HOST_DEVICE U * data()
Getter for data raw pointer with recast (casts T* to U*)
Definition: cs_array.h:2281
CS_F_HOST void copy_data(cs_dispatch_context &ctx, mdspan< T, N, L > &span, const cs_lnum_t n_vals=-1)
Copy data from a span, we suppose that data size is same as that of the array. A dispatch_context is ...
Definition: cs_array.h:2882
CS_F_HOST_DEVICE cs_alloc_mode_t mode()
Getter function for allocation mode.
Definition: cs_array.h:2628
CS_F_HOST_DEVICE void clear()
Clear data (empty container).
Definition: cs_array.h:1514
CS_F_HOST_DEVICE T * data()
Getter to data array.
Definition: cs_array.h:2263
CS_F_HOST void reshape_and_copy(const cs_lnum_t size1, const cs_lnum_t size2, cs_lnum_t size_to_keep, const char *file_name=__FILE__, const int line_number=__LINE__)
Resize data array and copy old data (2D)
Definition: cs_array.h:2104
CS_F_HOST void reshape(const cs_lnum_t size1, const cs_lnum_t size2, const cs_lnum_t size3, const char *file_name=__FILE__, const int line_number=__LINE__)
Resize data array 3D (no explicit copy, only realloc)
Definition: cs_array.h:2136
CS_F_HOST array(const cs_lnum_t(&dims)[N], cs_alloc_mode_t alloc_mode=cs_alloc_mode, const char *file_name=__FILE__, const int line_number=__LINE__)
Constructor method using dimensions.
Definition: cs_array.h:1184
CS_F_HOST_DEVICE array(T *data, const cs_lnum_t(&dims)[N])
Constructor method for non owner version in multidimensional.
Definition: cs_array.h:1356
CS_F_HOST_DEVICE mdspan< T, N-sizeof...(Args), L > sub_view(Args... indices)
Get span sub-view of array, with lower dimensionality.
Definition: cs_array.h:1561
CS_F_HOST void reshape_and_copy(const cs_lnum_t(&dims)[N], cs_lnum_t size_to_keep=-1, const char *file_name=__FILE__, const int line_number=__LINE__)
Resize data array and copy old data.
Definition: cs_array.h:1964
CS_F_HOST_DEVICE ~array()
Destructor method.
Definition: cs_array.h:1461
CS_F_HOST_DEVICE cs_lnum_t extent(int i) const
Getter function for size per dimension (extent).
Definition: cs_array.h:2508
CS_F_HOST void copy_data(cs_dispatch_context &ctx, array &other, 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_array.h:2850
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_array.h:2691
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_array.h:1675
CS_F_HOST_DEVICE void set_empty()
Initializer method for empty containers.
Definition: cs_array.h:1817
CS_F_HOST_DEVICE array(const array &other, bool deep_copy=false, const char *file_name=__FILE__, const int line_number=__LINE__)
Constructor method using copy. May be a shallow copy.
Definition: cs_array.h:1390
CS_F_HOST void copy_data(array &other, const cs_lnum_t n_vals=-1)
Copy data from another array, we suppose that data size is same as that of the array....
Definition: cs_array.h:2723
CS_F_HOST_DEVICE bool owner() const
Getter function for owner status.
Definition: cs_array.h:2612
CS_F_HOST_DEVICE T * sub_array(Args... indices) const
Const get sub array based on index.
Definition: cs_array.h:2246
CS_F_HOST array(array &&other)
Move constructor.
Definition: cs_array.h:1446
CS_F_HOST_DEVICE array(T *data, Args... indices)
Constructor method for non owner version.
Definition: cs_array.h:1334
CS_F_HOST_DEVICE void reshape_and_copy(const cs_lnum_t size1, const cs_lnum_t size2, const cs_lnum_t size3, cs_lnum_t size_to_keep, const char *file_name=__FILE__, const int line_number=__LINE__)
Resize data array and copy old data (3D)
Definition: cs_array.h:2168
Definition: cs_mdspan.h:69
auto parallel_for(cs_lnum_t n, F &&f, Args &&... args)
Definition: cs_dispatch.h:1570
void wait(void)
Wait (synchronize) until launched computations have finished.
Definition: cs_dispatch.h:1635
Definition: cs_dispatch.h:1711
void cs_array_real_fill_zero(cs_lnum_t size, cs_real_t a[])
Assign zero to all elements of an array.
Definition: cs_array.cpp:1019
void cs_array_real_set_wvalue(cs_lnum_t n_elts, int stride, const cs_real_t ref_val[], const cs_real_t weight[], cs_real_t a[])
Assign a weighted constant value of dim "stride" to an interlaced array sharing the same stride....
Definition: cs_array.cpp:602
void cs_array_real_set_scalar_on_subset(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], cs_real_t ref_val, cs_real_t a[])
Assign a constant scalar value to an array on a selected subset of elements. If elt_ids is null,...
Definition: cs_array.cpp:766
void cs_array_set_value_real(cs_lnum_t n_elts, cs_lnum_t dim, cs_real_t v, cs_real_t a[])
Assign a constant value to an array (deprecated function).
Definition: cs_array.cpp:1045
void cs_array_bool_fill_false(cs_lnum_t size, bool a[])
Assign false to all elements of an array. Case of an array of booleans.
Definition: cs_array.cpp:106
void cs_arrays_set_zero(cs_dispatch_context &ctx, const cs_lnum_t n_elts, Arrays &&... arrays)
Assign zero value to all elements of multiple arrays.
Definition: cs_array.h:343
void cs_array_real_set_tensor(cs_lnum_t n_elts, const cs_real_t ref_tens[3][3], cs_real_t a[])
Assign a constant 3x3 tensor to an array (of stride 9) which is interlaced.
Definition: cs_array.cpp:950
void cs_array_int_fill_zero(cs_lnum_t size, int a[])
Assign zero to all elements of an array. Case of a int array.
Definition: cs_array.cpp:247
void cs_array_real_set_vector(cs_lnum_t n_elts, const cs_real_t ref_val[3], cs_real_t a[])
Assign a constant vector to an array of stride 3 which is interlaced.
Definition: cs_array.cpp:830
void cs_array_flag_fill_zero(cs_lnum_t size, cs_flag_t a[])
Assign zero to all elements of an array. Case of a cs_flag_t array.
Definition: cs_array.cpp:124
void cs_array_real_scale(cs_lnum_t n_elts, int stride, const cs_lnum_t *elt_ids, cs_real_t scaling_factor, cs_real_t dest[])
Multiply each value by a scaling factor s.t. dest *= scaling_factor If elt_ids is non-null,...
Definition: cs_array.cpp:489
void cs_arrays_set_value_on_subset(const cs_lnum_t n_elts, const cs_lnum_t *elt_ids, const T *ref_val, Arrays &&... arrays)
Assign values on a selected subset of elements to multiple arrays. ref_val is input as a pointer or a...
Definition: cs_array.h:402
void cs_array_difference(cs_lnum_t size, const T *x, const T *y, T *diff)
Compute the difference diff = x - y. All arrays have the same dimension.
Definition: cs_array.h:539
void cs_array_real_set_wvector_on_subset(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], const cs_real_t ref_val[3], const cs_real_t weight[], cs_real_t a[])
Assign a weighted constant vector value to an interlaced array (of stride 3). The subset selection is...
Definition: cs_array.cpp:916
void cs_array_copy(const cs_lnum_t size, const T *src, T *dest)
Copy values from an array to another of the same dimensions.
Definition: cs_array.h:498
void cs_array_real_copy_subset(cs_lnum_t n_elts, int stride, const cs_lnum_t elt_ids[], int mode, const cs_real_t ref[], cs_real_t dest[])
Copy an array ("ref") into another array ("dest") on possibly only a part of the array(s)....
Definition: cs_array.cpp:336
void cs_array_lnum_fill_zero(cs_lnum_t size, cs_lnum_t a[])
Assign zero to all elements of an array. Case of a cs_lnum_t array.
Definition: cs_array.cpp:146
void cs_array_lnum_set_value_on_subset(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], cs_lnum_t num, cs_lnum_t a[])
Assign the value "num" to an array on a selected subset of elements. if elt_ids is null,...
Definition: cs_array.cpp:222
void cs_array_real_set_scalar(cs_lnum_t n_elts, cs_real_t ref_val, cs_real_t a[])
Assign a constant scalar value to an array.
Definition: cs_array.cpp:720
void cs_array_bool_fill_true(cs_lnum_t size, bool a[])
Assign true to all elements of an array. Case of an array of booleans.
Definition: cs_array.cpp:88
void cs_array_real_set_vector_on_subset(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], const cs_real_t ref_val[3], cs_real_t a[])
Assign a constant vector to an interlaced array (of stride 3) on a selected subset of elements....
Definition: cs_array.cpp:881
void cs_array_real_set_value_on_subset(cs_lnum_t n_elts, int stride, const cs_lnum_t elt_ids[], const cs_real_t ref_val[], cs_real_t a[])
Assign a constant value of dim "stride" to an interlaced array sharing the same stride....
Definition: cs_array.cpp:641
void cs_array_real_padd(cs_lnum_t n_elts, const cs_real_t l_add[], cs_real_t r[])
Add in place an array s.t. r += l_add.
Definition: cs_array.cpp:541
void cs_array_lnum_copy(cs_lnum_t size, const cs_lnum_t src[], cs_lnum_t dest[])
Copy values from an array of cs_lnum_t type to another of the same dimensions.
Definition: cs_array.cpp:170
void cs_array_real_copy(cs_lnum_t size, const cs_real_t src[], cs_real_t dest[])
Copy real values from an array to another of the same dimensions.
Definition: cs_array.cpp:457
void cs_array_int_set_value(cs_lnum_t size, int num, int a[])
Assign the value "num" to all elements of an array. Case of a int array.
Definition: cs_array.cpp:271
void cs_array_real_set_value(cs_lnum_t n_elts, int stride, const cs_real_t ref_val[], cs_real_t a[])
Assign a constant value of dim "stride" to an interlaced array sharing the same stride.
Definition: cs_array.cpp:567
void cs_arrays_set_value(const cs_lnum_t n_elts, const T *ref_val, Arrays &&... arrays)
Assign values to all elements of multiple arrays. ref_val is input as a pointer or an array.
Definition: cs_array.h:103
void cs_array_real_set_wscalar_on_subset(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], cs_real_t ref_val, const cs_real_t weight[], cs_real_t a[])
Assign a weighted constant scalar value to an array on a selected subset of elements....
Definition: cs_array.cpp:799
void cs_array_real_set_tensor_on_subset(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], const cs_real_t ref_tens[3][3], cs_real_t a[])
Assign a constant 3x3 tensor to an interlaced array (of stride 9) on a subset of elements....
Definition: cs_array.cpp:985
void cs_array_real_set_wvector(cs_lnum_t n_elts, const cs_real_t ref_val[3], const cs_real_t weight[], cs_real_t a[])
Assign a weighted constant vector value to an interlaced array (of stride 3). The array of weights ha...
Definition: cs_array.cpp:854
void cs_array_lnum_set_value(cs_lnum_t size, cs_lnum_t num, cs_lnum_t a[])
Assign the value "num" to all elements of an array. Case of a cs_lnum_t array.
Definition: cs_array.cpp:199
void cs_array_real_set_wvalue_on_subset(cs_lnum_t n_elts, int stride, const cs_lnum_t elt_ids[], const cs_real_t ref_val[], const cs_real_t weight[], cs_real_t a[])
Assign a weighted constant value of dim "stride" to an interlaced array sharing the same stride....
Definition: cs_array.cpp:682
void cs_array_int_set_value_on_subset(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], int num, int a[])
Assign the value "num" to an array on a selected subset of elements. if elt_ids is null,...
Definition: cs_array.cpp:294
void cs_array_real_set_wscalar(cs_lnum_t n_elts, cs_real_t ref_val, const cs_real_t weight[], cs_real_t a[])
Assign a weighted constant scalar value to an array. The weight array has the same size as the array ...
Definition: cs_array.cpp:742
#define __has_builtin(x)
Definition: cs_array_2dspan.h:48
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:585
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
#define _(String)
Definition: cs_defs.h:67
#define CS_LAMBDA
Definition: cs_defs.h:594
#define CS_THR_MIN
Definition: cs_defs.h:508
#define CS_UNUSED(x)
Definition: cs_defs.h:543
#define END_C_DECLS
Definition: cs_defs.h:555
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
unsigned short int cs_flag_t
Definition: cs_defs.h:359
#define CS_F_HOST
Definition: cs_defs.h:583
@ k
Definition: cs_field_pointer.h:72
#define CS_FREE(_ptr)
Definition: cs_mem.h:155
#define cs_alloc_mode
Definition: cs_mem.h:187
static cs_alloc_mode_t cs_check_device_ptr(const void *ptr)
Check if a pointer is associated with a device.
Definition: cs_mem.h:737
cs_alloc_mode_t
Definition: cs_mem.h:50
@ CS_ALLOC_HOST_DEVICE_SHARED
Definition: cs_mem.h:57
static int cs_parall_n_threads(cs_lnum_t n_elements, cs_lnum_t min_thread_elements)
Compute recommended number of threads for a section.
Definition: cs_parall.h:553
Definition: cs_array.h:1098
layout
Definition: cs_mdspan.h:52
Utility template which returns "true" for a given pack. This is necessary of std::enable_if_t<> when ...
Definition: cs_defs.h:832
Utility template to check if a pack of parameters is made of integral types.
Definition: cs_defs.h:809