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,
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 std::vector< 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 std::vector< 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 std::vector< 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 );
530 GEOS_ASSERT_MSG( length == expectedLength,
"expectedLength != length: " <<
531 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 std::vector< 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_ARRAY_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 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1226 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1231 sizeOfUnpackedChars += Unpack( buffer, gi );
1233 if( sizeOfIndicesPassedIn > 0 )
1236 "global index "<<gi<<
" unpacked from buffer does not equal the lookup "
1237 <<li<<
" for localIndex "<<li<<
" on this rank" );
1241 li = globalToLocalMap.at( gi );
1245 sizeOfUnpackedChars += Unpack( buffer, mappedGlobalIndex );
1246 if( mappedGlobalIndex != -1 )
1248 var[li] = relatedObjectGlobalToLocalMap.at( mappedGlobalIndex );
1256 return sizeOfUnpackedChars;
1259 template<
bool DO_PACKING,
typename SORTED >
1262 arrayView1d< arrayView1d< localIndex const >
const >
const & var,
1263 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1264 arrayView1d< localIndex const >
const & indices,
1265 arrayView1d< globalIndex const >
const & localToGlobalMap,
1266 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1270 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1274 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1276 typename mapBase< localIndex, array1d< globalIndex >, SORTED >::const_iterator
1277 iterUnmappedGI = unmappedGlobalIndices.find( li );
1279 array1d< globalIndex > junk;
1280 array1d< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1282 iterUnmappedGI->second;
1284 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1285 var[li].toSliceConst(),
1288 relatedObjectLocalToGlobalMap );
1291 return sizeOfPackedChars;
1294 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1298 arrayView1d< localIndex_array > & var,
1299 array1d< localIndex > & indices,
1300 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1301 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1302 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap )
1305 localIndex const sizeOfIndicesPassedIn = indices.size();
1307 localIndex sizeOfUnpackedChars = Unpack( buffer, numIndicesUnpacked );
1309 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1310 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1311 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1313 indices.resize( numIndicesUnpacked );
1318 sizeOfUnpackedChars += Unpack( buffer, gi );
1321 if( sizeOfIndicesPassedIn > 0 )
1324 "global index "<<gi<<
" unpacked from buffer does not equal the lookup "
1325 <<li<<
" for localIndex "<<li<<
" on this rank" );
1329 li = globalToLocalMap.at( gi );
1332 array1d< globalIndex > unmappedIndices;
1333 sizeOfUnpackedChars += Unpack( buffer,
1336 relatedObjectGlobalToLocalMap );
1338 if( unmappedIndices.size() > 0 )
1340 unmappedGlobalIndices[li] = unmappedIndices;
1343 return sizeOfUnpackedChars;
1346 template<
bool DO_PACKING,
typename SORTED >
1349 ArrayOfArraysView< localIndex const >
const & var,
1350 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1351 arrayView1d< localIndex const >
const & indices,
1352 arrayView1d< globalIndex const >
const & localToGlobalMap,
1353 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1356 array1d< globalIndex > junk;
1358 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1362 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1364 typename mapBase< localIndex, array1d< globalIndex >, SORTED >::const_iterator
1365 iterUnmappedGI = unmappedGlobalIndices.find( li );
1367 array1d< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1369 iterUnmappedGI->second;
1371 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1374 var.sizeOfArray( li ),
1375 relatedObjectLocalToGlobalMap );
1378 return sizeOfPackedChars;
1381 template<
bool DO_PACKING,
typename SORTED >
1384 ArrayOfArraysView< localIndex const >
const & var,
1385 mapBase<
localIndex, SortedArray< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1386 arrayView1d< localIndex const >
const & indices,
1387 arrayView1d< globalIndex const >
const & localToGlobalMap,
1388 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1391 SortedArray< globalIndex > junk;
1393 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1397 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1399 typename mapBase< localIndex, SortedArray< globalIndex >, SORTED >::const_iterator
1400 iterUnmappedGI = unmappedGlobalIndices.find( li );
1402 SortedArray< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1404 iterUnmappedGI->second;
1406 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1409 var.sizeOfArray( li ),
1410 relatedObjectLocalToGlobalMap );
1413 return sizeOfPackedChars;
1416 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1420 ArrayOfArrays< localIndex > & var,
1421 array1d< localIndex > & indices,
1422 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1423 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1424 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap )
1427 localIndex const sizeOfIndicesPassedIn = indices.size();
1429 localIndex sizeOfUnpackedChars = Unpack( buffer, numIndicesUnpacked );
1431 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1432 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1433 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1435 indices.resize( numIndicesUnpacked );
1436 array1d< globalIndex > unmappedIndices;
1441 sizeOfUnpackedChars += Unpack( buffer, gi );
1444 if( sizeOfIndicesPassedIn > 0 )
1447 "global index "<<gi<<
" unpacked from buffer does not equal the lookup "
1448 <<li<<
" for localIndex "<<li<<
" on this rank" );
1452 li = globalToLocalMap.at( gi );
1455 unmappedIndices.resize( 0 );
1456 sizeOfUnpackedChars += Unpack( buffer,
1460 relatedObjectGlobalToLocalMap );
1462 if( unmappedIndices.size() > 0 )
1464 unmappedGlobalIndices[li] = unmappedIndices;
1467 return sizeOfUnpackedChars;
1470 template<
typename SORTED0 >
1475 array1d< localIndex > & indices,
1476 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap )
1479 localIndex const sizeOfIndicesPassedIn = indices.size();
1481 localIndex sizeOfUnpackedChars = bufferOps::Unpack( buffer, numIndicesUnpacked );
1483 GEOS_ERROR_IF( sizeOfIndicesPassedIn != 0 && numIndicesUnpacked != indices.size(),
1484 "number of unpacked indices(" << numIndicesUnpacked <<
") does not equal size of "
1485 "indices passed into Unpack function(" << sizeOfIndicesPassedIn );
1487 indices.resize( numIndicesUnpacked );
1488 array1d< globalIndex > unmappedIndices;
1493 sizeOfUnpackedChars += bufferOps::Unpack( buffer, gi );
1496 if( sizeOfIndicesPassedIn > 0 )
1499 "global index " << gi <<
" unpacked from buffer does not equal the lookup "
1500 << li <<
" for localIndex " << li <<
" on this rank" );
1504 li = globalToLocalMap.at( gi );
1507 unmappedIndices.resize( 0 );
1508 sizeOfUnpackedChars += Unpack( buffer,
1512 return sizeOfUnpackedChars;
1516 template<
bool DO_PACKING,
typename SORTED >
1519 arrayView1d< SortedArray< localIndex >
const >
const & var,
1520 mapBase<
localIndex, SortedArray< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1521 arrayView1d< localIndex const >
const & indices,
1522 arrayView1d< globalIndex const >
const & localToGlobalMap,
1523 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1525 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, indices.size() );
1530 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1532 typename mapBase< localIndex, SortedArray< globalIndex >, SORTED >::const_iterator
1533 iterUnmappedGI = unmappedGlobalIndices.find( li );
1535 SortedArray< globalIndex > junk;
1536 SortedArray< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1538 iterUnmappedGI->second;
1540 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1543 relatedObjectLocalToGlobalMap );
1546 return sizeOfPackedChars;
1550 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1556 mapBase<
localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1557 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1558 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap,
1559 bool const clearFlag )
1562 localIndex const sizeOfIndicesPassedIn = indices.size();
1565 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1566 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1567 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1568 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1570 indices.resize( numIndicesUnpacked );
1572 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1576 sizeOfUnpackedChars += Unpack( buffer, gi );
1579 if( sizeOfIndicesPassedIn > 0 )
1582 "global index "<<gi<<
" unpacked from buffer does equal the lookup "
1583 <<li<<
" for localIndex "<<li<<
" on this rank" );
1587 li = globalToLocalMap.at( gi );
1590 SortedArray< globalIndex > unmappedIndices;
1591 sizeOfUnpackedChars += Unpack( buffer,
1594 relatedObjectGlobalToLocalMap,
1597 if( unmappedIndices.size() > 0 )
1599 unmappedGlobalIndices[li].insert( unmappedIndices.data(), unmappedIndices.size() );
1602 return sizeOfUnpackedChars;
1605 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
1609 ArrayOfSets< localIndex > & var,
1611 mapBase<
localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1612 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1613 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap,
1614 bool const clearFlag )
1617 localIndex const sizeOfIndicesPassedIn = indices.size();
1620 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1621 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1622 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1623 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1625 indices.resize( numIndicesUnpacked );
1629 std::vector< globalIndex > unmapped;
1632 std::vector< localIndex > mapped;
1635 std::vector< localIndex > mappedNew;
1638 array1d< localIndex > indiciesToInsert;
1639 ArrayOfSets< localIndex > valuesToInsert;
1640 indiciesToInsert.reserve( numIndicesUnpacked );
1641 valuesToInsert.reserve( numIndicesUnpacked );
1642 valuesToInsert.reserveValues( numIndicesUnpacked * 12 );
1644 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1647 sizeOfUnpackedChars += Unpack( buffer, gi );
1650 if( sizeOfIndicesPassedIn > 0 )
1653 "global index "<<gi<<
" unpacked from buffer does equal the lookup "
1654 <<li<<
" for localIndex "<<li<<
" on this rank" );
1658 li = globalToLocalMap.at( gi );
1667 sizeOfUnpackedChars += Unpack( buffer, set_length );
1679 sizeOfUnpackedChars += Unpack( buffer, temp );
1680 auto iter = relatedObjectGlobalToLocalMap.find( temp );
1683 if( iter == relatedObjectGlobalToLocalMap.end() )
1685 unmapped.push_back( temp );
1691 mapped.push_back( iter->second );
1696 mapped.resize( LvArray::sortedArrayManipulation::makeSortedUnique( mapped.begin(), mapped.end() ) );
1697 std::set_difference( mapped.begin(), mapped.end(), var[li].begin(), var[li].end(), std::back_inserter( mappedNew ) );
1698 localIndex const numNewValues = LvArray::integerConversion< localIndex >( mappedNew.size() );
1701 if( numNewValues <= var.capacityOfSet( li ) - var.sizeOfSet( li ) )
1704 var.insertIntoSet( li, mappedNew.begin(), mappedNew.end() );
1709 localIndex const k = indiciesToInsert.size();
1710 indiciesToInsert.emplace_back( li );
1711 valuesToInsert.appendSet( numNewValues );
1712 valuesToInsert.insertIntoSet( k, mappedNew.begin(), mappedNew.end() );
1716 unmapped.resize( LvArray::sortedArrayManipulation::makeSortedUnique( unmapped.begin(), unmapped.end() ) );
1717 if( unmapped.size() > 0 )
1719 unmappedGlobalIndices[li].insert( unmapped.begin(), unmapped.end() );
1724 if( !indiciesToInsert.empty() )
1727 array1d< localIndex > newCapacities( var.size() );
1728 forAll< parallelHostPolicy >( var.size(), [var = var.toViewConst(), newCapacities = newCapacities.toView()](
localIndex const k )
1730 newCapacities[k] = var.capacityOfSet( k );
1734 for(
localIndex i = 0; i < indiciesToInsert.size(); ++i )
1736 newCapacities[indiciesToInsert[i]] += valuesToInsert.sizeOfSet( i );
1740 ArrayOfSets< localIndex > newVar;
1741 newVar.resizeFromCapacities< parallelHostPolicy >( var.size(), newCapacities.data() );
1744 forAll< parallelHostPolicy >( var.size(), [var = var.toViewConst(), newVar = newVar.toView()](
localIndex const k )
1746 newVar.insertIntoSet( k, var[k].begin(), var[k].end() );
1750 for(
localIndex i = 0; i < indiciesToInsert.size(); ++i )
1753 newVar.insertIntoSet( k, valuesToInsert[i].begin(), valuesToInsert[i].end() );
1757 var = std::move( newVar );
1760 return sizeOfUnpackedChars;
1764 template<
bool DO_PACKING,
int USD0,
int USD1 >
1767 arrayView2d< localIndex const, USD0 >
const & var,
1768 arrayView1d< localIndex >
const & indices,
1769 arraySlice1d< globalIndex const, USD1 >
const & localToGlobalMap )
1771 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, indices.size() );
1775 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1777 sizeOfPackedChars += PackArray< DO_PACKING >( buffer, var[li], var.size( 1 ) );
1780 return sizeOfPackedChars;
1783 template<
typename SORTED,
int USD >
1787 arrayView2d< localIndex, USD >
const & var,
1788 array1d< localIndex > & indices,
1789 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap )
1792 localIndex const sizeOfIndicesPassedIn = indices.size();
1795 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1797 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1798 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1799 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1801 indices.resize( numIndicesUnpacked );
1803 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1806 sizeOfUnpackedChars += Unpack( buffer, gi );
1809 if( sizeOfIndicesPassedIn > 0 )
1812 "global index "<<gi<<
" unpacked from buffer does equal the lookup "
1813 <<li<<
" for localIndex "<<li<<
" on this rank" );
1817 li = globalToLocalMap.at( gi );
1821 sizeOfUnpackedChars += UnpackPointer( buffer, varSlice, var.size( 1 ) );
1824 return sizeOfUnpackedChars;
1828 template<
bool DO_PACKING,
typename SORTED,
int USD0 >
1831 arrayView2d< localIndex const, USD0 >
const & var,
1832 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
1833 arrayView1d< localIndex const >
const & indices,
1834 arraySlice1d< globalIndex const >
const & localToGlobalMap,
1835 arraySlice1d< globalIndex const >
const & relatedObjectLocalToGlobalMap )
1838 array1d< globalIndex > invalidGlobalIndices( var.size( 1 ) );
1841 invalidGlobalIndices[a] = -1;
1844 sizeOfPackedChars += Pack< DO_PACKING >( buffer, indices.size() );
1848 sizeOfPackedChars += Pack< DO_PACKING >( buffer, localToGlobalMap[li] );
1850 typename mapBase< localIndex, array1d< globalIndex >, SORTED >::const_iterator
1851 iterUnmappedGI = unmappedGlobalIndices.find( li );
1853 array1d< globalIndex >
const & unmappedGI = iterUnmappedGI==unmappedGlobalIndices.end() ?
1854 invalidGlobalIndices :
1855 iterUnmappedGI->second;
1857 sizeOfPackedChars += Pack< DO_PACKING >( buffer,
1861 relatedObjectLocalToGlobalMap );
1864 return sizeOfPackedChars;
1868 template<
typename SORTED0,
typename SORTED1,
typename SORTED2,
int USD >
1872 arrayView2d< localIndex, USD >
const & var,
1874 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
1875 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
1876 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap )
1879 localIndex const sizeOfIndicesPassedIn = indices.size();
1882 sizeOfUnpackedChars += Unpack( buffer, numIndicesUnpacked );
1883 GEOS_ERROR_IF( sizeOfIndicesPassedIn!=0 && numIndicesUnpacked!=indices.size(),
1884 "number of unpacked indices("<<numIndicesUnpacked<<
") does not equal size of "
1885 "indices passed into Unpack function("<<sizeOfIndicesPassedIn );
1887 indices.resize( numIndicesUnpacked );
1888 array1d< globalIndex > unmappedIndices;
1890 for(
localIndex a=0; a<numIndicesUnpacked; ++a )
1893 sizeOfUnpackedChars += Unpack( buffer, gi );
1896 if( sizeOfIndicesPassedIn > 0 )
1899 "global index "<<gi<<
" unpacked from buffer does equal the lookup "
1900 <<li<<
" for localIndex "<<li<<
" on this rank" );
1904 li = globalToLocalMap.at( gi );
1909 unmappedIndices.resize( 0 );
1910 sizeOfUnpackedChars += Unpack( buffer,
1914 relatedObjectGlobalToLocalMap );
1916 if( unmappedIndices.size()>0 )
1918 unmappedGlobalIndices[li] = unmappedIndices;
1923 return sizeOfUnpackedChars;
1926 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
1927 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
1928 Pack(
buffer_unit_type * & buffer, MAP_TYPE
const & var, T_INDICES
const & packIndices )
1930 typename MAP_TYPE::size_type
const length = var.size();
1931 localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length );
1933 for(
typename MAP_TYPE::const_iterator i=var.begin(); i!=var.end(); ++i )
1935 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->first );
1936 sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->second, packIndices );
1939 return sizeOfPackedChars;
1943 template<
typename MAP_TYPE,
typename T_INDICES >
1944 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
1945 Unpack(
buffer_unit_type const * & buffer, MAP_TYPE &
map, T_INDICES
const & unpackIndices )
1948 typename MAP_TYPE::size_type map_length;
1950 localIndex sizeOfUnpackedChars = Unpack( buffer, map_length );
1952 for(
typename MAP_TYPE::size_type a=0; a<map_length; ++a )
1954 typename MAP_TYPE::key_type key;
1955 typename MAP_TYPE::mapped_type value;
1956 sizeOfUnpackedChars += Unpack( buffer, key );
1957 sizeOfUnpackedChars += Unpack( buffer, value, unpackIndices );
1962 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.