16 #ifndef GEOS_DATAREPOSITORY_BUFFEROPS_INLINE_HPP_
17 #define GEOS_DATAREPOSITORY_BUFFEROPS_INLINE_HPP_
21 #include "codingUtilities/Utilities.hpp"
22 #include "codingUtilities/traits.hpp"
23 #include "LvArray/src/limits.hpp"
24 #include "common/GEOS_RAJA_Interface.hpp"
26 #include <type_traits>
34 template<
bool DO_PACKING,
typename T >
35 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
38 localIndex const sizeOfPackedChars =
sizeof(T);
41 memcpy( buffer, &var, sizeOfPackedChars );
42 buffer += sizeOfPackedChars;
44 return sizeOfPackedChars;
47 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
48 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
51 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
53 sizeOfPackedChars += length *
sizeof(T);
56 memcpy( buffer, var, length *
sizeof(T) );
57 buffer += length *
sizeof(T);
60 return sizeOfPackedChars;
63 template<
typename T,
typename INDEX_TYPE >
64 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
68 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
71 GEOS_FMT(
"expectedLength != length: {} != {}", expectedLength, length ) );
74 memcpy( var, buffer, length *
sizeof(T) );
75 sizeOfUnpackedChars += length *
sizeof(T);
76 buffer += length *
sizeof(T);
78 return sizeOfUnpackedChars;
81 template<
bool DO_PACKING >
84 const string::size_type varSize = var.size();
85 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, varSize );
89 memcpy( buffer, var.data(), varSize );
93 sizeOfPackedChars += varSize;
94 return sizeOfPackedChars;
97 template<
bool DO_PACKING,
typename T,
typename SET >
102 const localIndex length = LvArray::integerConversion< localIndex >( var.size() );
103 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
104 for( T
const & val : var )
106 sizeOfPackedChars += Pack< DO_PACKING >( buffer, val );
108 return sizeOfPackedChars;
111 template<
bool DO_PACKING,
typename T,
int SIZE >
115 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, var.data, SIZE );
116 return sizeOfPackedChars;
119 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD >
120 typename std::enable_if< is_packable< T >,
localIndex >::type
122 ArrayView< T, NDIM, USD >
const & var )
124 localIndex sizeOfPackedChars = PackPointer< DO_PACKING >( buffer, var.dims(), NDIM );
125 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, var.strides(), NDIM );
127 T
const *
const data = var.data();
128 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, data, length );
129 return sizeOfPackedChars;
132 template<
bool DO_PACKING,
typename T >
136 stdVector< T >
const & var )
138 size_t const length = var.size();
139 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
140 for( T
const & str : var )
142 sizeOfPackedChars += Pack< DO_PACKING >( buffer, str );
144 return sizeOfPackedChars;
147 template<
bool DO_PACKING,
typename T >
149 ArrayOfArrays< T >
const & var )
152 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.size() );
155 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.sizeOfArray( a ) );
156 T
const *
const data = var[a];
157 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, data, var.sizeOfArray( a ) );
159 return sizeOfPackedChars;
162 template<
bool DO_PACKING,
typename T >
164 ArrayOfSets< T >
const & var )
167 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.size() );
170 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.sizeOfSet( a ) );
171 T
const *
const data = var[a];
172 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, data, var.sizeOfSet( a ) );
174 return sizeOfPackedChars;
177 template<
bool DO_PACKING,
typename MAP_TYPE >
178 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
181 const typename MAP_TYPE::size_type length = var.size();
182 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
183 for(
typename MAP_TYPE::const_iterator i = var.begin(); i != var.end(); ++i )
185 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->first );
186 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->second );
188 return sizeOfPackedChars;
191 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
193 Pack(
buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND >
const & var )
195 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, var.first );
196 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.second );
197 return sizeOfPackedChars;
200 template<
bool DO_PACKING,
typename T >
203 return Pack< DO_PACKING >( buffer,
static_cast< T
const &
>(var));
209 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
210 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
213 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
214 sizeOfPackedChars += length *
sizeof(T);
217 memcpy( buffer, var, length *
sizeof(T) );
218 buffer += length *
sizeof(T);
220 return sizeOfPackedChars;
223 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
224 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
227 INDEX_TYPE
const length )
230 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
231 for( INDEX_TYPE a = 0; a < length; ++a )
233 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ a ] );
236 return sizeOfPackedChars;
239 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
240 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
242 arraySlice1d< T, USD >
const & var,
243 INDEX_TYPE
const length )
245 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
246 sizeOfPackedChars += length *
sizeof(T);
249 T *
const GEOS_RESTRICT buffer_T =
reinterpret_cast< T *
>( buffer );
250 for( INDEX_TYPE i = 0; i < length; ++i )
252 buffer_T[ i ] = var[ i ];
254 buffer += length *
sizeof(T);
256 return sizeOfPackedChars;
259 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
260 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
262 arraySlice1d< T, USD >
const & var,
263 INDEX_TYPE
const length )
265 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
266 for( INDEX_TYPE a = 0; a < length; ++a )
268 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ a ] );
270 return sizeOfPackedChars;
276 template<
bool DO_PACKING,
typename T,
typename T_indices >
277 typename std::enable_if< is_packable< T >,
localIndex >::type
279 stdVector< T >
const & var,
280 const T_indices & indices )
282 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, indices.size() );
283 for(
auto a = 0; a < indices.size(); ++a )
285 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[indices[a]] );
287 return sizeOfPackedChars;
292 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD,
typename T_indices >
293 typename std::enable_if< is_packable< T >,
localIndex >::type
295 ArrayView< T, NDIM, USD >
const & var,
296 const T_indices & indices )
298 localIndex sizeOfPackedChars = PackPointer< DO_PACKING >( buffer, var.strides(), NDIM );
299 for(
localIndex a = 0; a < indices.size(); ++a )
301 LvArray::forValuesInSlice( var[ indices[ a ] ],
302 [&sizeOfPackedChars, &buffer]( T
const & value )
304 sizeOfPackedChars += Pack< DO_PACKING >( buffer, value );
308 return sizeOfPackedChars;
311 template<
bool DO_PACKING,
typename T,
typename T_indices >
313 ArrayOfArrays< T >
const & var,
314 T_indices
const & indices )
317 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
318 for(
localIndex a = 0; a < indices.size(); ++a )
320 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.sizeOfArray( indices[a] ) );
321 T
const *
const data = var[indices[a]];
322 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, data, var.sizeOfArray( indices[a] ) );
324 return sizeOfPackedChars;
327 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
328 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
330 MAP_TYPE
const & var,
331 T_INDICES
const & packIndices )
333 const typename MAP_TYPE::size_type length = var.size();
334 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
335 for(
typename MAP_TYPE::const_iterator i = var.begin(); i != var.end(); ++i )
337 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->first );
338 sizeOfPackedChars += PackByIndex< DO_PACKING >( buffer, i->second, packIndices );
340 return sizeOfPackedChars;
346 template<
typename T >
347 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
351 localIndex const sizeOfUnpackedChars =
sizeof(T);
352 memcpy( &var, buffer, sizeOfUnpackedChars );
353 buffer += sizeOfUnpackedChars;
354 return sizeOfUnpackedChars;
362 string::size_type stringsize = 0;
363 localIndex sizeOfUnpackedChars = Unpack( buffer, stringsize );
364 var.resize( stringsize );
365 memcpy( &var[0], buffer, stringsize );
366 buffer += stringsize;
367 sizeOfUnpackedChars += stringsize;
368 return sizeOfUnpackedChars;
371 template<
typename T,
int SIZE >
374 Tensor< T, SIZE > & var )
377 sizeOfUnpackedChars += UnpackPointer( buffer, var.data, SIZE );
378 return sizeOfUnpackedChars;
381 template<
typename T,
typename SET >
388 localIndex sizeOfUnpackedChars = Unpack( buffer, set_length );
392 sizeOfUnpackedChars += Unpack( buffer, temp );
395 return sizeOfUnpackedChars;
398 template<
typename T,
int NDIM,
typename PERMUTATION >
399 typename std::enable_if< is_packable< T >,
localIndex >::type
401 Array< T, NDIM, PERMUTATION > & var )
404 localIndex sizeOfUnpackedChars = UnpackPointer( buffer, dims, NDIM );
405 var.resize( NDIM, dims );
408 sizeOfUnpackedChars += UnpackPointer( buffer, strides, NDIM );
409 for(
int i=0; i<NDIM; ++i )
414 sizeOfUnpackedChars += UnpackPointer( buffer, var.data(), var.size() );
415 return sizeOfUnpackedChars;
419 template<
typename T >
420 typename std::enable_if< is_packable< T >,
localIndex >::type
422 stdVector< T > & var )
425 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
426 var.resize( length );
429 sizeOfUnpackedChars += Unpack( buffer, val );
431 return sizeOfUnpackedChars;
434 template<
typename T >
436 ArrayOfArrays< T > & var )
440 sizeOfUnpackedChars += Unpack( buffer, numOfArrays );
441 var.resize( numOfArrays );
445 sizeOfUnpackedChars += Unpack( buffer, sizeOfArray );
446 var.resizeArray( a, sizeOfArray );
448 sizeOfUnpackedChars += UnpackPointer( buffer, data, sizeOfArray );
450 return sizeOfUnpackedChars;
460 localIndex sizeOfUnpackedChars = bufferOps::Unpack( buffer, length );
462 var.resizeArray( subArrayIndex, length );
466 array1d< globalIndex > & tmp = var( subArrayIndex, a );
467 sizeOfUnpackedChars += bufferOps::Unpack( buffer, tmp );
470 return sizeOfUnpackedChars;
474 template<
typename T >
476 ArrayOfSets< T > & var )
478 ArrayOfArrays< T > varAsArray;
479 localIndex sizeOfUnpackedChars = Unpack( buffer, varAsArray );
480 var.template assimilate< parallelHostPolicy >( std::move( varAsArray ), LvArray::sortedArrayManipulation::SORTED_UNIQUE );
481 return sizeOfUnpackedChars;
484 template<
typename MAP_TYPE >
485 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
490 typename MAP_TYPE::size_type map_length;
491 localIndex sizeOfUnpackedChars = Unpack( buffer, map_length );
492 for(
typename MAP_TYPE::size_type a = 0; a < map_length; ++a )
494 typename MAP_TYPE::key_type key;
495 typename MAP_TYPE::mapped_type value;
496 sizeOfUnpackedChars += Unpack( buffer, key );
497 sizeOfUnpackedChars += Unpack( buffer, value );
498 map[key] = std::move( value );
500 return sizeOfUnpackedChars;
503 template<
typename T_FIRST,
typename T_SECOND >
505 std::pair< T_FIRST, T_SECOND > & var )
507 localIndex sizeOfUnpackedChars = Unpack( buffer, var.first );
508 sizeOfUnpackedChars += Unpack( buffer, var.second );
509 return sizeOfUnpackedChars;
512 template<
typename T >
514 InterObjectRelation< T > & var )
516 return Unpack( buffer,
static_cast< T &
>(var));
522 template<
typename T,
typename INDEX_TYPE >
523 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
526 INDEX_TYPE
const expectedLength )
529 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
531 GEOS_FMT(
"expectedLength != length: {} != {}", expectedLength, length ) );
533 memcpy( var, buffer, length *
sizeof(T) );
534 sizeOfUnpackedChars += length *
sizeof(T);
535 buffer += length *
sizeof(T);
536 return sizeOfUnpackedChars;
539 template<
typename T,
typename INDEX_TYPE >
540 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
543 INDEX_TYPE
const expectedLength )
546 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
550 for( INDEX_TYPE a=0; a<length; ++a )
552 sizeOfUnpackedChars += Unpack( buffer, var[a] );
555 return sizeOfUnpackedChars;
558 template<
typename T,
typename INDEX_TYPE,
int USD >
559 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
561 arraySlice1d< T, USD >
const & var,
562 INDEX_TYPE
const expectedLength )
565 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
569 T
const *
const GEOS_RESTRICT buffer_T =
reinterpret_cast< T
const *
>( buffer );
570 for( INDEX_TYPE i = 0; i < length; ++i )
572 var[ i ] = buffer_T[ i ];
575 buffer += length *
sizeof(T);
576 sizeOfUnpackedChars += length *
sizeof(T);
577 return sizeOfUnpackedChars;
580 template<
typename T,
typename INDEX_TYPE,
int USD >
581 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
583 arraySlice1d< T, USD >
const & var,
584 INDEX_TYPE
const expectedLength )
587 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
591 for( INDEX_TYPE a=0; a<length; ++a )
593 sizeOfUnpackedChars += Unpack( buffer, var[a] );
596 return sizeOfUnpackedChars;
602 template<
typename T,
typename T_indices >
605 stdVector< T > & var,
606 T_indices
const & indices )
610 sizeOfUnpackedChars += Unpack( buffer, numUnpackedIndices );
611 GEOS_ERROR_IF( numUnpackedIndices != indices.size(),
"number of unpacked indices does not equal expected number" );
613 for(
localIndex a = 0; a < indices.size(); ++a )
615 sizeOfUnpackedChars += Unpack( buffer, var[ indices[ a ] ] );
617 return sizeOfUnpackedChars;
620 template<
typename T,
int NDIM,
int USD,
typename T_indices >
623 ArrayView< T, NDIM, USD >
const & var,
624 const T_indices & indices )
627 localIndex sizeOfUnpackedChars = UnpackPointer( buffer, strides, NDIM );
631 LvArray::forValuesInSlice( var[ indices[ a ] ],
632 [&sizeOfUnpackedChars, &buffer] ( T & value )
634 sizeOfUnpackedChars += Unpack( buffer, value );
638 return sizeOfUnpackedChars;
641 template<
typename T,
typename T_indices >
644 ArrayOfArrays< T > & var,
645 T_indices
const & indices )
649 sizeOfUnpackedChars += Unpack( buffer, numUnpackedIndices );
650 GEOS_ERROR_IF( numUnpackedIndices != indices.size(),
"number of unpacked indices does not equal expected number" );
651 for(
localIndex a = 0; a < indices.size(); ++a )
654 sizeOfUnpackedChars += Unpack( buffer, sizeOfSubArray );
655 var.resizeArray( indices[a], sizeOfSubArray );
656 sizeOfUnpackedChars += UnpackArray( buffer, var[indices[a]], sizeOfSubArray );
658 return sizeOfUnpackedChars;
661 template<
typename MAP_TYPE,
typename T_INDICES >
662 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
665 T_INDICES
const & unpackIndices )
668 typename MAP_TYPE::size_type map_length;
669 localIndex sizeOfUnpackedChars = Unpack( buffer, map_length );
670 for(
typename MAP_TYPE::size_type a = 0; a < map_length; ++a )
672 typename MAP_TYPE::key_type key;
673 typename MAP_TYPE::mapped_type value;
674 sizeOfUnpackedChars += Unpack( buffer, key );
675 sizeOfUnpackedChars += UnpackByIndex( buffer, value, unpackIndices );
676 map[key] = std::move( value );
678 return sizeOfUnpackedChars;
681 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
684 arraySlice1d< INDEX_TYPE const >
const & indices,
685 INDEX_TYPE
const length )
687 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
691 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ indices[a] ] );
694 return sizeOfPackedChars;
697 template<
typename T,
typename INDEX_TYPE >
700 arraySlice1d< INDEX_TYPE const >
const & indices,
701 INDEX_TYPE & length )
703 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
705 for( INDEX_TYPE a=0; a<length; ++a )
707 sizeOfUnpackedChars += Unpack( buffer, var[ indices[a] ] );
710 return sizeOfUnpackedChars;
713 #ifdef GEOS_USE_BOUNDS_CHECK
715 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
716 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
718 arraySlice1d< T >
const & var,
719 INDEX_TYPE
const length )
721 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
723 for( INDEX_TYPE a=0; a<length; ++a )
725 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ a ] );
728 return sizeOfPackedChars;
731 template<
typename T,
typename INDEX_TYPE >
732 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
734 arraySlice1d< T > & var,
735 INDEX_TYPE
const expectedLength )
738 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
742 T
const *
const GEOS_RESTRICT buffer_T =
reinterpret_cast< T
const *
>( buffer );
743 for( INDEX_TYPE i = 0; i < length; ++i )
745 var[ i ] = buffer_T[ i ];
748 buffer += length *
sizeof(T);
749 sizeOfUnpackedChars += length *
sizeof(T);
751 return sizeOfUnpackedChars;
754 template<
typename T,
typename INDEX_TYPE >
755 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
757 arraySlice1d< T > & var,
758 INDEX_TYPE
const expectedLength )
761 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
765 for( INDEX_TYPE a=0; a<length; ++a )
767 sizeOfUnpackedChars += Unpack( buffer, var[a] );
770 return sizeOfUnpackedChars;
774 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
777 arraySlice1d< T >
const & var,
778 arraySlice1d< INDEX_TYPE >
const & indices,
779 INDEX_TYPE
const length )
781 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
783 for( INDEX_TYPE a=0; a<length; ++a )
785 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ indices[a] ] );
788 return sizeOfPackedChars;
792 template<
typename T,
typename INDEX_TYPE >
796 arraySlice1d< T > & var,
797 arraySlice1d< INDEX_TYPE >
const & indices,
798 INDEX_TYPE & length )
802 sizeOfUnpackedChars += Unpack( buffer, length );
804 for( INDEX_TYPE a=0; a<length; ++a )
806 sizeOfUnpackedChars += Unpack( buffer, var[ indices[a] ] );
809 return sizeOfUnpackedChars;
814 template<
bool DO_PACKING,
int USD >
816 SortedArray< localIndex >
const & var,
817 SortedArray< globalIndex >
const & unmappedGlobalIndices,
818 arraySlice1d< globalIndex const, USD >
const & localToGlobal )
820 const localIndex length = LvArray::integerConversion< localIndex >( var.size()+unmappedGlobalIndices.size());
821 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
825 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobal[ lid ] );
828 for(
globalIndex const gid : unmappedGlobalIndices )
830 sizeOfPackedChars += Pack< DO_PACKING >( buffer, gid );
834 return sizeOfPackedChars;
837 template<
typename SORTED >
840 SortedArray< localIndex > & var,
841 SortedArray< globalIndex > & unmappedGlobalIndices,
842 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap,
843 bool const clearExistingSet )
845 if( clearExistingSet )
850 localIndex sizeOfUnpackedChars = Unpack( buffer, set_length );
855 sizeOfUnpackedChars += Unpack( buffer, temp );
856 typename mapBase< globalIndex, localIndex, SORTED >::const_iterator iter = globalToLocalMap.find( temp );
857 if( iter==globalToLocalMap.end() )
859 unmappedGlobalIndices.insert( temp );
863 var.insert( iter->second );
867 return sizeOfUnpackedChars;
870 template<
bool DO_PACKING >
872 SortedArrayView< localIndex const >
const & var,
873 arrayView1d< localIndex const >
const & packList,
874 arraySlice1d< globalIndex const >
const & localToGlobal )
877 for(
auto a : packList )
879 length += var.count( a );
882 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
884 for(
localIndex a=0; a< packList.size(); ++a )
886 if( var.count( packList[ a ] ) )
888 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobal[packList[a]] );
892 return sizeOfPackedChars;
895 template<
bool DO_PACKING >
897 SortedArrayView< localIndex const >
const & var,
898 arrayView1d< localIndex const >
const & packList,
899 SortedArrayView< globalIndex const >
const & unmappedGlobalIndices,
900 arraySlice1d< globalIndex const >
const & localToGlobal )
904 array1d< localIndex > temp( var.size() );
906 for(
auto a : packList )
914 temp.resize( length );
915 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
920 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobal[temp[a]] );
923 for(
globalIndex const gid : unmappedGlobalIndices )
925 sizeOfPackedChars += Pack< DO_PACKING >( buffer, gid );
928 return sizeOfPackedChars;
931 template<
bool DO_PACKING,
typename T,
typename T_indices >
934 ArrayOfArrays< T >
const & var,
935 T_indices
const & indices )
939 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
942 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.sizeOfArray( indices[a] ) );
943 T
const *
const data = var[indices[a]];
944 sizeOfPackedChars += Pack< DO_PACKING >( buffer, data, var.sizeOfArray( indices[a] ) );
946 return sizeOfPackedChars;
950 template<
typename T,
typename T_indices >
953 ArrayOfArrays< T > & var,
954 T_indices
const & indices )
958 sizeOfUnpackedChars += Unpack( buffer, numUnpackedIndices );
960 GEOS_ERROR_IF( numUnpackedIndices!=indices.size(),
"number of unpacked indices does not equal expected number" );
965 sizeOfUnpackedChars += Unpack( buffer, sizeOfSubArray );
966 var.resizeArray( indices[a], sizeOfSubArray );
967 sizeOfUnpackedChars += Unpack( buffer, var[indices[a]], sizeOfSubArray );
971 return sizeOfUnpackedChars;
974 template<
bool DO_PACKING,
int USD >
976 arraySlice1d< localIndex const, USD >
const & var,
979 arraySlice1d< globalIndex const >
const & localToGlobalMap )
981 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
991 buffer_GI[a] = localToGlobalMap[var[a]];
995 buffer_GI[a] = unmappedGlobalIndices[a];
1002 return sizeOfPackedChars;
1005 template<
typename SORTED >
1010 array1d< globalIndex > & unmappedGlobalIndices,
1011 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap )
1014 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
1015 var.resize( length );
1016 unmappedGlobalIndices.resize( length );
1019 bool unpackedGlobalFlag =
false;
1023 sizeOfUnpackedChars += Unpack( buffer, unpackedGlobalIndex );
1025 typename mapBase< globalIndex, localIndex, SORTED >::const_iterator
1026 iter = globalToLocalMap.find( unpackedGlobalIndex );
1027 if( iter == globalToLocalMap.end() )
1030 unmappedGlobalIndices[a] = unpackedGlobalIndex;
1031 unpackedGlobalFlag =
true;
1035 var[a] = iter->second;
1038 if( !unpackedGlobalFlag )
1040 unmappedGlobalIndices.clear();
1043 return sizeOfUnpackedChars;
1050 std::unordered_map< globalIndex, localIndex >
const & globalToLocalMap )
1053 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
1054 var.resize( length );
1059 sizeOfUnpackedChars += Unpack( buffer, unpackedGlobalIndex );
1060 var[a] = globalToLocalMap.at( unpackedGlobalIndex );
1063 return sizeOfUnpackedChars;
1066 template<
typename SORTED >
1070 ArrayOfArrays< localIndex > & var,
1072 array1d< globalIndex > & unmappedGlobalIndices,
1073 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap )
1076 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
1078 var.resizeArray( subArrayIndex, length );
1079 unmappedGlobalIndices.resize( length );
1082 bool unpackedGlobalFlag =
false;
1086 sizeOfUnpackedChars += Unpack( buffer, unpackedGlobalIndex );
1088 typename mapBase< globalIndex, localIndex, SORTED >::const_iterator
1089 iter = globalToLocalMap.find( unpackedGlobalIndex );
1090 if( iter == globalToLocalMap.end() )
1093 unmappedGlobalIndices[a] = unpackedGlobalIndex;
1094 unpackedGlobalFlag =
true;
1098 var( subArrayIndex, a ) = iter->second;
1101 if( !unpackedGlobalFlag )
1103 unmappedGlobalIndices.clear();
1106 return sizeOfUnpackedChars;
1109 template<
typename SORTED,
int USD >
1113 arraySlice1d< localIndex, USD > & var,
1114 array1d< globalIndex > & unmappedGlobalIndices,
1116 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap )
1121 sizeOfUnpackedChars += Unpack( buffer, length );
1126 unmappedGlobalIndices.resize( length );
1129 bool unpackedGlobalFlag =
false;
1133 sizeOfUnpackedChars += Unpack( buffer, unpackedGlobalIndex );
1135 typename mapBase< globalIndex, localIndex, SORTED >::const_iterator
1136 iter = globalToLocalMap.find( unpackedGlobalIndex );
1137 if( iter == globalToLocalMap.end() )
1140 unmappedGlobalIndices[a] = unpackedGlobalIndex;
1141 unpackedGlobalFlag =
true;
1145 var[a] = iter->second;
1148 if( !unpackedGlobalFlag )
1150 unmappedGlobalIndices.clear();
1153 return sizeOfUnpackedChars;
1157 template<
bool DO_PACKING >
1160 arrayView1d< localIndex const >
const & var,
1161 arrayView1d< localIndex const >
const & indices,
1162 arrayView1d< globalIndex const >
const & localToGlobalMap,
1163 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1167 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1171 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1174 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1175 relatedObjectLocalToGlobalMap[var[li]] );
1179 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1184 return sizeOfPackedChars;
1187 template<
bool DO_PACKING >
1191 arrayView1d< localIndex const >
const & indices,
1192 arrayView1d< globalIndex const >
const & localToGlobalMap )
1196 sizeOfPackedChars += bufferOps::Pack< DO_PACKING >( buffer, indices.size() );
1197 for(
localIndex a = 0; a < indices.size(); ++a )
1200 sizeOfPackedChars += bufferOps::Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1202 sizeOfPackedChars += bufferOps::PackArray< DO_PACKING >( buffer,
1204 var.sizeOfArray( li ) );
1207 return sizeOfPackedChars;
1210 template<
typename SORTED0,
typename SORTED1 >
1214 arrayView1d< localIndex >
const & var,
1215 array1d< localIndex >
const & indices,
1216 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap,
1217 mapBase< globalIndex, localIndex, SORTED1 >
const & relatedObjectGlobalToLocalMap )
1220 localIndex const sizeOfIndicesPassedIn = indices.size();
1222 localIndex sizeOfUnpackedChars = Unpack( buffer, numIndicesUnpacked );
1224 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1225 GEOS_FMT(
"number of unpacked indices ({}) does not equal size of indices passed into Unpack function ({})",
1227 sizeOfIndicesPassedIn ) );
1232 sizeOfUnpackedChars += Unpack( buffer, gi );
1234 if( sizeOfIndicesPassedIn > 0 )
1237 GEOS_FMT(
"global index {} unpacked from buffer does not equal the lookup {} for localIndex {} on this rank",
1242 li = globalToLocalMap.at( gi );
1246 sizeOfUnpackedChars += Unpack( buffer, mappedGlobalIndex );
1247 if( mappedGlobalIndex != -1 )
1249 var[li] = relatedObjectGlobalToLocalMap.at( mappedGlobalIndex );
1257 return sizeOfUnpackedChars;
1260 template<
bool DO_PACKING,
typename SORTED >
1263 arrayView1d< arrayView1d< localIndex const >
const >
const & var,
1264 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1265 arrayView1d< localIndex const >
const & indices,
1266 arrayView1d< globalIndex const >
const & localToGlobalMap,
1267 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1271 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1275 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1277 typename mapBase< localIndex, array1d< globalIndex >, SORTED >::const_iterator
1278 iterUnmappedGI = unmappedGlobalIndices.find( li );
1280 array1d< globalIndex > junk;
1281 array1d< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1283 iterUnmappedGI->second;
1285 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1286 var[li].toSliceConst(),
1289 relatedObjectLocalToGlobalMap );
1292 return sizeOfPackedChars;
1295 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1299 arrayView1d< localIndex_array > & var,
1300 array1d< localIndex > & indices,
1301 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1302 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1303 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap )
1306 localIndex const sizeOfIndicesPassedIn = indices.size();
1308 localIndex sizeOfUnpackedChars = Unpack( buffer, numIndicesUnpacked );
1310 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1311 GEOS_FMT(
"number of unpacked indices ({}) does not equal size of indices passed into Unpack function ({})",
1313 sizeOfIndicesPassedIn ) );
1315 indices.resize( numIndicesUnpacked );
1320 sizeOfUnpackedChars += Unpack( buffer, gi );
1323 if( sizeOfIndicesPassedIn > 0 )
1326 GEOS_FMT(
"global index {} unpacked from buffer does not equal the lookup {} for localIndex {} on this rank",
1331 li = globalToLocalMap.at( gi );
1334 array1d< globalIndex > unmappedIndices;
1335 sizeOfUnpackedChars += Unpack( buffer,
1338 relatedObjectGlobalToLocalMap );
1340 if( unmappedIndices.size() > 0 )
1342 unmappedGlobalIndices[li] = unmappedIndices;
1345 return sizeOfUnpackedChars;
1348 template<
bool DO_PACKING,
typename SORTED >
1351 ArrayOfArraysView< localIndex const >
const & var,
1352 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1353 arrayView1d< localIndex const >
const & indices,
1354 arrayView1d< globalIndex const >
const & localToGlobalMap,
1355 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1358 array1d< globalIndex > junk;
1360 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1364 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1366 typename mapBase< localIndex, array1d< globalIndex >, SORTED >::const_iterator
1367 iterUnmappedGI = unmappedGlobalIndices.find( li );
1369 array1d< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1371 iterUnmappedGI->second;
1373 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1376 var.sizeOfArray( li ),
1377 relatedObjectLocalToGlobalMap );
1380 return sizeOfPackedChars;
1383 template<
bool DO_PACKING,
typename SORTED >
1386 ArrayOfArraysView< localIndex const >
const & var,
1387 mapBase<
localIndex, SortedArray< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1388 arrayView1d< localIndex const >
const & indices,
1389 arrayView1d< globalIndex const >
const & localToGlobalMap,
1390 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1393 SortedArray< globalIndex > junk;
1395 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1399 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1401 typename mapBase< localIndex, SortedArray< globalIndex >, SORTED >::const_iterator
1402 iterUnmappedGI = unmappedGlobalIndices.find( li );
1404 SortedArray< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1406 iterUnmappedGI->second;
1408 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1411 var.sizeOfArray( li ),
1412 relatedObjectLocalToGlobalMap );
1415 return sizeOfPackedChars;
1418 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1422 ArrayOfArrays< localIndex > & var,
1423 array1d< localIndex > & indices,
1424 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1425 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1426 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap )
1429 localIndex const sizeOfIndicesPassedIn = indices.size();
1431 localIndex sizeOfUnpackedChars = Unpack( buffer, numIndicesUnpacked );
1433 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1434 GEOS_FMT(
"number of unpacked indices ({}) does not equal size of indices passed into Unpack function ({})",
1436 sizeOfIndicesPassedIn ) );
1438 indices.resize( numIndicesUnpacked );
1439 array1d< globalIndex > unmappedIndices;
1444 sizeOfUnpackedChars += Unpack( buffer, gi );
1447 if( sizeOfIndicesPassedIn > 0 )
1450 GEOS_FMT(
"global index {} unpacked from buffer does not equal the lookup {} for localIndex {} on this rank",
1455 li = globalToLocalMap.at( gi );
1458 unmappedIndices.resize( 0 );
1459 sizeOfUnpackedChars += Unpack( buffer,
1463 relatedObjectGlobalToLocalMap );
1465 if( unmappedIndices.size() > 0 )
1467 unmappedGlobalIndices[li] = unmappedIndices;
1470 return sizeOfUnpackedChars;
1473 template<
typename SORTED0 >
1478 array1d< localIndex > & indices,
1479 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap )
1482 localIndex const sizeOfIndicesPassedIn = indices.size();
1484 localIndex sizeOfUnpackedChars = bufferOps::Unpack( buffer, numIndicesUnpacked );
1486 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1487 GEOS_FMT(
"number of unpacked indices ({}) does not equal size of indices passed into Unpack function ({})",
1489 sizeOfIndicesPassedIn ) );
1491 indices.resize( numIndicesUnpacked );
1492 array1d< globalIndex > unmappedIndices;
1497 sizeOfUnpackedChars += bufferOps::Unpack( buffer, gi );
1500 if( sizeOfIndicesPassedIn > 0 )
1503 GEOS_FMT(
"global index {} unpacked from buffer does not equal the lookup {} for localIndex {} on this rank",
1508 li = globalToLocalMap.at( gi );
1511 unmappedIndices.resize( 0 );
1512 sizeOfUnpackedChars += Unpack( buffer,
1516 return sizeOfUnpackedChars;
1520 template<
bool DO_PACKING,
typename SORTED >
1523 arrayView1d< SortedArray< localIndex >
const >
const & var,
1524 mapBase<
localIndex, SortedArray< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1525 arrayView1d< localIndex const >
const & indices,
1526 arrayView1d< globalIndex const >
const & localToGlobalMap,
1527 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1529 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, indices.size() );
1534 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1536 typename mapBase< localIndex, SortedArray< globalIndex >, SORTED >::const_iterator
1537 iterUnmappedGI = unmappedGlobalIndices.find( li );
1539 SortedArray< globalIndex > junk;
1540 SortedArray< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1542 iterUnmappedGI->second;
1544 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1547 relatedObjectLocalToGlobalMap );
1550 return sizeOfPackedChars;
1554 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1560 mapBase<
localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1561 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1562 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap,
1563 bool const clearFlag )
1566 localIndex const sizeOfIndicesPassedIn = indices.size();
1569 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1570 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1571 GEOS_FMT(
"number of unpacked indices ({}) does not equal size of indices passed into Unpack function ({})",
1573 sizeOfIndicesPassedIn ) );
1575 indices.resize( numIndicesUnpacked );
1577 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1581 sizeOfUnpackedChars += Unpack( buffer, gi );
1584 if( sizeOfIndicesPassedIn > 0 )
1587 GEOS_FMT(
"global index {} unpacked from buffer does not equal the lookup {} for localIndex {} on this rank",
1592 li = globalToLocalMap.at( gi );
1595 SortedArray< globalIndex > unmappedIndices;
1596 sizeOfUnpackedChars += Unpack( buffer,
1599 relatedObjectGlobalToLocalMap,
1602 if( unmappedIndices.size() > 0 )
1604 unmappedGlobalIndices[li].insert( unmappedIndices.data(), unmappedIndices.size() );
1607 return sizeOfUnpackedChars;
1610 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1614 ArrayOfSets< localIndex > & var,
1616 mapBase<
localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1617 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1618 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap,
1619 bool const clearFlag )
1622 localIndex const sizeOfIndicesPassedIn = indices.size();
1625 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1626 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1627 GEOS_FMT(
"number of unpacked indices ({}) does not equal size of indices passed into Unpack function ({})",
1629 sizeOfIndicesPassedIn ) );
1630 indices.resize( numIndicesUnpacked );
1634 stdVector< globalIndex > unmapped;
1637 stdVector< localIndex > mapped;
1640 stdVector< localIndex > mappedNew;
1643 array1d< localIndex > indiciesToInsert;
1644 ArrayOfSets< localIndex > valuesToInsert;
1645 indiciesToInsert.reserve( numIndicesUnpacked );
1646 valuesToInsert.reserve( numIndicesUnpacked );
1647 valuesToInsert.reserveValues( numIndicesUnpacked * 12 );
1649 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1652 sizeOfUnpackedChars += Unpack( buffer, gi );
1655 if( sizeOfIndicesPassedIn > 0 )
1658 GEOS_FMT(
"global index {} unpacked from buffer does not equal the lookup {} for localIndex {} on this rank",
1663 li = globalToLocalMap.at( gi );
1672 sizeOfUnpackedChars += Unpack( buffer, set_length );
1684 sizeOfUnpackedChars += Unpack( buffer, temp );
1685 auto iter = relatedObjectGlobalToLocalMap.find( temp );
1688 if( iter == relatedObjectGlobalToLocalMap.end() )
1690 unmapped.push_back( temp );
1696 mapped.push_back( iter->second );
1701 mapped.resize( LvArray::sortedArrayManipulation::makeSortedUnique( mapped.begin(), mapped.end() ) );
1702 std::set_difference( mapped.begin(), mapped.end(), var[li].begin(), var[li].end(), std::back_inserter( mappedNew ) );
1703 localIndex const numNewValues = LvArray::integerConversion< localIndex >( mappedNew.size() );
1706 if( numNewValues <= var.capacityOfSet( li ) - var.sizeOfSet( li ) )
1709 var.insertIntoSet( li, mappedNew.begin(), mappedNew.end() );
1714 localIndex const k = indiciesToInsert.size();
1715 indiciesToInsert.emplace_back( li );
1716 valuesToInsert.appendSet( numNewValues );
1717 valuesToInsert.insertIntoSet( k, mappedNew.begin(), mappedNew.end() );
1721 unmapped.resize( LvArray::sortedArrayManipulation::makeSortedUnique( unmapped.begin(), unmapped.end() ) );
1722 if( unmapped.size() > 0 )
1724 unmappedGlobalIndices[li].insert( unmapped.begin(), unmapped.end() );
1729 if( !indiciesToInsert.empty() )
1732 array1d< localIndex > newCapacities( var.size() );
1733 forAll< parallelHostPolicy >( var.size(), [var = var.toViewConst(), newCapacities = newCapacities.toView()](
localIndex const k )
1735 newCapacities[k] = var.capacityOfSet( k );
1739 for(
localIndex i = 0; i < indiciesToInsert.size(); ++i )
1741 newCapacities[indiciesToInsert[i]] += valuesToInsert.sizeOfSet( i );
1745 ArrayOfSets< localIndex > newVar;
1746 newVar.resizeFromCapacities< parallelHostPolicy >( var.size(), newCapacities.data() );
1749 forAll< parallelHostPolicy >( var.size(), [var = var.toViewConst(), newVar = newVar.toView()](
localIndex const k )
1751 newVar.insertIntoSet( k, var[k].begin(), var[k].end() );
1755 for(
localIndex i = 0; i < indiciesToInsert.size(); ++i )
1758 newVar.insertIntoSet( k, valuesToInsert[i].begin(), valuesToInsert[i].end() );
1762 var = std::move( newVar );
1765 return sizeOfUnpackedChars;
1769 template<
bool DO_PACKING,
int USD0,
int USD1 >
1772 arrayView2d< localIndex const, USD0 >
const & var,
1773 arrayView1d< localIndex >
const & indices,
1774 arraySlice1d< globalIndex const, USD1 >
const & localToGlobalMap )
1776 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, indices.size() );
1780 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1782 sizeOfPackedChars += PackArray< DO_PACKING >( buffer, var[li], var.size( 1 ) );
1785 return sizeOfPackedChars;
1788 template<
typename SORTED,
int USD >
1792 arrayView2d< localIndex, USD >
const & var,
1793 array1d< localIndex > & indices,
1794 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap )
1797 localIndex const sizeOfIndicesPassedIn = indices.size();
1800 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1802 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1803 GEOS_FMT(
"number of unpacked indices ({}) does not equal size of indices passed into Unpack function ({})",
1805 sizeOfIndicesPassedIn ) );
1807 indices.resize( numIndicesUnpacked );
1809 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1812 sizeOfUnpackedChars += Unpack( buffer, gi );
1815 if( sizeOfIndicesPassedIn > 0 )
1818 GEOS_FMT(
"global index {} unpacked from buffer does not equal the lookup {} for localIndex {} on this rank",
1823 li = globalToLocalMap.at( gi );
1827 sizeOfUnpackedChars += UnpackPointer( buffer, varSlice, var.size( 1 ) );
1830 return sizeOfUnpackedChars;
1834 template<
bool DO_PACKING,
typename SORTED,
int USD0 >
1837 arrayView2d< localIndex const, USD0 >
const & var,
1838 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1839 arrayView1d< localIndex const >
const & indices,
1840 arraySlice1d< globalIndex const >
const & localToGlobalMap,
1841 arraySlice1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1844 array1d< globalIndex > invalidGlobalIndices( var.size( 1 ) );
1847 invalidGlobalIndices[a] = -1;
1850 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1854 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1856 typename mapBase< localIndex, array1d< globalIndex >, SORTED >::const_iterator
1857 iterUnmappedGI = unmappedGlobalIndices.find( li );
1859 array1d< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1860 invalidGlobalIndices :
1861 iterUnmappedGI->second;
1863 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1867 relatedObjectLocalToGlobalMap );
1870 return sizeOfPackedChars;
1874 template<
typename SORTED0,
typename SORTED1,
typename SORTED2,
int USD >
1878 arrayView2d< localIndex, USD >
const & var,
1880 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1881 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1882 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap )
1885 localIndex const sizeOfIndicesPassedIn = indices.size();
1888 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1889 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1890 GEOS_FMT(
"number of unpacked indices ({}) does not equal size of indices passed into Unpack function ({})",
1892 sizeOfIndicesPassedIn ) );
1894 indices.resize( numIndicesUnpacked );
1895 array1d< globalIndex > unmappedIndices;
1897 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1900 sizeOfUnpackedChars += Unpack( buffer, gi );
1903 if( sizeOfIndicesPassedIn > 0 )
1906 GEOS_FMT(
"global index {} unpacked from buffer does not equal the lookup {} for localIndex {} on this rank",
1911 li = globalToLocalMap.at( gi );
1916 unmappedIndices.resize( 0 );
1917 sizeOfUnpackedChars += Unpack( buffer,
1921 relatedObjectGlobalToLocalMap );
1923 if( unmappedIndices.size()>0 )
1925 unmappedGlobalIndices[li] = unmappedIndices;
1930 return sizeOfUnpackedChars;
1933 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
1934 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
1935 Pack(
buffer_unit_type * & buffer, MAP_TYPE
const & var, T_INDICES
const & packIndices )
1937 typename MAP_TYPE::size_type
const length = var.size();
1938 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
1940 for(
typename MAP_TYPE::const_iterator i=var.begin(); i!=var.end(); ++i )
1942 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->first );
1943 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->second, packIndices );
1946 return sizeOfPackedChars;
1950 template<
typename MAP_TYPE,
typename T_INDICES >
1951 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
1952 Unpack(
buffer_unit_type const * & buffer, MAP_TYPE &
map, T_INDICES
const & unpackIndices )
1955 typename MAP_TYPE::size_type map_length;
1957 localIndex sizeOfUnpackedChars = Unpack( buffer, map_length );
1959 for(
typename MAP_TYPE::size_type a=0; a<map_length; ++a )
1961 typename MAP_TYPE::key_type key;
1962 typename MAP_TYPE::mapped_type value;
1963 sizeOfUnpackedChars += Unpack( buffer, key );
1964 sizeOfUnpackedChars += Unpack( buffer, value, unpackIndices );
1969 return sizeOfUnpackedChars;
#define GEOS_RESTRICT
preprocessor variable for the C99 restrict keyword for use with pointers
#define GEOS_DEBUG_VAR(...)
Mark a debug variable and silence compiler warnings.
#define GEOS_ASSERT_MSG(COND,...)
Abort execution if COND is false but only when NDEBUG is not defined..
#define GEOS_ERROR_IF(COND,...)
Conditionally raise a hard error and terminate the program.
#define GEOS_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
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).
constexpr static localIndex unmappedLocalIndexValue
A global variable for the value of a object that has not been assigned a geos::globalIndex.
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).
ArraySlice< T, 1, USD > arraySlice1d
Alias for 1D array slice.
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.