9.1
general documentation
cs_mdspan.h
Go to the documentation of this file.
1#ifndef __CS_MDSPAN_H__
2#define __CS_MDSPAN_H__
3
4/*============================================================================
5 * mdspan class and handling utilities.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*----------------------------------------------------------------------------
31 * Standard C and C++ library headers
32 *----------------------------------------------------------------------------*/
33
34#include <string.h>
35
36/*----------------------------------------------------------------------------
37 * Local headers
38 *----------------------------------------------------------------------------*/
39
40#include "base/cs_defs.h"
41
42#include "base/cs_dispatch.h"
43
44/*----------------------------------------------------------------------------*/
45
46#if defined(__cplusplus)
47
48namespace cs {
49
51enum class
52layout {
53 right,
54 left,
55 unknown
56};
57
58/*----------------------------------------------------------------------------*/
66/*----------------------------------------------------------------------------*/
67
68template<class T, int N, layout L = layout::right>
69class mdspan {
70
71/*=============================================================================
72 * Public methods
73 *============================================================================*/
74
75public:
76
77 /* Make array class friend */
78 template<class _T_, int _N_, layout _L_> friend class array;
79
80 /*--------------------------------------------------------------------------*/
84 /*--------------------------------------------------------------------------*/
85
88 _extent{0},
89 _offset{0},
90 _size(0),
91 _data(nullptr)
92 {}
93
94 /*--------------------------------------------------------------------------*/
98 /*--------------------------------------------------------------------------*/
99
100 template<typename... Args>
103 (
104 T *data,
105 Args... indices
106 )
107 {
108 check_operator_args_(indices...);
109 set_size_(indices...);
110 _data = data;
111 }
112
113 /*--------------------------------------------------------------------------*/
117 /*--------------------------------------------------------------------------*/
118
121 (
122 T *data,
123 const cs_lnum_t(&dims)[N]
124 )
125 {
126 set_size_(dims);
127 _data = data;
128 }
129
130 /*--------------------------------------------------------------------------*/
134 /*--------------------------------------------------------------------------*/
135
138 (
139 const mdspan& other
140 )
141 {
142 set_size_(other._extent);
143 _data = other._data;
144 }
145
146 /*--------------------------------------------------------------------------*/
150 /*--------------------------------------------------------------------------*/
151
154 (
155 mdspan&& other
156 )
157 : mdspan()
158 {
159 swap(*this, other);
160 }
161
162 /*--------------------------------------------------------------------------*/
166 /*--------------------------------------------------------------------------*/
167
170 {
171 _data = nullptr;
172 }
173
174 /*--------------------------------------------------------------------------*/
178 /*--------------------------------------------------------------------------*/
179
181 friend void
183 (
184 mdspan& first,
185 mdspan& second
186 )
187 {
188 using std::swap;
189
190 swap(first._extent, second._extent);
191 swap(first._offset, second._offset);
192 swap(first._size, second._size);
193 swap(first._data, second._data);
194 }
195
196 /*===========================================================================
197 * Operators
198 *==========================================================================*/
199
200 /*--------------------------------------------------------------------------*/
204 /*--------------------------------------------------------------------------*/
205
207 mdspan& operator=(const mdspan& other)
208 {
209 for (int i = 0; i < N; i++) {
210 _extent[i] = other._extent[i];
211 _offset[i] = other._offset[i];
212 }
213 _size = other._size;
214 _data = other._data;
215
216 return *this;
217 }
218
221 {
222
223 swap(*this, other);
224
225 return *this;
226 }
227
228 /*--------------------------------------------------------------------------*/
234 /*--------------------------------------------------------------------------*/
235
237 inline
238 T& operator[]
239 (
240 cs_lnum_t i
241 )
242 {
243 return _data[i];
244 }
245
246 /*--------------------------------------------------------------------------*/
252 /*--------------------------------------------------------------------------*/
253
255 inline
256 T& operator[]
257 (
258 cs_lnum_t i
259 ) const
260 {
261 return _data[i];
262 }
263
264 /*--------------------------------------------------------------------------*/
270 /*--------------------------------------------------------------------------*/
271
272 template<typename Id1>
274 inline
275 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
276 operator()
277 (
278 Id1 i
279 )
280 {
281 check_operator_args_(i);
282 return _data[i];
283 }
284
285 /*--------------------------------------------------------------------------*/
291 /*--------------------------------------------------------------------------*/
292
293 template<typename Id1>
295 inline
296 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
297 operator()
298 (
299 Id1 i
300 ) const
301 {
302 check_operator_args_(i);
303 return _data[i];
304 }
305
306 /*--------------------------------------------------------------------------*/
312 /*--------------------------------------------------------------------------*/
313
314 template<typename Id1, typename Id2>
316 inline
317 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
318 operator()
319 (
320 Id1 i,
321 Id2 j
322 )
323 {
324 check_operator_args_(i,j);
325
326 if (L == layout::right)
327 return _data[i*_offset[0] + j];
328 else if (L == layout::left)
329 return _data[i + j*_offset[1]];
330 else
331 return _data[i*_offset[0] + j*_offset[1]];
332 }
333
334 /*--------------------------------------------------------------------------*/
340 /*--------------------------------------------------------------------------*/
341
342 template<typename Id1, typename Id2>
344 inline
345 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
346 operator()
347 (
348 Id1 i,
349 Id2 j
350 ) const
351 {
352 check_operator_args_(i,j);
353
354 if (L == layout::right)
355 return _data[i*_offset[0] + j];
356 else if (L == layout::left)
357 return _data[i + j*_offset[1]];
358 else
359 return _data[i*_offset[0] + j*_offset[1]];
360 }
361
362 /*--------------------------------------------------------------------------*/
368 /*--------------------------------------------------------------------------*/
369
370 template<typename... Args>
372 inline
373 std::enable_if_t<cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
374 operator()
375 (
376 Args... indices
377 )
378 {
379 check_operator_args_(indices...);
380
381 return _data[data_offset_(indices...)];
382 }
383
384 /*--------------------------------------------------------------------------*/
390 /*--------------------------------------------------------------------------*/
391
392 template<typename... Args>
394 inline
395 std::enable_if_t<cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
396 operator()
397 (
398 Args... indices
399 ) const
400 {
401 check_operator_args_(indices...);
402
403 return _data[data_offset_(indices...)];
404 }
405
406 /*===========================================================================
407 * Getters
408 *==========================================================================*/
409
410 /*--------------------------------------------------------------------------*/
416 /*--------------------------------------------------------------------------*/
417
419 inline
422 {
423 return _size;
424 }
425
426 /*--------------------------------------------------------------------------*/
432 /*--------------------------------------------------------------------------*/
433
435 inline
437 size() const
438 {
439 return _size;
440 }
441
442 /*--------------------------------------------------------------------------*/
448 /*--------------------------------------------------------------------------*/
449
451 inline
454 (
455 int i
456 )
457 {
458 return _extent[i];
459 }
460
461 /*--------------------------------------------------------------------------*/
467 /*--------------------------------------------------------------------------*/
468
470 inline
473 (
474 int i
475 ) const
476 {
477 return _extent[i];
478 }
479
480 /*--------------------------------------------------------------------------*/
486 /*--------------------------------------------------------------------------*/
487
489 T*
491 {
492 return _data;
493 }
494
495 /*--------------------------------------------------------------------------*/
503 /*--------------------------------------------------------------------------*/
504
505 template<typename U>
507 U*
509 {
510 return reinterpret_cast<U*>(_data);
511 }
512
513 /*--------------------------------------------------------------------------*/
519 /*--------------------------------------------------------------------------*/
520
521 template<typename... Args>
523 mdspan<T, N-sizeof...(Args), L>
525 (
526 Args... indices
527 )
528 {
529 check_sub_function_args_(indices...);
530
531 constexpr int n_idx = sizeof...(Args);
532
533 cs_lnum_t dims[N - n_idx];
534
535 if (L == layout::right) {
536 for (int i = 0; i < N - n_idx; i++)
537 dims[i] = _extent[i+n_idx];
538 }
539 else if (L == layout::left) {
540 for (int i = 0; i < N - n_idx; i++)
541 dims[i] = _extent[i];
542 }
543
544 return mdspan<T,N-n_idx,L>(_data + contiguous_data_offset_(indices...), dims);
545 }
546
547 /*--------------------------------------------------------------------------*/
551 /*--------------------------------------------------------------------------*/
552
553 template<typename... Args>
555 T*
557 (
558 Args... indices
559 )
560 {
561 check_sub_function_args_(indices...);
562
563 return _data + contiguous_data_offset_(indices...);
564 }
565
566 /*--------------------------------------------------------------------------*/
570 /*--------------------------------------------------------------------------*/
571
574 (
575 T val,
576 const cs_lnum_t n_vals = -1
578 )
579 {
580 assert(n_vals <= _size);
581
582 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
583
584 // Explicit pointer, avoid passing internal member of class to the functor
585 T* data_ptr = _data;
586
588
589 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
590 data_ptr[e_id] = val;
591 });
592
593 ctx.wait();
594 }
595
596 /*--------------------------------------------------------------------------*/
602 /*--------------------------------------------------------------------------*/
603
606 (
608 T val,
609 const cs_lnum_t n_vals = -1
611 )
612 {
613 assert(n_vals <= _size);
614
615 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
616
617 // Explicit pointer, avoid passing internal member of class to the functor
618 T* data_ptr = _data;
619
620 /* No wait here since context is passed as argument */
621 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
622 data_ptr[e_id] = val;
623 });
624 }
625
626 /*--------------------------------------------------------------------------*/
630 /*--------------------------------------------------------------------------*/
631
634 (
635 T val,
636 const cs_lnum_t n_elts,
637 const cs_lnum_t elt_ids[]
638 )
639 {
640 assert(n_elts <= _size && n_elts >= 0);
641
642 if (n_elts < 1)
643 return;
644
646
647 if (elt_ids == nullptr)
648 set_to_val(ctx, val, n_elts);
649 else {
650 // Explicit pointer, avoid passing internal member of class to the functor
651 T* data_ptr = _data;
652
653 ctx.parallel_for(n_elts, CS_LAMBDA (cs_lnum_t e_id) {
654 data_ptr[elt_ids[e_id]] = val;
655 });
656 }
657
658 ctx.wait();
659 }
660
661 /*--------------------------------------------------------------------------*/
667 /*--------------------------------------------------------------------------*/
668
671 (
673 T val,
674 const cs_lnum_t n_elts,
675 const cs_lnum_t elt_ids[]
676 )
677 {
678 assert(n_elts <= _size && n_elts >= 0);
679
680 if (n_elts < 1)
681 return;
682
683 /* No wait here since context is passed as argument */
684 if (elt_ids == nullptr)
685 set_to_val(ctx, val, n_elts);
686 else {
687 // Explicit pointer, avoid passing internal member of class to the functor
688 T* data_ptr = _data;
689 ctx.parallel_for(n_elts, CS_LAMBDA (cs_lnum_t e_id) {
690 data_ptr[elt_ids[e_id]] = val;
691 });
692 }
693 }
694
695 /*--------------------------------------------------------------------------*/
699 /*--------------------------------------------------------------------------*/
700
702 void
704 {
706
707 // Explicit pointer, avoid passing internal member of class to the functor
708 T* data_ptr = _data;
709
710 ctx.parallel_for(_size, CS_LAMBDA (cs_lnum_t e_id) {
711 data_ptr[e_id] = static_cast<T>(0);
712 });
713
714 ctx.wait();
715 }
716
717 /*--------------------------------------------------------------------------*/
721 /*--------------------------------------------------------------------------*/
722
724 void
726 (
728 )
729 {
730 // Explicit pointer, avoid passing internal member of class to the functor
731 T* data_ptr = _data;
732
733 ctx.parallel_for(_size, CS_LAMBDA (cs_lnum_t e_id) {
734 data_ptr[e_id] = static_cast<T>(0);
735 });
736 }
737
738 /*--------------------------------------------------------------------------*/
743 /*--------------------------------------------------------------------------*/
744
746 void
748 (
749 T *data,
750 const cs_lnum_t n_vals = -1
752 )
753 {
754 assert(n_vals <= _size);
755
756 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
757
758 // Explicit pointer, avoid passing internal member of class to the functor
759 T* data_ptr = _data;
760
762
763 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
764 data_ptr[e_id] = data[e_id];
765 });
766
767 ctx.wait();
768 }
769
770 /*--------------------------------------------------------------------------*/
775 /*--------------------------------------------------------------------------*/
776
778 void
780 (
781 const T *data,
782 const cs_lnum_t n_vals = -1
784 )
785 {
786 assert(n_vals <= _size);
787
788 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
789
790 // Explicit pointer, avoid passing internal member of class to the functor
791 T* data_ptr = _data;
792
794
795 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
796 data_ptr[e_id] = data[e_id];
797 });
798
799 ctx.wait();
800 }
801
802 /*--------------------------------------------------------------------------*/
807 /*--------------------------------------------------------------------------*/
808
810 void
812 (
813 mdspan& other,
814 const cs_lnum_t n_vals = -1
816 )
817 {
818 assert(other._size == _size);
819
820 assert(n_vals <= _size);
821
822 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
823
824 // Explicit pointer, avoid passing internal member of class to the functor
825 T* data_ptr = _data;
826 T* o_data_ptr = other._data;
827
829
830 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
831 data_ptr[e_id] = o_data_ptr[e_id];
832 });
833
834 ctx.wait();
835 }
836
837 /*--------------------------------------------------------------------------*/
843 /*--------------------------------------------------------------------------*/
844
846 void
848 (
850 T *data,
851 const cs_lnum_t n_vals = -1
853 )
854 {
855 assert(n_vals <= _size);
856
857 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
858
859 // Explicit pointer, avoid passing internal member of class to the functor
860 T* data_ptr = _data;
861
862 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
863 data_ptr[e_id] = data[e_id];
864 });
865 }
866
867 /*--------------------------------------------------------------------------*/
873 /*--------------------------------------------------------------------------*/
874
876 void
878 (
880 const T *data,
881 const cs_lnum_t n_vals = -1
883 )
884 {
885 assert(n_vals <= _size);
886
887 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
888
889 // Explicit pointer, avoid passing internal member of class to the functor
890 T* data_ptr = _data;
891
892 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
893 data_ptr[e_id] = data[e_id];
894 });
895 }
896
897 /*--------------------------------------------------------------------------*/
902 /*--------------------------------------------------------------------------*/
903
905 void
907 (
909 mdspan &other,
910 const cs_lnum_t n_vals = -1
912 )
913 {
914 assert(other.size() == _size);
915
916 assert(n_vals <= _size);
917
918 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
919
920 // Explicit pointer, avoid passing internal member of class to the functor
921 T* data_ptr = _data;
922 T* o_data_ptr = other._data;
923
924 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
925 data_ptr[e_id] = o_data_ptr[e_id];
926 });
927 }
928
929private:
930
931 /*--------------------------------------------------------------------------*/
935 /*--------------------------------------------------------------------------*/
936
937 template<typename... Args>
939 static inline
940 void
941 check_operator_args_
942 (
943 Args...
944 )
945 {
946 static_assert(sizeof...(Args) == N, "Wrong number of arguments");
947 static_assert(sizeof...(Args) != 0, "No input arguments provided...");
948 static_assert(cs::are_integral<Args...>::value, "Non integral input arguments.");
949 }
950
951 /*--------------------------------------------------------------------------*/
955 /*--------------------------------------------------------------------------*/
956
957 template<typename... Args>
959 static inline
960 void
961 check_sub_function_args_
962 (
963 Args...
964 )
965 {
966 static_assert(sizeof...(Args) < N, "Too many input arguments.");
967 static_assert(sizeof...(Args) != 0, "No input arguments provided...");
968 static_assert(cs::are_integral<Args...>::value, "Non integral indices provided");
969 }
970
971 /*--------------------------------------------------------------------------*/
975 /*--------------------------------------------------------------------------*/
976
977 template<typename... Args>
979 inline
981 data_offset_
982 (
983 Args... indices
984 ) const
985 {
986 static_assert(sizeof...(Args) <= N && sizeof...(Args) > 0,
987 "Number of indices is out of bounds");
988
989 constexpr int n_idx = sizeof...(Args);
990
991 cs_lnum_t _indices[n_idx] = {indices...};
992
993 cs_lnum_t retval = 0;
994 for (int i = 0; i < n_idx; i++)
995 retval +=_indices[i] * _offset[i];
996
997 return retval;
998 }
999
1000 /*--------------------------------------------------------------------------*/
1004 /*--------------------------------------------------------------------------*/
1005
1006 template<typename... Args>
1008 inline
1009 cs_lnum_t
1010 contiguous_data_offset_
1011 (
1012 Args... indices
1013 ) const
1014 {
1015 static_assert(sizeof...(Args) <= N && sizeof...(Args) > 0,
1016 "Number of indices is out of bounds");
1017
1018 constexpr int n_idx = sizeof...(Args);
1019
1020 cs_lnum_t _indices[n_idx] = {indices...};
1021
1022 cs_lnum_t retval = 0;
1023 if (L == layout::right) {
1024 for (int i = 0; i < n_idx; i++)
1025 retval +=_indices[i] * _offset[i];
1026 }
1027 else if (L == layout::left) {
1028 for (int i = 0; i < n_idx; i++)
1029 retval +=_indices[i] * _offset[N-1-i];
1030 }
1031
1032 return retval;
1033 }
1034
1035 /*===========================================================================
1036 * Private methods
1037 *==========================================================================*/
1038
1039 /*--------------------------------------------------------------------------*/
1043 /*--------------------------------------------------------------------------*/
1044
1046 void
1047 set_size_
1048 (
1049 const cs_lnum_t(&dims)[N]
1050 )
1051 {
1052 _size = (N > 0) ? 1 : 0;
1053 for (int i = 0; i < N; i++) {
1054 _extent[i] = dims[i];
1055 _size *= dims[i];
1056 _offset[i] = 1;
1057 }
1058
1059 /* Compute offset values for getters */
1060
1061 if (L == layout::right) {
1062 /* Version for Layout right */
1063 for (int i = 0; i < N-1; i++) {
1064 for (int j = i + 1; j < N; j++)
1065 _offset[i] *= dims[j];
1066 }
1067 }
1068 else if (L == layout::left) {
1069 for (int i = N-1; i >= 1; i--) {
1070 for (int j = i - 1; j >= 0; j--)
1071 _offset[i] *= dims[j];
1072 }
1073 }
1074 }
1075
1076 /*--------------------------------------------------------------------------*/
1080 /*--------------------------------------------------------------------------*/
1081
1082 template<typename... Args>
1084 void
1085 set_size_
1086 (
1087 Args... dims
1088 )
1089 {
1090 check_operator_args_(dims...);
1091
1092 cs_lnum_t loc_dims[N] = {dims...};
1093
1094 set_size_(loc_dims);
1095 }
1096
1097 /*===========================================================================
1098 * Private members
1099 *==========================================================================*/
1100
1101 cs_lnum_t _extent[N];
1102 cs_lnum_t _offset[N];
1103 cs_lnum_t _size;
1104 T* _data;
1105};
1106
1107} /* namespace cs */
1108
1109template<class T, cs::layout L = cs::layout::right>
1111
1112template<class T, cs::layout L = cs::layout::right>
1114
1115template<class T, cs::layout L = cs::layout::right>
1117
1118template<class T, cs::layout L = cs::layout::right>
1120
1121template<class T, int N>
1123
1124template<class T, int N>
1126
1127#endif /* __cplusplus */
1128
1129/*--------------------------------------------------------------------------*/
1130
1131#endif /* __CS_MDSPAN_H__ */
Definition: cs_array.h:1111
Definition: cs_mdspan.h:69
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:634
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:574
CS_F_HOST_DEVICE 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:812
CS_F_HOST friend void swap(mdspan &first, mdspan &second)
Class swap operator used for assignment or move.
Definition: cs_mdspan.h:183
CS_F_HOST_DEVICE mdspan(T *data, const cs_lnum_t(&dims)[N])
Constructor method using dimensions.
Definition: cs_mdspan.h:121
CS_F_HOST_DEVICE cs_lnum_t size()
Getter for total size.
Definition: cs_mdspan.h:421
CS_F_HOST_DEVICE void zero(cs_dispatch_context &ctx)
Set all values of the data array to 0.
Definition: cs_mdspan.h:726
CS_F_HOST_DEVICE T * sub_array(Args... indices)
Get sub array based on index.
Definition: cs_mdspan.h:557
CS_F_HOST_DEVICE cs_lnum_t size() const
Getter for total size.
Definition: cs_mdspan.h:437
CS_F_HOST_DEVICE 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:780
CS_F_HOST_DEVICE cs_lnum_t extent(int i)
Getter for extent along a given dimension.
Definition: cs_mdspan.h:454
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:671
CS_F_HOST_DEVICE mdspan()
Default constructor method leading to "empty container".
Definition: cs_mdspan.h:87
CS_F_HOST_DEVICE 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:878
CS_F_HOST_DEVICE U * data()
Getter for data raw pointer with recast (casts T* to U*)
Definition: cs_mdspan.h:508
CS_F_HOST_DEVICE 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:907
CS_F_HOST_DEVICE ~mdspan()
Desstructor method using dimensions.
Definition: cs_mdspan.h:169
CS_F_HOST mdspan & operator=(mdspan &&other)
Definition: cs_mdspan.h:220
CS_F_HOST_DEVICE T * data()
Getter for data raw pointer.
Definition: cs_mdspan.h:490
CS_F_HOST_DEVICE void zero()
Set all values of the data array to 0.
Definition: cs_mdspan.h:703
CS_F_HOST_DEVICE mdspan(const mdspan &other)
Constructor method using copy. May be a shallow copy.
Definition: cs_mdspan.h:138
CS_F_HOST mdspan(mdspan &&other)
Move constructor.
Definition: cs_mdspan.h:154
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:525
CS_F_HOST_DEVICE cs_lnum_t extent(int i) const
Getter for extent along a given dimension.
Definition: cs_mdspan.h:473
CS_F_HOST_DEVICE mdspan(T *data, Args... indices)
Constructor method using only global size (works for N=1).
Definition: cs_mdspan.h:103
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:606
CS_F_HOST_DEVICE 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:848
CS_F_HOST_DEVICE 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_mdspan.h:748
CS_F_HOST mdspan & operator=(const mdspan &other)
Assignment operator.
Definition: cs_mdspan.h:207
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
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:585
#define CS_LAMBDA
Definition: cs_defs.h:594
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
#define CS_F_HOST
Definition: cs_defs.h:583
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