Commit de4063f2 authored by Jakub Klinkovský's avatar Jakub Klinkovský Committed by Jakub Klinkovský
Browse files

Added loadFromGlobalFile to DistributedArray and DistributedArrayView

parent ac41fa6b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -277,6 +277,12 @@ public:
   void
   forElements( IndexType begin, IndexType end, Function&& f ) const;

   void
   loadFromGlobalFile( const String& fileName, bool allowCasting = false );

   void
   loadFromGlobalFile( File& file, bool allowCasting = false );

protected:
   ViewType view;
   LocalArrayType localData;
+14 −0
Original line number Diff line number Diff line
@@ -316,5 +316,19 @@ DistributedArray< Value, Device, Index, Allocator >::forElements( IndexType begi
   view.forElements( begin, end, f );
}

template< typename Value, typename Device, typename Index, typename Allocator >
void
DistributedArray< Value, Device, Index, Allocator >::loadFromGlobalFile( const String& fileName, bool allowCasting )
{
   view.loadFromGlobalFile( fileName, allowCasting );
}

template< typename Value, typename Device, typename Index, typename Allocator >
void
DistributedArray< Value, Device, Index, Allocator >::loadFromGlobalFile( File& file, bool allowCasting )
{
   view.loadFromGlobalFile( file, allowCasting );
}

}  // namespace Containers
}  // namespace TNL
+6 −0
Original line number Diff line number Diff line
@@ -253,6 +253,12 @@ public:
   void
   forElements( IndexType begin, IndexType end, Function&& f ) const;

   void
   loadFromGlobalFile( const String& fileName, bool allowCasting = false );

   void
   loadFromGlobalFile( File& file, bool allowCasting = false );

protected:
   LocalRangeType localRange;
   IndexType ghosts = 0;
+30 −0
Original line number Diff line number Diff line
@@ -377,5 +377,35 @@ DistributedArrayView< Value, Device, Index >::forElements( IndexType begin, Inde
   localData.forElements( localBegin, localEnd, local_f );
}

template< typename Value, typename Device, typename Index >
void
DistributedArrayView< Value, Device, Index >::loadFromGlobalFile( const String& fileName, bool allowCasting )
{
   File file( fileName, std::ios_base::in );
   loadFromGlobalFile( file, allowCasting );
}

template< typename Value, typename Device, typename Index >
void
DistributedArrayView< Value, Device, Index >::loadFromGlobalFile( File& file, bool allowCasting )
{
   using IO = detail::ArrayIO< Value, Index, typename Allocators::Default< Device >::template Allocator< Value > >;
   const std::string type = getObjectType( file );
   const auto parsedType = parseObjectType( type );

   if( ! allowCasting && type != IO::getSerializationType() )
      throw Exceptions::FileDeserializationError(
         file.getFileName(), "object type does not match (expected " + IO::getSerializationType() + ", found " + type + ")." );

   std::size_t elementsInFile;
   file.load( &elementsInFile );

   if( allowCasting )
      IO::loadSubrange(
         file, elementsInFile, localRange.getBegin(), localData.getData(), localData.getSize(), parsedType[ 1 ] );
   else
      IO::loadSubrange( file, elementsInFile, localRange.getBegin(), localData.getData(), localData.getSize() );
}

}  // namespace Containers
}  // namespace TNL