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 );
70 GEOS_ASSERT_MSG( length == expectedLength,
"expectedLength != length: " <<
71 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 >
100 const localIndex length = LvArray::integerConversion< localIndex >( var.size() );
101 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
102 for( T
const & val : var )
104 sizeOfPackedChars += Pack< DO_PACKING >( buffer, val );
106 return sizeOfPackedChars;
109 template<
bool DO_PACKING,
typename T,
int SIZE >
113 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, var.data, SIZE );
114 return sizeOfPackedChars;
117 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD >
118 typename std::enable_if< is_packable< T >,
localIndex >::type
120 ArrayView< T, NDIM, USD >
const & var )
122 localIndex sizeOfPackedChars = PackPointer< DO_PACKING >( buffer, var.dims(), NDIM );
123 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, var.strides(), NDIM );
125 T
const *
const data = var.data();
126 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, data, length );
127 return sizeOfPackedChars;
130 template<
bool DO_PACKING,
typename T >
132 ArrayOfArrays< T >
const & var )
135 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.size() );
138 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.sizeOfArray( a ) );
139 T
const *
const data = var[a];
140 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, data, var.sizeOfArray( a ) );
142 return sizeOfPackedChars;
145 template<
bool DO_PACKING,
typename T >
147 ArrayOfSets< T >
const & var )
150 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.size() );
153 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.sizeOfSet( a ) );
154 T
const *
const data = var[a];
155 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, data, var.sizeOfSet( a ) );
157 return sizeOfPackedChars;
160 template<
bool DO_PACKING,
typename MAP_TYPE >
161 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
164 const typename MAP_TYPE::size_type length = var.size();
165 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
166 for(
typename MAP_TYPE::const_iterator i = var.begin(); i != var.end(); ++i )
168 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->first );
169 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->second );
171 return sizeOfPackedChars;
174 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
176 Pack(
buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND >
const & var )
178 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, var.first );
179 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.second );
180 return sizeOfPackedChars;
183 template<
bool DO_PACKING,
typename T >
186 return Pack< DO_PACKING >( buffer,
static_cast< T
const &
>(var));
192 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
193 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
196 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
197 sizeOfPackedChars += length *
sizeof(T);
200 memcpy( buffer, var, length *
sizeof(T) );
201 buffer += length *
sizeof(T);
203 return sizeOfPackedChars;
206 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
207 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
210 INDEX_TYPE
const length )
213 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
214 for( INDEX_TYPE a = 0; a < length; ++a )
216 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ a ] );
219 return sizeOfPackedChars;
222 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
223 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
225 arraySlice1d< T, USD >
const & var,
226 INDEX_TYPE
const length )
228 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
229 sizeOfPackedChars += length *
sizeof(T);
232 T *
const GEOS_RESTRICT buffer_T =
reinterpret_cast< T *
>( buffer );
233 for( INDEX_TYPE i = 0; i < length; ++i )
235 buffer_T[ i ] = var[ i ];
237 buffer += length *
sizeof(T);
239 return sizeOfPackedChars;
242 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
243 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
245 arraySlice1d< T, USD >
const & var,
246 INDEX_TYPE
const length )
248 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
249 for( INDEX_TYPE a = 0; a < length; ++a )
251 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ a ] );
253 return sizeOfPackedChars;
259 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD,
typename T_indices >
260 typename std::enable_if< is_packable< T >,
localIndex >::type
262 ArrayView< T, NDIM, USD >
const & var,
263 const T_indices & indices )
265 localIndex sizeOfPackedChars = PackPointer< DO_PACKING >( buffer, var.strides(), NDIM );
266 for(
localIndex a = 0; a < indices.size(); ++a )
268 LvArray::forValuesInSlice( var[ indices[ a ] ],
269 [&sizeOfPackedChars, &buffer]( T
const & value )
271 sizeOfPackedChars += Pack< DO_PACKING >( buffer, value );
275 return sizeOfPackedChars;
278 template<
bool DO_PACKING,
typename T,
typename T_indices >
280 ArrayOfArrays< T >
const & var,
281 T_indices
const & indices )
284 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
285 for(
localIndex a = 0; a < indices.size(); ++a )
287 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.sizeOfArray( indices[a] ) );
288 T
const *
const data = var[indices[a]];
289 sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, data, var.sizeOfArray( indices[a] ) );
291 return sizeOfPackedChars;
294 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
295 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
297 MAP_TYPE
const & var,
298 T_INDICES
const & packIndices )
300 const typename MAP_TYPE::size_type length = var.size();
301 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
302 for(
typename MAP_TYPE::const_iterator i = var.begin(); i != var.end(); ++i )
304 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->first );
305 sizeOfPackedChars += PackByIndex< DO_PACKING >( buffer, i->second, packIndices );
307 return sizeOfPackedChars;
313 template<
typename T >
314 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
318 localIndex const sizeOfUnpackedChars =
sizeof(T);
319 memcpy( &var, buffer, sizeOfUnpackedChars );
320 buffer += sizeOfUnpackedChars;
321 return sizeOfUnpackedChars;
329 string::size_type stringsize = 0;
330 localIndex sizeOfUnpackedChars = Unpack( buffer, stringsize );
331 var.resize( stringsize );
332 memcpy( &var[0], buffer, stringsize );
333 buffer += stringsize;
334 sizeOfUnpackedChars += stringsize;
335 return sizeOfUnpackedChars;
338 template<
typename T,
int SIZE >
341 Tensor< T, SIZE > & var )
344 sizeOfUnpackedChars += UnpackPointer( buffer, var.data, SIZE );
345 return sizeOfUnpackedChars;
348 template<
typename T >
351 SortedArray< T > & var )
355 localIndex sizeOfUnpackedChars = Unpack( buffer, set_length );
359 sizeOfUnpackedChars += Unpack( buffer, temp );
362 return sizeOfUnpackedChars;
365 template<
typename T,
int NDIM,
typename PERMUTATION >
366 typename std::enable_if< is_packable< T >,
localIndex >::type
368 Array< T, NDIM, PERMUTATION > & var )
371 localIndex sizeOfUnpackedChars = UnpackPointer( buffer, dims, NDIM );
372 var.resize( NDIM, dims );
375 sizeOfUnpackedChars += UnpackPointer( buffer, strides, NDIM );
376 for(
int i=0; i<NDIM; ++i )
381 sizeOfUnpackedChars += UnpackPointer( buffer, var.data(), var.size() );
382 return sizeOfUnpackedChars;
385 template<
typename T >
387 ArrayOfArrays< T > & var )
391 sizeOfUnpackedChars += Unpack( buffer, numOfArrays );
392 var.resize( numOfArrays );
396 sizeOfUnpackedChars += Unpack( buffer, sizeOfArray );
397 var.resizeArray( a, sizeOfArray );
399 sizeOfUnpackedChars += UnpackPointer( buffer, data, sizeOfArray );
401 return sizeOfUnpackedChars;
411 localIndex sizeOfUnpackedChars = bufferOps::Unpack( buffer, length );
413 var.resizeArray( subArrayIndex, length );
417 array1d< globalIndex > & tmp = var( subArrayIndex, a );
418 sizeOfUnpackedChars += bufferOps::Unpack( buffer, tmp );
421 return sizeOfUnpackedChars;
425 template<
typename T >
427 ArrayOfSets< T > & var )
429 ArrayOfArrays< T > varAsArray;
430 localIndex sizeOfUnpackedChars = Unpack( buffer, varAsArray );
431 var.template assimilate< parallelHostPolicy >( std::move( varAsArray ), LvArray::sortedArrayManipulation::SORTED_UNIQUE );
432 return sizeOfUnpackedChars;
435 template<
typename MAP_TYPE >
436 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
441 typename MAP_TYPE::size_type map_length;
442 localIndex sizeOfUnpackedChars = Unpack( buffer, map_length );
443 for(
typename MAP_TYPE::size_type a = 0; a < map_length; ++a )
445 typename MAP_TYPE::key_type key;
446 typename MAP_TYPE::mapped_type value;
447 sizeOfUnpackedChars += Unpack( buffer, key );
448 sizeOfUnpackedChars += Unpack( buffer, value );
449 map[key] = std::move( value );
451 return sizeOfUnpackedChars;
454 template<
typename T_FIRST,
typename T_SECOND >
456 std::pair< T_FIRST, T_SECOND > & var )
458 localIndex sizeOfUnpackedChars = Unpack( buffer, var.first );
459 sizeOfUnpackedChars += Unpack( buffer, var.second );
460 return sizeOfUnpackedChars;
463 template<
typename T >
465 InterObjectRelation< T > & var )
467 return Unpack( buffer,
static_cast< T &
>(var));
473 template<
typename T,
typename INDEX_TYPE >
474 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
477 INDEX_TYPE
const expectedLength )
480 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
481 GEOS_ASSERT_MSG( length == expectedLength,
"expectedLength != length: " <<
482 expectedLength <<
" != " << length );
484 memcpy( var, buffer, length *
sizeof(T) );
485 sizeOfUnpackedChars += length *
sizeof(T);
486 buffer += length *
sizeof(T);
487 return sizeOfUnpackedChars;
490 template<
typename T,
typename INDEX_TYPE >
491 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
494 INDEX_TYPE
const expectedLength )
497 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
501 for( INDEX_TYPE a=0; a<length; ++a )
503 sizeOfUnpackedChars += Unpack( buffer, var[a] );
506 return sizeOfUnpackedChars;
509 template<
typename T,
typename INDEX_TYPE,
int USD >
510 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
512 arraySlice1d< T, USD >
const & var,
513 INDEX_TYPE
const expectedLength )
516 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
520 T
const *
const GEOS_RESTRICT buffer_T =
reinterpret_cast< T
const *
>( buffer );
521 for( INDEX_TYPE i = 0; i < length; ++i )
523 var[ i ] = buffer_T[ i ];
526 buffer += length *
sizeof(T);
527 sizeOfUnpackedChars += length *
sizeof(T);
528 return sizeOfUnpackedChars;
531 template<
typename T,
typename INDEX_TYPE,
int USD >
532 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
534 arraySlice1d< T, USD >
const & var,
535 INDEX_TYPE
const expectedLength )
538 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
542 for( INDEX_TYPE a=0; a<length; ++a )
544 sizeOfUnpackedChars += Unpack( buffer, var[a] );
547 return sizeOfUnpackedChars;
553 template<
typename T,
int NDIM,
int USD,
typename T_indices >
556 ArrayView< T, NDIM, USD >
const & var,
557 const T_indices & indices )
560 localIndex sizeOfUnpackedChars = UnpackPointer( buffer, strides, NDIM );
564 LvArray::forValuesInSlice( var[ indices[ a ] ],
565 [&sizeOfUnpackedChars, &buffer] ( T & value )
567 sizeOfUnpackedChars += Unpack( buffer, value );
571 return sizeOfUnpackedChars;
574 template<
typename T,
typename T_indices >
577 ArrayOfArrays< T > & var,
578 T_indices
const & indices )
582 sizeOfUnpackedChars += Unpack( buffer, numUnpackedIndices );
583 GEOS_ERROR_IF( numUnpackedIndices != indices.size(),
"number of unpacked indices does not equal expected number" );
584 for(
localIndex a = 0; a < indices.size(); ++a )
587 sizeOfUnpackedChars += Unpack( buffer, sizeOfSubArray );
588 var.resizeArray( indices[a], sizeOfSubArray );
589 sizeOfUnpackedChars += UnpackArray( buffer, var[indices[a]], sizeOfSubArray );
591 return sizeOfUnpackedChars;
594 template<
typename MAP_TYPE,
typename T_INDICES >
595 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
598 T_INDICES
const & unpackIndices )
601 typename MAP_TYPE::size_type map_length;
602 localIndex sizeOfUnpackedChars = Unpack( buffer, map_length );
603 for(
typename MAP_TYPE::size_type a = 0; a < map_length; ++a )
605 typename MAP_TYPE::key_type key;
606 typename MAP_TYPE::mapped_type value;
607 sizeOfUnpackedChars += Unpack( buffer, key );
608 sizeOfUnpackedChars += UnpackByIndex( buffer, value, unpackIndices );
609 map[key] = std::move( value );
611 return sizeOfUnpackedChars;
614 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
617 arraySlice1d< INDEX_TYPE const >
const & indices,
618 INDEX_TYPE
const length )
620 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
624 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ indices[a] ] );
627 return sizeOfPackedChars;
630 template<
typename T,
typename INDEX_TYPE >
633 arraySlice1d< INDEX_TYPE const >
const & indices,
634 INDEX_TYPE & length )
636 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
638 for( INDEX_TYPE a=0; a<length; ++a )
640 sizeOfUnpackedChars += Unpack( buffer, var[ indices[a] ] );
643 return sizeOfUnpackedChars;
646 #ifdef GEOS_USE_ARRAY_BOUNDS_CHECK
648 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
649 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
651 arraySlice1d< T >
const & var,
652 INDEX_TYPE
const length )
654 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
656 for( INDEX_TYPE a=0; a<length; ++a )
658 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ a ] );
661 return sizeOfPackedChars;
664 template<
typename T,
typename INDEX_TYPE >
665 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
667 arraySlice1d< T > & var,
668 INDEX_TYPE
const expectedLength )
671 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
675 T
const *
const GEOS_RESTRICT buffer_T =
reinterpret_cast< T
const *
>( buffer );
676 for( INDEX_TYPE i = 0; i < length; ++i )
678 var[ i ] = buffer_T[ i ];
681 buffer += length *
sizeof(T);
682 sizeOfUnpackedChars += length *
sizeof(T);
684 return sizeOfUnpackedChars;
687 template<
typename T,
typename INDEX_TYPE >
688 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
690 arraySlice1d< T > & var,
691 INDEX_TYPE
const expectedLength )
694 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
698 for( INDEX_TYPE a=0; a<length; ++a )
700 sizeOfUnpackedChars += Unpack( buffer, var[a] );
703 return sizeOfUnpackedChars;
707 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
710 arraySlice1d< T >
const & var,
711 arraySlice1d< INDEX_TYPE >
const & indices,
712 INDEX_TYPE
const length )
714 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
716 for( INDEX_TYPE a=0; a<length; ++a )
718 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ indices[a] ] );
721 return sizeOfPackedChars;
725 template<
typename T,
typename INDEX_TYPE >
729 arraySlice1d< T > & var,
730 arraySlice1d< INDEX_TYPE >
const & indices,
731 INDEX_TYPE & length )
735 sizeOfUnpackedChars += Unpack( buffer, length );
737 for( INDEX_TYPE a=0; a<length; ++a )
739 sizeOfUnpackedChars += Unpack( buffer, var[ indices[a] ] );
742 return sizeOfUnpackedChars;
747 template<
bool DO_PACKING,
int USD >
749 SortedArray< localIndex >
const & var,
750 SortedArray< globalIndex >
const & unmappedGlobalIndices,
751 arraySlice1d< globalIndex const, USD >
const & localToGlobal )
753 const localIndex length = LvArray::integerConversion< localIndex >( var.size()+unmappedGlobalIndices.size());
754 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
758 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobal[ lid ] );
761 for(
globalIndex const gid : unmappedGlobalIndices )
763 sizeOfPackedChars += Pack< DO_PACKING >( buffer, gid );
767 return sizeOfPackedChars;
770 template<
typename SORTED >
773 SortedArray< localIndex > & var,
774 SortedArray< globalIndex > & unmappedGlobalIndices,
775 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap,
776 bool const clearExistingSet )
778 if( clearExistingSet )
783 localIndex sizeOfUnpackedChars = Unpack( buffer, set_length );
788 sizeOfUnpackedChars += Unpack( buffer, temp );
789 typename mapBase< globalIndex, localIndex, SORTED >::const_iterator iter = globalToLocalMap.find( temp );
790 if( iter==globalToLocalMap.end() )
792 unmappedGlobalIndices.insert( temp );
796 var.insert( iter->second );
800 return sizeOfUnpackedChars;
803 template<
bool DO_PACKING >
805 SortedArrayView< localIndex const >
const & var,
806 arrayView1d< localIndex const >
const & packList,
807 arraySlice1d< globalIndex const >
const & localToGlobal )
810 for(
auto a : packList )
812 length += var.count( a );
815 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
817 for(
localIndex a=0; a< packList.size(); ++a )
819 if( var.count( packList[ a ] ) )
821 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobal[packList[a]] );
825 return sizeOfPackedChars;
828 template<
bool DO_PACKING >
830 SortedArrayView< localIndex const >
const & var,
831 arrayView1d< localIndex const >
const & packList,
832 SortedArrayView< globalIndex const >
const & unmappedGlobalIndices,
833 arraySlice1d< globalIndex const >
const & localToGlobal )
837 array1d< localIndex > temp( var.size() );
839 for(
auto a : packList )
847 temp.resize( length );
848 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
853 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobal[temp[a]] );
856 for(
globalIndex const gid : unmappedGlobalIndices )
858 sizeOfPackedChars += Pack< DO_PACKING >( buffer, gid );
861 return sizeOfPackedChars;
864 template<
bool DO_PACKING,
typename T,
typename T_indices >
867 ArrayOfArrays< T >
const & var,
868 T_indices
const & indices )
872 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
875 sizeOfPackedChars += Pack< DO_PACKING >( buffer, var.sizeOfArray( indices[a] ) );
876 T
const *
const data = var[indices[a]];
877 sizeOfPackedChars += Pack< DO_PACKING >( buffer, data, var.sizeOfArray( indices[a] ) );
879 return sizeOfPackedChars;
883 template<
typename T,
typename T_indices >
886 ArrayOfArrays< T > & var,
887 T_indices
const & indices )
891 sizeOfUnpackedChars += Unpack( buffer, numUnpackedIndices );
893 GEOS_ERROR_IF( numUnpackedIndices!=indices.size(),
"number of unpacked indices does not equal expected number" );
898 sizeOfUnpackedChars += Unpack( buffer, sizeOfSubArray );
899 var.resizeArray( indices[a], sizeOfSubArray );
900 sizeOfUnpackedChars += Unpack( buffer, var[indices[a]], sizeOfSubArray );
904 return sizeOfUnpackedChars;
907 template<
bool DO_PACKING,
int USD >
909 arraySlice1d< localIndex const, USD >
const & var,
912 arraySlice1d< globalIndex const >
const & localToGlobalMap )
914 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
924 buffer_GI[a] = localToGlobalMap[var[a]];
928 buffer_GI[a] = unmappedGlobalIndices[a];
935 return sizeOfPackedChars;
938 template<
typename SORTED >
943 array1d< globalIndex > & unmappedGlobalIndices,
944 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap )
947 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
948 var.resize( length );
949 unmappedGlobalIndices.resize( length );
952 bool unpackedGlobalFlag =
false;
956 sizeOfUnpackedChars += Unpack( buffer, unpackedGlobalIndex );
958 typename mapBase< globalIndex, localIndex, SORTED >::const_iterator
959 iter = globalToLocalMap.find( unpackedGlobalIndex );
960 if( iter == globalToLocalMap.end() )
963 unmappedGlobalIndices[a] = unpackedGlobalIndex;
964 unpackedGlobalFlag =
true;
968 var[a] = iter->second;
971 if( !unpackedGlobalFlag )
973 unmappedGlobalIndices.clear();
976 return sizeOfUnpackedChars;
983 std::unordered_map< globalIndex, localIndex >
const & globalToLocalMap )
986 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
987 var.resize( length );
992 sizeOfUnpackedChars += Unpack( buffer, unpackedGlobalIndex );
993 var[a] = globalToLocalMap.at( unpackedGlobalIndex );
996 return sizeOfUnpackedChars;
999 template<
typename SORTED >
1003 ArrayOfArrays< localIndex > & var,
1005 array1d< globalIndex > & unmappedGlobalIndices,
1006 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap )
1009 localIndex sizeOfUnpackedChars = Unpack( buffer, length );
1011 var.resizeArray( subArrayIndex, length );
1012 unmappedGlobalIndices.resize( length );
1015 bool unpackedGlobalFlag =
false;
1019 sizeOfUnpackedChars += Unpack( buffer, unpackedGlobalIndex );
1021 typename mapBase< globalIndex, localIndex, SORTED >::const_iterator
1022 iter = globalToLocalMap.find( unpackedGlobalIndex );
1023 if( iter == globalToLocalMap.end() )
1026 unmappedGlobalIndices[a] = unpackedGlobalIndex;
1027 unpackedGlobalFlag =
true;
1031 var( subArrayIndex, a ) = iter->second;
1034 if( !unpackedGlobalFlag )
1036 unmappedGlobalIndices.clear();
1039 return sizeOfUnpackedChars;
1042 template<
typename SORTED,
int USD >
1046 arraySlice1d< localIndex, USD > & var,
1047 array1d< globalIndex > & unmappedGlobalIndices,
1049 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap )
1054 sizeOfUnpackedChars += Unpack( buffer, length );
1059 unmappedGlobalIndices.resize( length );
1062 bool unpackedGlobalFlag =
false;
1066 sizeOfUnpackedChars += Unpack( buffer, unpackedGlobalIndex );
1068 typename mapBase< globalIndex, localIndex, SORTED >::const_iterator
1069 iter = globalToLocalMap.find( unpackedGlobalIndex );
1070 if( iter == globalToLocalMap.end() )
1073 unmappedGlobalIndices[a] = unpackedGlobalIndex;
1074 unpackedGlobalFlag =
true;
1078 var[a] = iter->second;
1081 if( !unpackedGlobalFlag )
1083 unmappedGlobalIndices.clear();
1086 return sizeOfUnpackedChars;
1090 template<
bool DO_PACKING >
1093 arrayView1d< localIndex const >
const & var,
1094 arrayView1d< localIndex const >
const & indices,
1095 arrayView1d< globalIndex const >
const & localToGlobalMap,
1096 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1100 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1104 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1107 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1108 relatedObjectLocalToGlobalMap[var[li]] );
1112 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1117 return sizeOfPackedChars;
1120 template<
bool DO_PACKING >
1124 arrayView1d< localIndex const >
const & indices,
1125 arrayView1d< globalIndex const >
const & localToGlobalMap )
1129 sizeOfPackedChars += bufferOps::Pack< DO_PACKING >( buffer, indices.size() );
1130 for(
localIndex a = 0; a < indices.size(); ++a )
1133 sizeOfPackedChars += bufferOps::Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1135 sizeOfPackedChars += bufferOps::PackArray< DO_PACKING >( buffer,
1137 var.sizeOfArray( li ) );
1140 return sizeOfPackedChars;
1143 template<
typename SORTED0,
typename SORTED1 >
1147 arrayView1d< localIndex >
const & var,
1148 array1d< localIndex >
const & indices,
1149 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap,
1150 mapBase< globalIndex, localIndex, SORTED1 >
const & relatedObjectGlobalToLocalMap )
1153 localIndex const sizeOfIndicesPassedIn = indices.size();
1155 localIndex sizeOfUnpackedChars = Unpack( buffer, numIndicesUnpacked );
1157 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1158 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1159 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1164 sizeOfUnpackedChars += Unpack( buffer, gi );
1166 if( sizeOfIndicesPassedIn > 0 )
1169 "global index "<<gi<<
" unpacked from buffer does not equal the lookup "
1170 <<li<<
" for localIndex "<<li<<
" on this rank" );
1174 li = globalToLocalMap.at( gi );
1178 sizeOfUnpackedChars += Unpack( buffer, mappedGlobalIndex );
1179 if( mappedGlobalIndex != -1 )
1181 var[li] = relatedObjectGlobalToLocalMap.at( mappedGlobalIndex );
1189 return sizeOfUnpackedChars;
1192 template<
bool DO_PACKING,
typename SORTED >
1195 arrayView1d< arrayView1d< localIndex const >
const >
const & var,
1196 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1197 arrayView1d< localIndex const >
const & indices,
1198 arrayView1d< globalIndex const >
const & localToGlobalMap,
1199 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1203 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1207 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1209 typename mapBase< localIndex, array1d< globalIndex >, SORTED >::const_iterator
1210 iterUnmappedGI = unmappedGlobalIndices.find( li );
1212 array1d< globalIndex > junk;
1213 array1d< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1215 iterUnmappedGI->second;
1217 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1218 var[li].toSliceConst(),
1221 relatedObjectLocalToGlobalMap );
1224 return sizeOfPackedChars;
1227 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1231 arrayView1d< localIndex_array > & var,
1232 array1d< localIndex > & indices,
1233 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1234 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1235 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap )
1238 localIndex const sizeOfIndicesPassedIn = indices.size();
1240 localIndex sizeOfUnpackedChars = Unpack( buffer, numIndicesUnpacked );
1242 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1243 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1244 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1246 indices.resize( numIndicesUnpacked );
1251 sizeOfUnpackedChars += Unpack( buffer, gi );
1254 if( sizeOfIndicesPassedIn > 0 )
1257 "global index "<<gi<<
" unpacked from buffer does not equal the lookup "
1258 <<li<<
" for localIndex "<<li<<
" on this rank" );
1262 li = globalToLocalMap.at( gi );
1265 array1d< globalIndex > unmappedIndices;
1266 sizeOfUnpackedChars += Unpack( buffer,
1269 relatedObjectGlobalToLocalMap );
1271 if( unmappedIndices.size() > 0 )
1273 unmappedGlobalIndices[li] = unmappedIndices;
1276 return sizeOfUnpackedChars;
1279 template<
bool DO_PACKING,
typename SORTED >
1282 ArrayOfArraysView< localIndex const >
const & var,
1283 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1284 arrayView1d< localIndex const >
const & indices,
1285 arrayView1d< globalIndex const >
const & localToGlobalMap,
1286 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1289 array1d< globalIndex > junk;
1291 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1295 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1297 typename mapBase< localIndex, array1d< globalIndex >, SORTED >::const_iterator
1298 iterUnmappedGI = unmappedGlobalIndices.find( li );
1300 array1d< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1302 iterUnmappedGI->second;
1304 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1307 var.sizeOfArray( li ),
1308 relatedObjectLocalToGlobalMap );
1311 return sizeOfPackedChars;
1314 template<
bool DO_PACKING,
typename SORTED >
1317 ArrayOfArraysView< localIndex const >
const & var,
1318 mapBase<
localIndex, SortedArray< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1319 arrayView1d< localIndex const >
const & indices,
1320 arrayView1d< globalIndex const >
const & localToGlobalMap,
1321 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1324 SortedArray< globalIndex > junk;
1326 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1330 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1332 typename mapBase< localIndex, SortedArray< globalIndex >, SORTED >::const_iterator
1333 iterUnmappedGI = unmappedGlobalIndices.find( li );
1335 SortedArray< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1337 iterUnmappedGI->second;
1339 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1342 var.sizeOfArray( li ),
1343 relatedObjectLocalToGlobalMap );
1346 return sizeOfPackedChars;
1349 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1353 ArrayOfArrays< localIndex > & var,
1354 array1d< localIndex > & indices,
1355 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1356 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1357 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap )
1360 localIndex const sizeOfIndicesPassedIn = indices.size();
1362 localIndex sizeOfUnpackedChars = Unpack( buffer, numIndicesUnpacked );
1364 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1365 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1366 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1368 indices.resize( numIndicesUnpacked );
1369 array1d< globalIndex > unmappedIndices;
1374 sizeOfUnpackedChars += Unpack( buffer, gi );
1377 if( sizeOfIndicesPassedIn > 0 )
1380 "global index "<<gi<<
" unpacked from buffer does not equal the lookup "
1381 <<li<<
" for localIndex "<<li<<
" on this rank" );
1385 li = globalToLocalMap.at( gi );
1388 unmappedIndices.resize( 0 );
1389 sizeOfUnpackedChars += Unpack( buffer,
1393 relatedObjectGlobalToLocalMap );
1395 if( unmappedIndices.size() > 0 )
1397 unmappedGlobalIndices[li] = unmappedIndices;
1400 return sizeOfUnpackedChars;
1403 template<
typename SORTED0 >
1408 array1d< localIndex > & indices,
1409 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap )
1412 localIndex const sizeOfIndicesPassedIn = indices.size();
1414 localIndex sizeOfUnpackedChars = bufferOps::Unpack( buffer, numIndicesUnpacked );
1416 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1417 "number of unpacked indices(" << numIndicesUnpacked <<
") does not equal size of "
1418 "indices passed into Unpack function(" << sizeOfIndicesPassedIn );
1420 indices.resize( numIndicesUnpacked );
1421 array1d< globalIndex > unmappedIndices;
1426 sizeOfUnpackedChars += bufferOps::Unpack( buffer, gi );
1429 if( sizeOfIndicesPassedIn > 0 )
1432 "global index " << gi <<
" unpacked from buffer does not equal the lookup "
1433 << li <<
" for localIndex " << li <<
" on this rank" );
1437 li = globalToLocalMap.at( gi );
1440 unmappedIndices.resize( 0 );
1441 sizeOfUnpackedChars += Unpack( buffer,
1445 return sizeOfUnpackedChars;
1449 template<
bool DO_PACKING,
typename SORTED >
1452 arrayView1d< SortedArray< localIndex >
const >
const & var,
1453 mapBase<
localIndex, SortedArray< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1454 arrayView1d< localIndex const >
const & indices,
1455 arrayView1d< globalIndex const >
const & localToGlobalMap,
1456 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1458 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, indices.size() );
1463 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1465 typename mapBase< localIndex, SortedArray< globalIndex >, SORTED >::const_iterator
1466 iterUnmappedGI = unmappedGlobalIndices.find( li );
1468 SortedArray< globalIndex > junk;
1469 SortedArray< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1471 iterUnmappedGI->second;
1473 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1476 relatedObjectLocalToGlobalMap );
1479 return sizeOfPackedChars;
1483 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1489 mapBase<
localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1490 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1491 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap,
1492 bool const clearFlag )
1495 localIndex const sizeOfIndicesPassedIn = indices.size();
1498 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1499 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1500 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1501 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1503 indices.resize( numIndicesUnpacked );
1505 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1509 sizeOfUnpackedChars += Unpack( buffer, gi );
1512 if( sizeOfIndicesPassedIn > 0 )
1515 "global index "<<gi<<
" unpacked from buffer does equal the lookup "
1516 <<li<<
" for localIndex "<<li<<
" on this rank" );
1520 li = globalToLocalMap.at( gi );
1523 SortedArray< globalIndex > unmappedIndices;
1524 sizeOfUnpackedChars += Unpack( buffer,
1527 relatedObjectGlobalToLocalMap,
1530 if( unmappedIndices.size() > 0 )
1532 unmappedGlobalIndices[li].insert( unmappedIndices.data(), unmappedIndices.size() );
1535 return sizeOfUnpackedChars;
1538 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1542 ArrayOfSets< localIndex > & var,
1544 mapBase<
localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1545 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1546 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap,
1547 bool const clearFlag )
1550 localIndex const sizeOfIndicesPassedIn = indices.size();
1553 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1554 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1555 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1556 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1558 indices.resize( numIndicesUnpacked );
1562 std::vector< globalIndex > unmapped;
1565 std::vector< localIndex > mapped;
1568 std::vector< localIndex > mappedNew;
1571 array1d< localIndex > indiciesToInsert;
1572 ArrayOfSets< localIndex > valuesToInsert;
1573 indiciesToInsert.reserve( numIndicesUnpacked );
1574 valuesToInsert.reserve( numIndicesUnpacked );
1575 valuesToInsert.reserveValues( numIndicesUnpacked * 12 );
1577 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1580 sizeOfUnpackedChars += Unpack( buffer, gi );
1583 if( sizeOfIndicesPassedIn > 0 )
1586 "global index "<<gi<<
" unpacked from buffer does equal the lookup "
1587 <<li<<
" for localIndex "<<li<<
" on this rank" );
1591 li = globalToLocalMap.at( gi );
1600 sizeOfUnpackedChars += Unpack( buffer, set_length );
1612 sizeOfUnpackedChars += Unpack( buffer, temp );
1613 auto iter = relatedObjectGlobalToLocalMap.find( temp );
1616 if( iter == relatedObjectGlobalToLocalMap.end() )
1618 unmapped.push_back( temp );
1624 mapped.push_back( iter->second );
1629 mapped.resize( LvArray::sortedArrayManipulation::makeSortedUnique( mapped.begin(), mapped.end() ) );
1630 std::set_difference( mapped.begin(), mapped.end(), var[li].begin(), var[li].end(), std::back_inserter( mappedNew ) );
1631 localIndex const numNewValues = LvArray::integerConversion< localIndex >( mappedNew.size() );
1634 if( numNewValues <= var.capacityOfSet( li ) - var.sizeOfSet( li ) )
1637 var.insertIntoSet( li, mappedNew.begin(), mappedNew.end() );
1642 localIndex const k = indiciesToInsert.size();
1643 indiciesToInsert.emplace_back( li );
1644 valuesToInsert.appendSet( numNewValues );
1645 valuesToInsert.insertIntoSet( k, mappedNew.begin(), mappedNew.end() );
1649 unmapped.resize( LvArray::sortedArrayManipulation::makeSortedUnique( unmapped.begin(), unmapped.end() ) );
1650 if( unmapped.size() > 0 )
1652 unmappedGlobalIndices[li].insert( unmapped.begin(), unmapped.end() );
1657 if( !indiciesToInsert.empty() )
1660 array1d< localIndex > newCapacities( var.size() );
1661 forAll< parallelHostPolicy >( var.size(), [var = var.toViewConst(), newCapacities = newCapacities.toView()](
localIndex const k )
1663 newCapacities[k] = var.capacityOfSet( k );
1667 for(
localIndex i = 0; i < indiciesToInsert.size(); ++i )
1669 newCapacities[indiciesToInsert[i]] += valuesToInsert.sizeOfSet( i );
1673 ArrayOfSets< localIndex > newVar;
1674 newVar.resizeFromCapacities< parallelHostPolicy >( var.size(), newCapacities.data() );
1677 forAll< parallelHostPolicy >( var.size(), [var = var.toViewConst(), newVar = newVar.toView()](
localIndex const k )
1679 newVar.insertIntoSet( k, var[k].begin(), var[k].end() );
1683 for(
localIndex i = 0; i < indiciesToInsert.size(); ++i )
1686 newVar.insertIntoSet( k, valuesToInsert[i].begin(), valuesToInsert[i].end() );
1690 var = std::move( newVar );
1693 return sizeOfUnpackedChars;
1697 template<
bool DO_PACKING,
int USD0,
int USD1 >
1700 arrayView2d< localIndex const, USD0 >
const & var,
1701 arrayView1d< localIndex >
const & indices,
1702 arraySlice1d< globalIndex const, USD1 >
const & localToGlobalMap )
1704 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, indices.size() );
1708 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1710 sizeOfPackedChars += PackArray< DO_PACKING >( buffer, var[li], var.size( 1 ) );
1713 return sizeOfPackedChars;
1716 template<
typename SORTED,
int USD >
1720 arrayView2d< localIndex, USD >
const & var,
1721 array1d< localIndex > & indices,
1722 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap )
1725 localIndex const sizeOfIndicesPassedIn = indices.size();
1728 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1730 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1731 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1732 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1734 indices.resize( numIndicesUnpacked );
1736 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1739 sizeOfUnpackedChars += Unpack( buffer, gi );
1742 if( sizeOfIndicesPassedIn > 0 )
1745 "global index "<<gi<<
" unpacked from buffer does equal the lookup "
1746 <<li<<
" for localIndex "<<li<<
" on this rank" );
1750 li = globalToLocalMap.at( gi );
1754 sizeOfUnpackedChars += UnpackPointer( buffer, varSlice, var.size( 1 ) );
1757 return sizeOfUnpackedChars;
1761 template<
bool DO_PACKING,
typename SORTED,
int USD0 >
1764 arrayView2d< localIndex const, USD0 >
const & var,
1765 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1766 arrayView1d< localIndex const >
const & indices,
1767 arraySlice1d< globalIndex const >
const & localToGlobalMap,
1768 arraySlice1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1771 array1d< globalIndex > invalidGlobalIndices( var.size( 1 ) );
1774 invalidGlobalIndices[a] = -1;
1777 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1781 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1783 typename mapBase< localIndex, array1d< globalIndex >, SORTED >::const_iterator
1784 iterUnmappedGI = unmappedGlobalIndices.find( li );
1786 array1d< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1787 invalidGlobalIndices :
1788 iterUnmappedGI->second;
1790 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1794 relatedObjectLocalToGlobalMap );
1797 return sizeOfPackedChars;
1801 template<
typename SORTED0,
typename SORTED1,
typename SORTED2,
int USD >
1805 arrayView2d< localIndex, USD >
const & var,
1807 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1808 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1809 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap )
1812 localIndex const sizeOfIndicesPassedIn = indices.size();
1815 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1816 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1817 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1818 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1820 indices.resize( numIndicesUnpacked );
1821 array1d< globalIndex > unmappedIndices;
1823 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1826 sizeOfUnpackedChars += Unpack( buffer, gi );
1829 if( sizeOfIndicesPassedIn > 0 )
1832 "global index "<<gi<<
" unpacked from buffer does equal the lookup "
1833 <<li<<
" for localIndex "<<li<<
" on this rank" );
1837 li = globalToLocalMap.at( gi );
1842 unmappedIndices.resize( 0 );
1843 sizeOfUnpackedChars += Unpack( buffer,
1847 relatedObjectGlobalToLocalMap );
1849 if( unmappedIndices.size()>0 )
1851 unmappedGlobalIndices[li] = unmappedIndices;
1856 return sizeOfUnpackedChars;
1859 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
1860 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
1861 Pack(
buffer_unit_type * & buffer, MAP_TYPE
const & var, T_INDICES
const & packIndices )
1863 typename MAP_TYPE::size_type
const length = var.size();
1864 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
1866 for(
typename MAP_TYPE::const_iterator i=var.begin(); i!=var.end(); ++i )
1868 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->first );
1869 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->second, packIndices );
1872 return sizeOfPackedChars;
1876 template<
typename MAP_TYPE,
typename T_INDICES >
1877 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
1878 Unpack(
buffer_unit_type const * & buffer, MAP_TYPE &
map, T_INDICES
const & unpackIndices )
1881 typename MAP_TYPE::size_type map_length;
1883 localIndex sizeOfUnpackedChars = Unpack( buffer, map_length );
1885 for(
typename MAP_TYPE::size_type a=0; a<map_length; ++a )
1887 typename MAP_TYPE::key_type key;
1888 typename MAP_TYPE::mapped_type value;
1889 sizeOfUnpackedChars += Unpack( buffer, key );
1890 sizeOfUnpackedChars += Unpack( buffer, value, unpackIndices );
1895 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_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
#define GEOS_ASSERT_MSG(EXP, msg)
Assert a condition in debug builds.
#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.