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;
66 constexpr
bool is_packable_set =
false;
68 template<
typename T >
69 constexpr
bool is_packable_set< SortedArray< T > > = is_packable_helper< T >::value;
73 constexpr
bool is_packable_map =
false;
75 template<
typename T_KEY,
typename T_VAL,
typename SORTED >
76 constexpr
bool is_packable_map< mapBase< T_KEY, T_VAL, SORTED > > = is_packable_helper< T_KEY >::value &&
77 is_packable_helper< T_VAL >::value;
80 template<
typename T >
81 struct is_packable_helper
83 static constexpr
bool value = is_noncontainer_type_packable< T > ||
84 is_packable_array< T > ||
85 is_packable_map< T > ||
89 template<
typename T >
90 constexpr
bool is_packable = is_packable_helper< T >::value;
92 template<
typename T >
93 constexpr
bool is_packable_by_index = is_packable_array< T >;
96 constexpr
bool is_map_packable_by_index =
false;
98 template<
typename T_KEY,
typename T_VAL,
typename SORTED >
99 constexpr
bool is_map_packable_by_index< mapBase< T_KEY, T_VAL, SORTED > > = is_packable< T_KEY > &&
100 is_packable_by_index< T_VAL >;
102 template<
typename T >
103 constexpr
bool can_memcpy_helper = std::is_arithmetic< T >::value ||
104 std::is_enum< T >::value ||
105 traits::is_tensorT< T >;
107 template<
typename T >
108 constexpr
bool can_memcpy = can_memcpy_helper< std::remove_const_t< std::remove_pointer_t< T > > >;
113 template<
bool DO_PACKING,
typename T >
114 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
119 template<
bool DO_PACKING >
122 const string & var );
125 template<
bool DO_PACKING,
typename T >
128 SortedArray< T >
const & var );
131 template<
bool DO_PACKING,
typename T >
132 typename std::enable_if< traits::is_tensorT< T >,
localIndex >::type
137 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD >
138 typename std::enable_if< is_packable< T >,
localIndex >::type
140 ArrayView< T, NDIM, USD >
const & var );
143 template<
bool DO_PACKING,
typename T >
146 ArrayOfArrays< T >
const & var );
149 template<
bool DO_PACKING,
typename T >
152 ArrayOfSets< T >
const & var );
155 template<
bool DO_PACKING,
typename MAP_TYPE >
156 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
158 MAP_TYPE
const & var );
161 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
164 std::pair< T_FIRST, T_SECOND >
const & var );
167 template<
bool DO_PACKING,
typename T >
170 InterObjectRelation< T >
const & var );
174 template<
bool DO_PACKING,
typename T >
175 typename std::enable_if< !is_packable< T >,
localIndex >::type
179 GEOS_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable." );
186 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
187 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
190 INDEX_TYPE
const length );
193 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
194 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
197 INDEX_TYPE
const length );
200 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
201 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
203 arraySlice1d< T, USD >
const & var,
204 INDEX_TYPE
const length );
207 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
208 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
210 arraySlice1d< T, USD >
const & var,
211 INDEX_TYPE
const length );
216 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD,
typename T_indices >
217 typename std::enable_if< is_packable< T >,
localIndex >::type
219 ArrayView< T, NDIM, USD >
const & var,
220 const T_indices & indices );
223 template<
bool DO_PACKING,
typename T,
typename T_indices >
225 ArrayOfArrays< T >
const & var,
226 T_indices
const & indices );
229 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
230 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
232 MAP_TYPE
const & var,
233 T_INDICES
const & indices );
236 template<
bool DO_PACKING,
typename T,
typename T_INDICES >
237 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >,
localIndex >::type
242 GEOS_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
249 template<
typename T >
250 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
261 template<
typename T >
262 typename std::enable_if< traits::is_tensorT< T >,
localIndex >::type
267 template<
typename T >
270 SortedArray< T > & var );
273 template<
typename T,
int NDIM,
typename PERMUTATION >
274 typename std::enable_if< is_packable< T >,
localIndex >::type
276 Array< T, NDIM, PERMUTATION > & var );
279 template<
typename T >
281 ArrayOfArrays< T > & var );
291 template<
typename T >
293 ArrayOfSets< T > & var );
296 template<
typename MAP_TYPE >
297 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
302 template<
typename T_FIRST,
typename T_SECOND >
305 std::pair< T_FIRST, T_SECOND > & var );
308 template<
typename T >
311 InterObjectRelation< T > & var );
314 template<
typename T >
315 typename std::enable_if< !is_packable< T >,
localIndex >::type
319 GEOS_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable." );
326 template<
typename T,
typename INDEX_TYPE >
327 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
330 INDEX_TYPE
const expectedLength );
333 template<
typename T,
typename INDEX_TYPE >
334 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
337 INDEX_TYPE
const expectedLength );
340 template<
typename T,
typename INDEX_TYPE,
int USD >
341 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
343 arraySlice1d< T, USD >
const & var,
344 INDEX_TYPE
const length );
347 template<
typename T,
typename INDEX_TYPE,
int USD >
348 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
350 arraySlice1d< T, USD >
const & var,
351 INDEX_TYPE
const length );
356 template<
typename T,
int NDIM,
int USD,
typename T_indices >
359 ArrayView< T, NDIM, USD >
const & var,
360 const T_indices & indices );
363 template<
typename T,
typename T_indices >
366 ArrayOfArrays< T > & var,
367 T_indices
const & indices );
370 template<
typename MAP_TYPE,
typename T_INDICES >
371 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
374 T_INDICES
const & indices );
377 template<
typename T,
typename T_INDICES >
378 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >,
localIndex >::type
383 GEOS_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
388 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
391 arraySlice1d< INDEX_TYPE const >
const & indices,
392 INDEX_TYPE
const length );
395 template<
typename T,
typename INDEX_TYPE >
398 arraySlice1d< INDEX_TYPE const >
const & indices,
399 INDEX_TYPE & length );
402 template<
bool DO_PACKING,
int USD >
404 SortedArray< localIndex >
const & var,
405 SortedArray< globalIndex >
const & unmappedGlobalIndices,
406 arraySlice1d< globalIndex const, USD >
const & localToGlobal );
409 template<
typename SORTED >
411 SortedArray< localIndex > & var,
412 SortedArray< globalIndex > & unmappedGlobalIndices,
413 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap,
414 bool const clearExistingSet );
417 template<
typename T >
420 ArrayOfSets< T >
const & var );
423 template<
typename T >
426 ArrayOfSets< T > & var );
430 template<
bool DO_PACKING,
int USD >
433 arraySlice1d< localIndex const, USD >
const & var,
436 arraySlice1d< globalIndex const >
const & localToGlobalMap );
439 template<
typename SORTED >
442 array1d< globalIndex > & unmappedGlobalIndices,
443 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap );
448 std::unordered_map< globalIndex, localIndex >
const & globalToLocalMap );
451 template<
typename SORTED,
int USD >
455 arraySlice1d< localIndex, USD > & var,
456 array1d< globalIndex > & unmappedGlobalIndices,
458 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap );
461 template<
bool DO_PACKING >
464 arrayView1d< localIndex const >
const & var,
465 arrayView1d< localIndex const >
const & indices,
466 arrayView1d< globalIndex const >
const & localToGlobalMap,
467 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
470 template<
bool DO_PACKING >
474 arrayView1d< localIndex const >
const & indices,
475 arrayView1d< globalIndex const >
const & localToGlobalMap );
478 template<
typename SORTED0,
typename SORTED1 >
482 arrayView1d< localIndex >
const & var,
483 array1d< localIndex >
const & indices,
484 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap,
485 mapBase< globalIndex, localIndex, SORTED1 >
const & relatedObjectGlobalToLocalMap );
489 template<
bool DO_PACKING,
typename SORTED >
492 arrayView1d< arrayView1d< localIndex const >
const >
const & var,
493 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
494 arrayView1d< localIndex const >
const & indices,
495 arrayView1d< globalIndex const >
const & localToGlobalMap,
496 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
499 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
503 arrayView1d< localIndex_array > & var,
504 array1d< localIndex > & indices,
505 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
506 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
507 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap );
510 template<
typename SORTED0 >
515 array1d< localIndex > & indices,
516 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap );
519 template<
bool DO_PACKING,
typename SORTED >
522 arrayView1d< SortedArray< localIndex >
const >
const & var,
523 mapBase<
localIndex, SortedArray< globalIndex >, SORTED >
const & unmappedGlobalIndices,
524 arrayView1d< localIndex const >
const & indices,
525 arrayView1d< globalIndex const >
const & localToGlobalMap,
526 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
529 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
535 mapBase<
localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
536 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
537 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap,
538 bool const clearFlag );
541 template<
bool DO_PACKING,
int USD0,
int USD1 >
544 arrayView2d< localIndex const, USD0 >
const & var,
545 arrayView1d< localIndex >
const & indices,
546 arraySlice1d< globalIndex const, USD1 >
const & localToGlobalMap );
549 template<
typename SORTED,
int USD >
553 arrayView2d< localIndex, USD >
const & var,
554 array1d< localIndex > & indices,
555 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap );
558 template<
bool DO_PACKING,
typename SORTED,
int USD0 >
561 arrayView2d< localIndex const, USD0 >
const & var,
562 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
563 arrayView1d< localIndex const >
const & indices,
564 arraySlice1d< globalIndex const >
const & localToGlobalMap,
565 arraySlice1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
568 template<
typename SORTED0,
typename SORTED1,
typename SORTED2,
int USD >
572 arrayView2d< localIndex, USD >
const & var,
574 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
575 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
576 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap );
579 template<
bool DO_PACKING,
typename MAP_TYPE >
580 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
584 template<
typename MAP_TYPE >
585 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
589 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
590 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
591 Pack(
buffer_unit_type * & buffer, MAP_TYPE
const & var, T_INDICES
const & packIndices );
594 template<
typename MAP_TYPE,
typename T_INDICES >
595 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
596 Unpack(
buffer_unit_type const * & buffer, MAP_TYPE &
map, T_INDICES
const & unpackIndices );
599 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
601 Pack(
buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND >
const & var );
604 template<
typename T_FIRST,
typename T_SECOND >
606 Unpack(
buffer_unit_type const * & buffer, std::pair< T_FIRST, T_SECOND > & var );
609 template<
bool DO_PACKING,
typename T >
612 InterObjectRelation< T >
const & var );
614 template<
typename ... VARPACK >
616 PackSize( VARPACK
const && ... pack )
619 return Pack< false >( junk, pack ... );
622 template<
typename ... VARPACK >
624 PackSize( VARPACK && ... pack )
627 return Pack< false >( junk, pack ... );
630 #ifdef GEOS_USE_ARRAY_BOUNDS_CHECK
632 template<
bool DO_PACKING,
typename T,
typename T_INDICES >
633 typename std::enable_if< !is_packable_by_index< T > &&
634 !is_map_packable_by_index< T >,
localIndex >::type
637 GEOS_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
642 template<
typename T,
typename T_INDICES >
643 typename std::enable_if< !is_packable_by_index< T > &&
644 !is_map_packable_by_index< T >,
localIndex >::type
647 GEOS_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
652 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
655 arraySlice1d< T >
const & var,
656 arraySlice1d< INDEX_TYPE >
const & indices,
657 INDEX_TYPE
const length );
660 template<
typename T,
typename INDEX_TYPE >
663 arraySlice1d< T > & var,
664 arraySlice1d< INDEX_TYPE >
const & indices,
665 INDEX_TYPE & length );
672 #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.