17 #ifndef GEOSX_DATAREPOSITORY_BUFFEROPS_HPP_ 18 #define GEOSX_DATAREPOSITORY_BUFFEROPS_HPP_ 21 #include "codingUtilities/Utilities.hpp" 22 #include "codingUtilities/static_if.hpp" 23 #include "codingUtilities/traits.hpp" 26 #include <type_traits> 31 template<
typename T >
37 template<
typename T >
38 struct is_packable_helper;
40 template<
typename T >
41 constexpr
bool is_noncontainer_type_packable = std::is_trivial< T >::value ||
42 std::is_arithmetic< T >::value ||
43 traits::is_tensorT< T > ||
44 traits::is_string< T >;
46 template<
typename T >
47 constexpr
bool is_container = !is_noncontainer_type_packable< T >;
50 constexpr
bool is_packable_array =
false;
52 template<
typename T,
int NDIM,
typename PERMUTATION >
53 constexpr
bool is_packable_array< Array< T, NDIM, PERMUTATION > > = is_packable_helper< T >::value;
55 template<
typename T,
int NDIM,
int USD >
56 constexpr
bool is_packable_array< ArrayView< T, NDIM, USD > > = is_packable_helper< T >::value;
58 template<
typename T,
int NDIM,
int USD >
59 constexpr
bool is_packable_array< ArraySlice< T, NDIM, USD > > = is_packable_helper< T >::value;
61 template<
typename T >
62 constexpr
bool is_packable_array< ArrayOfArrays< T > > = is_packable_helper< T >::value;
65 constexpr
bool is_packable_set =
false;
67 template<
typename T >
68 constexpr
bool is_packable_set< SortedArray< T > > = is_packable_helper< T >::value;
72 constexpr
bool is_packable_map =
false;
74 template<
typename T_KEY,
typename T_VAL,
typename SORTED >
75 constexpr
bool is_packable_map< mapBase< T_KEY, T_VAL, SORTED > > = is_packable_helper< T_KEY >::value &&
76 is_packable_helper< T_VAL >::value;
79 template<
typename T >
80 struct is_packable_helper
82 static constexpr
bool value = is_noncontainer_type_packable< T > ||
83 is_packable_array< T > ||
84 is_packable_map< T > ||
88 template<
typename T >
89 constexpr
bool is_packable = is_packable_helper< T >::value;
91 template<
typename T >
92 constexpr
bool is_packable_by_index = is_packable_array< T >;
95 constexpr
bool is_map_packable_by_index =
false;
97 template<
typename T_KEY,
typename T_VAL,
typename SORTED >
98 constexpr
bool is_map_packable_by_index< mapBase< T_KEY, T_VAL, SORTED > > = is_packable< T_KEY > &&
99 is_packable_by_index< T_VAL >;
101 template<
typename T >
102 constexpr
bool can_memcpy_helper = std::is_arithmetic< T >::value ||
103 std::is_enum< T >::value ||
104 traits::is_tensorT< T >;
106 template<
typename T >
107 constexpr
bool can_memcpy = can_memcpy_helper< std::remove_const_t< std::remove_pointer_t< T > > >;
112 template<
bool DO_PACKING,
typename T >
113 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
118 template<
bool DO_PACKING >
121 const string & var );
124 template<
bool DO_PACKING,
typename T >
130 template<
bool DO_PACKING,
typename T >
131 typename std::enable_if< traits::is_tensorT< T >,
localIndex >::type
136 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD >
137 typename std::enable_if< is_packable< T >,
localIndex >::type
142 template<
bool DO_PACKING,
typename T >
148 template<
bool DO_PACKING,
typename T >
154 template<
bool DO_PACKING,
typename MAP_TYPE >
155 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
157 MAP_TYPE
const & var );
160 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
163 std::pair< T_FIRST, T_SECOND >
const & var );
166 template<
bool DO_PACKING,
typename T >
173 template<
bool DO_PACKING,
typename T >
174 typename std::enable_if< !is_packable< T >,
localIndex >::type
178 GEOSX_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable." );
185 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
186 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
189 INDEX_TYPE
const length );
192 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
193 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
196 INDEX_TYPE
const length );
199 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
200 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
203 INDEX_TYPE
const length );
206 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
207 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
210 INDEX_TYPE
const length );
215 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD,
typename T_indices >
216 typename std::enable_if< is_packable< T >,
localIndex >::type
219 const T_indices & indices );
222 template<
bool DO_PACKING,
typename T,
typename T_indices >
225 T_indices
const & indices );
228 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
229 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
231 MAP_TYPE
const & var,
232 T_INDICES
const & indices );
235 template<
bool DO_PACKING,
typename T,
typename T_INDICES >
236 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >,
localIndex >::type
241 GEOSX_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
248 template<
typename T >
249 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
260 template<
typename T >
261 typename std::enable_if< traits::is_tensorT< T >,
localIndex >::type
266 template<
typename T >
272 template<
typename T,
int NDIM,
typename PERMUTATION >
273 typename std::enable_if< is_packable< T >,
localIndex >::type
278 template<
typename T >
283 template<
typename T >
288 template<
typename MAP_TYPE >
289 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
294 template<
typename T_FIRST,
typename T_SECOND >
297 std::pair< T_FIRST, T_SECOND > & var );
300 template<
typename T >
306 template<
typename T >
307 typename std::enable_if< !is_packable< T >,
localIndex >::type
311 GEOSX_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable." );
318 template<
typename T,
typename INDEX_TYPE >
319 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
322 INDEX_TYPE
const expectedLength );
325 template<
typename T,
typename INDEX_TYPE >
326 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
329 INDEX_TYPE
const expectedLength );
332 template<
typename T,
typename INDEX_TYPE,
int USD >
333 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
336 INDEX_TYPE
const length );
339 template<
typename T,
typename INDEX_TYPE,
int USD >
340 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
343 INDEX_TYPE
const length );
348 template<
typename T,
int NDIM,
int USD,
typename T_indices >
352 const T_indices & indices );
355 template<
typename T,
typename T_indices >
359 T_indices
const & indices );
362 template<
typename MAP_TYPE,
typename T_INDICES >
363 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
366 T_INDICES
const & indices );
369 template<
typename T,
typename T_INDICES >
370 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >,
localIndex >::type
375 GEOSX_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
380 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
384 INDEX_TYPE
const length );
387 template<
typename T,
typename INDEX_TYPE >
391 INDEX_TYPE & length );
394 template<
bool DO_PACKING,
int USD >
401 template<
typename SORTED >
406 bool const clearExistingSet );
409 template<
typename T >
415 template<
typename T >
422 template<
bool DO_PACKING,
int USD >
431 template<
typename SORTED >
440 std::unordered_map< globalIndex, localIndex >
const & globalToLocalMap );
443 template<
typename SORTED,
int USD >
453 template<
bool DO_PACKING >
462 template<
typename SORTED0,
typename SORTED1 >
473 template<
bool DO_PACKING,
typename SORTED >
483 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
494 template<
bool DO_PACKING,
typename SORTED >
504 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
513 bool const clearFlag );
516 template<
bool DO_PACKING,
int USD0,
int USD1 >
524 template<
typename SORTED,
int USD >
533 template<
bool DO_PACKING,
typename SORTED,
int USD0 >
543 template<
typename SORTED0,
typename SORTED1,
typename SORTED2,
int USD >
554 template<
bool DO_PACKING,
typename MAP_TYPE >
555 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
559 template<
typename MAP_TYPE >
560 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
564 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
565 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
566 Pack(
buffer_unit_type * & buffer, MAP_TYPE
const & var, T_INDICES
const & packIndices );
569 template<
typename MAP_TYPE,
typename T_INDICES >
570 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
571 Unpack(
buffer_unit_type const * & buffer, MAP_TYPE &
map, T_INDICES
const & unpackIndices );
574 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
576 Pack(
buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND >
const & var );
579 template<
typename T_FIRST,
typename T_SECOND >
581 Unpack(
buffer_unit_type const * & buffer, std::pair< T_FIRST, T_SECOND > & var );
584 template<
bool DO_PACKING,
typename T >
589 template<
typename ... VARPACK >
591 PackSize( VARPACK
const && ... pack )
594 return Pack< false >( junk, pack ... );
597 template<
typename ... VARPACK >
599 PackSize( VARPACK && ... pack )
602 return Pack< false >( junk, pack ... );
605 #ifdef GEOSX_USE_ARRAY_BOUNDS_CHECK 607 template<
bool DO_PACKING,
typename T,
typename T_INDICES >
608 typename std::enable_if< !is_packable_by_index< T > &&
609 !is_map_packable_by_index< T >,
localIndex >::type
612 GEOSX_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
617 template<
typename T,
typename T_INDICES >
618 typename std::enable_if< !is_packable_by_index< T > &&
619 !is_map_packable_by_index< T >,
localIndex >::type
622 GEOSX_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
627 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
632 INDEX_TYPE
const length );
635 template<
typename T,
typename INDEX_TYPE >
640 INDEX_TYPE & length );
647 #include "BufferOps_inline.hpp"
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
This class provides an interface similar to an std::set.
Base template for ordered and unordered maps.
Contains portable access to std::numeric_limits and functions for converting between integral types...
This class implements an array of arrays like object with contiguous storage.
This class serves to provide a "view" of a multidimensional array.
signed char buffer_unit_type
Type stored in communication buffers.
#define GEOSX_ERROR(msg)
Raise a hard error and terminate the program.
This class implements an array of sets like object with contiguous storage.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
#define GEOSX_RESTRICT
preprocessor variable for the C99 restrict keyword for use with pointers
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
#define GEOSX_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.