18 #ifndef GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
19 #define GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
23 #include "codingUtilities/Utilities.hpp"
24 #include "codingUtilities/traits.hpp"
25 #include "LvArray/src/limits.hpp"
27 #include <type_traits>
32 template<
typename T >
33 class InterObjectRelation;
38 template<
typename T >
39 struct is_packable_helper;
41 template<
typename T >
42 constexpr
bool is_noncontainer_type_packable = std::is_trivial< T >::value ||
43 std::is_arithmetic< T >::value ||
44 traits::is_tensorT< T > ||
45 traits::is_string< T >;
47 template<
typename T >
48 constexpr
bool is_container = !is_noncontainer_type_packable< T >;
51 constexpr
bool is_packable_array =
false;
53 template<
typename T,
int NDIM,
typename PERMUTATION >
54 constexpr
bool is_packable_array< Array< T, NDIM, PERMUTATION > > = is_packable_helper< T >::value;
56 template<
typename T,
int NDIM,
int USD >
57 constexpr
bool is_packable_array< ArrayView< T, NDIM, USD > > = is_packable_helper< T >::value;
59 template<
typename T,
int NDIM,
int USD >
60 constexpr
bool is_packable_array< ArraySlice< T, NDIM, USD > > = is_packable_helper< T >::value;
62 template<
typename T >
63 constexpr
bool is_packable_array< ArrayOfArrays< T > > = is_packable_helper< T >::value;
67 constexpr
bool is_packable_vector =
false;
69 template<
typename T >
70 constexpr
bool is_packable_vector< std::vector< T > > = is_packable_helper< T >::value;
74 constexpr
bool is_packable_set =
false;
76 template<
typename T >
77 constexpr
bool is_packable_set< SortedArray< T > > = is_packable_helper< T >::value;
79 template<
typename T >
80 constexpr
bool is_packable_set< set< T > > = is_packable_helper< T >::value;
84 constexpr
bool is_packable_map =
false;
86 template<
typename T_KEY,
typename T_VAL,
typename SORTED >
87 constexpr
bool is_packable_map< mapBase< T_KEY, T_VAL, SORTED > > = is_packable_helper< T_KEY >::value &&
88 is_packable_helper< T_VAL >::value;
91 template<
typename T >
92 struct is_packable_helper
94 static constexpr
bool value = is_noncontainer_type_packable< T > ||
95 is_packable_vector< T > ||
96 is_packable_array< T > ||
97 is_packable_map< T > ||
101 template<
typename T >
102 constexpr
bool is_packable = is_packable_helper< T >::value;
104 template<
typename T >
105 constexpr
bool is_packable_by_index = is_packable_array< T > || is_packable_vector< T >;
108 constexpr
bool is_map_packable_by_index =
false;
110 template<
typename T_KEY,
typename T_VAL,
typename SORTED >
111 constexpr
bool is_map_packable_by_index< mapBase< T_KEY, T_VAL, SORTED > > = is_packable< T_KEY > &&
112 is_packable_by_index< T_VAL >;
114 template<
typename T >
115 constexpr
bool can_memcpy_helper = std::is_arithmetic< T >::value ||
116 std::is_enum< T >::value ||
117 traits::is_tensorT< T >;
119 template<
typename T >
120 constexpr
bool can_memcpy = can_memcpy_helper< std::remove_const_t< std::remove_pointer_t< T > > >;
125 template<
bool DO_PACKING,
typename T >
126 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
131 template<
bool DO_PACKING >
134 const string & var );
137 template<
bool DO_PACKING,
typename T,
typename SET >
142 template<
bool DO_PACKING,
typename T >
145 SortedArray< T >
const & var )
146 {
return PackSet< DO_PACKING, T >( buffer, var ); }
148 template<
bool DO_PACKING,
typename T >
151 set< T >
const & var )
152 {
return PackSet< DO_PACKING, T >( buffer, var ); }
157 template<
bool DO_PACKING,
typename T >
158 typename std::enable_if< traits::is_tensorT< T >,
localIndex >::type
163 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD >
164 typename std::enable_if< is_packable< T >,
localIndex >::type
166 ArrayView< T, NDIM, USD >
const & var );
168 template<
bool DO_PACKING,
typename T >
171 std::vector< T >
const & var );
174 template<
bool DO_PACKING,
typename T >
177 ArrayOfArrays< T >
const & var );
180 template<
bool DO_PACKING,
typename T >
183 ArrayOfSets< T >
const & var );
186 template<
bool DO_PACKING,
typename MAP_TYPE >
187 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
189 MAP_TYPE
const & var );
192 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
195 std::pair< T_FIRST, T_SECOND >
const & var );
198 template<
bool DO_PACKING,
typename T >
201 InterObjectRelation< T >
const & var );
205 template<
bool DO_PACKING,
typename T >
206 typename std::enable_if< !is_packable< T >,
localIndex >::type
210 GEOS_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable." );
217 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
218 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
221 INDEX_TYPE
const length );
224 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
225 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
228 INDEX_TYPE
const length );
231 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
232 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
234 arraySlice1d< T, USD >
const & var,
235 INDEX_TYPE
const length );
238 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
239 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
241 arraySlice1d< T, USD >
const & var,
242 INDEX_TYPE
const length );
247 template<
bool DO_PACKING,
typename T,
typename T_indices >
248 typename std::enable_if< is_packable< T >,
localIndex >::type
250 std::vector< T >
const & var,
251 const T_indices & indices );
254 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD,
typename T_indices >
255 typename std::enable_if< is_packable< T >,
localIndex >::type
257 ArrayView< T, NDIM, USD >
const & var,
258 const T_indices & indices );
261 template<
bool DO_PACKING,
typename T,
typename T_indices >
263 ArrayOfArrays< T >
const & var,
264 T_indices
const & indices );
267 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
268 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
270 MAP_TYPE
const & var,
271 T_INDICES
const & indices );
274 template<
bool DO_PACKING,
typename T,
typename T_INDICES >
275 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >,
localIndex >::type
280 GEOS_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
287 template<
typename T >
288 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
299 template<
typename T >
300 typename std::enable_if< traits::is_tensorT< T >,
localIndex >::type
305 template<
typename T,
typename SET >
310 template<
typename T >
313 SortedArray< T > & var )
314 {
return UnpackSet< T >( buffer, var ); }
316 template<
typename T >
320 {
return UnpackSet< T >( buffer, var ); }
324 template<
typename T,
int NDIM,
typename PERMUTATION >
325 typename std::enable_if< is_packable< T >,
localIndex >::type
327 Array< T, NDIM, PERMUTATION > & var );
329 template<
typename T >
330 typename std::enable_if< is_packable< T >,
localIndex >::type
332 std::vector< T > & var );
336 template<
typename T >
338 ArrayOfArrays< T > & var );
348 template<
typename T >
350 ArrayOfSets< T > & var );
353 template<
typename MAP_TYPE >
354 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
359 template<
typename T_FIRST,
typename T_SECOND >
362 std::pair< T_FIRST, T_SECOND > & var );
365 template<
typename T >
368 InterObjectRelation< T > & var );
371 template<
typename T >
372 typename std::enable_if< !is_packable< T >,
localIndex >::type
376 GEOS_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable." );
383 template<
typename T,
typename INDEX_TYPE >
384 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
387 INDEX_TYPE
const expectedLength );
390 template<
typename T,
typename INDEX_TYPE >
391 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
394 INDEX_TYPE
const expectedLength );
397 template<
typename T,
typename INDEX_TYPE,
int USD >
398 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
400 arraySlice1d< T, USD >
const & var,
401 INDEX_TYPE
const length );
404 template<
typename T,
typename INDEX_TYPE,
int USD >
405 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
407 arraySlice1d< T, USD >
const & var,
408 INDEX_TYPE
const length );
413 template<
typename T,
typename T_indices >
416 std::vector< T > & var,
417 T_indices
const & indices );
420 template<
typename T,
int NDIM,
int USD,
typename T_indices >
423 ArrayView< T, NDIM, USD >
const & var,
424 const T_indices & indices );
427 template<
typename T,
typename T_indices >
430 ArrayOfArrays< T > & var,
431 T_indices
const & indices );
434 template<
typename MAP_TYPE,
typename T_INDICES >
435 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
438 T_INDICES
const & indices );
441 template<
typename T,
typename T_INDICES >
442 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >,
localIndex >::type
447 GEOS_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
452 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
455 arraySlice1d< INDEX_TYPE const >
const & indices,
456 INDEX_TYPE
const length );
459 template<
typename T,
typename INDEX_TYPE >
462 arraySlice1d< INDEX_TYPE const >
const & indices,
463 INDEX_TYPE & length );
466 template<
bool DO_PACKING,
int USD >
468 SortedArray< localIndex >
const & var,
469 SortedArray< globalIndex >
const & unmappedGlobalIndices,
470 arraySlice1d< globalIndex const, USD >
const & localToGlobal );
473 template<
typename SORTED >
475 SortedArray< localIndex > & var,
476 SortedArray< globalIndex > & unmappedGlobalIndices,
477 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap,
478 bool const clearExistingSet );
481 template<
typename T >
484 ArrayOfSets< T >
const & var );
487 template<
typename T >
490 ArrayOfSets< T > & var );
494 template<
bool DO_PACKING,
int USD >
497 arraySlice1d< localIndex const, USD >
const & var,
500 arraySlice1d< globalIndex const >
const & localToGlobalMap );
503 template<
typename SORTED >
506 array1d< globalIndex > & unmappedGlobalIndices,
507 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap );
512 std::unordered_map< globalIndex, localIndex >
const & globalToLocalMap );
515 template<
typename SORTED,
int USD >
519 arraySlice1d< localIndex, USD > & var,
520 array1d< globalIndex > & unmappedGlobalIndices,
522 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap );
525 template<
bool DO_PACKING >
528 arrayView1d< localIndex const >
const & var,
529 arrayView1d< localIndex const >
const & indices,
530 arrayView1d< globalIndex const >
const & localToGlobalMap,
531 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
534 template<
bool DO_PACKING >
538 arrayView1d< localIndex const >
const & indices,
539 arrayView1d< globalIndex const >
const & localToGlobalMap );
542 template<
typename SORTED0,
typename SORTED1 >
546 arrayView1d< localIndex >
const & var,
547 array1d< localIndex >
const & indices,
548 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap,
549 mapBase< globalIndex, localIndex, SORTED1 >
const & relatedObjectGlobalToLocalMap );
553 template<
bool DO_PACKING,
typename SORTED >
556 arrayView1d< arrayView1d< localIndex const >
const >
const & var,
557 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
558 arrayView1d< localIndex const >
const & indices,
559 arrayView1d< globalIndex const >
const & localToGlobalMap,
560 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
563 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
567 arrayView1d< localIndex_array > & var,
568 array1d< localIndex > & indices,
569 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
570 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
571 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap );
574 template<
typename SORTED0 >
579 array1d< localIndex > & indices,
580 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap );
583 template<
bool DO_PACKING,
typename SORTED >
586 arrayView1d< SortedArray< localIndex >
const >
const & var,
587 mapBase<
localIndex, SortedArray< globalIndex >, SORTED >
const & unmappedGlobalIndices,
588 arrayView1d< localIndex const >
const & indices,
589 arrayView1d< globalIndex const >
const & localToGlobalMap,
590 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
593 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
599 mapBase<
localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
600 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
601 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap,
602 bool const clearFlag );
605 template<
bool DO_PACKING,
int USD0,
int USD1 >
608 arrayView2d< localIndex const, USD0 >
const & var,
609 arrayView1d< localIndex >
const & indices,
610 arraySlice1d< globalIndex const, USD1 >
const & localToGlobalMap );
613 template<
typename SORTED,
int USD >
617 arrayView2d< localIndex, USD >
const & var,
618 array1d< localIndex > & indices,
619 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap );
622 template<
bool DO_PACKING,
typename SORTED,
int USD0 >
625 arrayView2d< localIndex const, USD0 >
const & var,
626 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
627 arrayView1d< localIndex const >
const & indices,
628 arraySlice1d< globalIndex const >
const & localToGlobalMap,
629 arraySlice1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
632 template<
typename SORTED0,
typename SORTED1,
typename SORTED2,
int USD >
636 arrayView2d< localIndex, USD >
const & var,
638 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
639 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
640 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap );
643 template<
bool DO_PACKING,
typename MAP_TYPE >
644 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
648 template<
typename MAP_TYPE >
649 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
653 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
654 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
655 Pack(
buffer_unit_type * & buffer, MAP_TYPE
const & var, T_INDICES
const & packIndices );
658 template<
typename MAP_TYPE,
typename T_INDICES >
659 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
660 Unpack(
buffer_unit_type const * & buffer, MAP_TYPE &
map, T_INDICES
const & unpackIndices );
663 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
665 Pack(
buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND >
const & var );
668 template<
typename T_FIRST,
typename T_SECOND >
670 Unpack(
buffer_unit_type const * & buffer, std::pair< T_FIRST, T_SECOND > & var );
673 template<
bool DO_PACKING,
typename T >
676 InterObjectRelation< T >
const & var );
678 template<
typename ... VARPACK >
680 PackSize( VARPACK
const && ... pack )
683 return Pack< false >( junk, pack ... );
686 template<
typename ... VARPACK >
688 PackSize( VARPACK && ... pack )
691 return Pack< false >( junk, pack ... );
694 #ifdef GEOS_USE_ARRAY_BOUNDS_CHECK
696 template<
bool DO_PACKING,
typename T,
typename T_INDICES >
697 typename std::enable_if< !is_packable_by_index< T > &&
698 !is_map_packable_by_index< T >,
localIndex >::type
701 GEOS_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
706 template<
typename T,
typename T_INDICES >
707 typename std::enable_if< !is_packable_by_index< T > &&
708 !is_map_packable_by_index< T >,
localIndex >::type
711 GEOS_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
716 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
719 arraySlice1d< T >
const & var,
720 arraySlice1d< INDEX_TYPE >
const & indices,
721 INDEX_TYPE
const length );
724 template<
typename T,
typename INDEX_TYPE >
727 arraySlice1d< T > & var,
728 arraySlice1d< INDEX_TYPE >
const & indices,
729 INDEX_TYPE & length );
736 #include "BufferOps_inline.hpp"
#define GEOS_RESTRICT
preprocessor variable for the C99 restrict keyword for use with pointers
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
array1d< localIndex > localIndex_array
A 1-dimensional array of geos::localIndex types.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
LvArray::ArrayOfArraysView< T, INDEX_TYPE const, CONST_SIZES, LvArray::ChaiBuffer > ArrayOfArraysView
View of array of variable-sized arrays. See LvArray::ArrayOfArraysView for details.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
signed char buffer_unit_type
Type stored in communication buffers.
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.