Loading src/TNL/Functions/VectorField.h +4 −2 Original line number Diff line number Diff line Loading @@ -96,6 +96,8 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > static constexpr int getMeshDimension() { return MeshType::getMeshDimension(); } static constexpr int getVectorDimension() { return Size; } static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ) Loading Loading @@ -192,8 +194,8 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > "Attempt to bind vector which is not large enough." ); for( int i = 0; i < Size; i ++ ) { this->vectorField[ i ].bind( meshPointer, data, offset ); offset += this->vectorField[ i ]->getDofs(); this->vectorField[ i ]->bind( meshPointer, data, offset ); offset += this->vectorField[ i ]->getDofs(meshPointer); } } Loading src/TNL/Meshes/DistributedMeshes/CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ SET( headers BufferEntitiesHelper.h DistributedGrid_Base.hpp DistributedGridSynchronizer.h DistributedGridIO.h DistributedGridIO_MeshFunction.h DistributedGridIO_VectorField.h Directions.h ) Loading src/TNL/Meshes/DistributedMeshes/DistributedGridIO.h +2 −0 Original line number Diff line number Diff line Loading @@ -56,4 +56,6 @@ class DistributedGridIO<MeshFunctionType,Dummy,Device> } } //not clean logic of includes... #include <TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h> #include <TNL/Meshes/DistributedMeshes/DistributedGridIO_VectorField.h> src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h +15 −9 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ #pragma once #include <TNL/Functions/MeshFunction.h> namespace TNL { namespace Meshes { namespace DistributedMeshes { Loading @@ -19,14 +21,13 @@ namespace DistributedMeshes { * This variant cerate copy of MeshFunction but smaller, reduced to local entities, without overlap. * It is slow and has high RAM consumption */ template<typename MeshFunctionType, template<typename MeshType, typename Device> class DistributedGridIO<MeshFunctionType,LocalCopy,Device> class DistributedGridIO<Functions::MeshFunction<MeshType>,LocalCopy,Device> { public: typedef typename MeshFunctionType::MeshType MeshType; typedef typename Functions::MeshFunction<MeshType> MeshFunctionType; typedef typename MeshFunctionType::MeshType::CoordinatesType CoordinatesType; typedef typename MeshFunctionType::MeshType::PointType PointType; typedef typename MeshFunctionType::VectorType VectorType; Loading Loading @@ -360,7 +361,7 @@ class DistributedGridIO_MPIIOBase return headerSize+dataCount*sizeof(RealType); //size of readed data; }; //tak mohlo by to něco kontrolovat...ale nic to nekontroluje //it shoudl check some loaded files...... but chcek nothing... static int readMeshFunctionHeader(MPI_File file,MeshFunctionType &meshFunction, int length) { MPI_Status rstatus; Loading Loading @@ -396,10 +397,12 @@ class DistributedGridIO_MPIIOBase }; #endif template<typename MeshFunctionType> class DistributedGridIO<MeshFunctionType,MpiIO,TNL::Devices::Cuda> template<typename MeshType> class DistributedGridIO<Functions::MeshFunction<MeshType>,MpiIO,TNL::Devices::Cuda> { public: typedef typename Functions::MeshFunction<MeshType> MeshFunctionType; static bool save(const String& fileName, MeshFunctionType &meshFunction) { #ifdef HAVE_MPI Loading Loading @@ -437,10 +440,13 @@ class DistributedGridIO<MeshFunctionType,MpiIO,TNL::Devices::Cuda> }; template<typename MeshFunctionType> class DistributedGridIO<MeshFunctionType,MpiIO,TNL::Devices::Host> template<typename MeshType> class DistributedGridIO<Functions::MeshFunction<MeshType>,MpiIO,TNL::Devices::Host> { public: typedef typename Functions::MeshFunction<MeshType> MeshFunctionType; static bool save(const String& fileName, MeshFunctionType &meshFunction) { #ifdef HAVE_MPI Loading src/TNL/Meshes/DistributedMeshes/DistributedGridIO_VectorField.h 0 → 100644 +150 −0 Original line number Diff line number Diff line /*************************************************************************** DistributedGridIO_NeshFunction.h - description ------------------- begin : October 5, 2017 copyright : (C) 2017 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <TNL/Functions/VectorField.h> namespace TNL { namespace Meshes { namespace DistributedMeshes { //VCT field template< int Size, typename MeshFunctionType, typename Device> class DistributedGridIO<Functions::VectorField<Size,MeshFunctionType>,MpiIO,Device> { public: static bool save(const String& fileName, Functions::VectorField<Size,MeshFunctionType> &vectorField) { #ifdef HAVE_MPI std::cout << "saving VCT filed" << endl; if(Communicators::MpiCommunicator::IsInitialized())//i.e. - isUsed { auto *distrGrid=vectorField.getMesh().getDistributedMesh(); if(distrGrid==NULL) { return vectorField.save(fileName); } MPI_Comm group=*((MPI_Comm*)(distrGrid->getCommunicationGroup())); //write MPI_File file; MPI_File_open( group, const_cast< char* >( fileName.getString() ), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &file); int offset=0; //global offset -> every meshfunctoion creates it's own datatypes we need manage global offset if(Communicators::MpiCommunicator::GetRank(group)==0) offset+=writeVectorFieldHeader(file,vectorField); MPI_Bcast(&offset, 1, MPI_INT,0, group); for( int i = 0; i < vectorField.getVectorDimension(); i++ ) { typename MeshFunctionType::RealType * data=vectorField[i]->getData().getData(); //here manage data transfer Device... int size = DistributedGridIO_MPIIOBase<MeshFunctionType>::save(file,*(vectorField[i]),data,offset); offset+=size; if( size==0 ) return false; } MPI_File_close(&file); return true; } #endif std::cout << "MPIIO can be used only with MPICommunicator." << std::endl; return false; }; private: static unsigned int writeVectorFieldHeader(MPI_File &file,Functions::VectorField<Size,MeshFunctionType> &vectorField) { unsigned int size=0; int count; MPI_Status wstatus; //Magic MPI_File_write( file, const_cast< void* >( ( const void* ) "TNLMN" ), 5, MPI_CHAR,&wstatus ); MPI_Get_count(&wstatus,MPI_CHAR,&count); size+=count*sizeof(char); //Meshfunction type String vectorFieldSerializationType=vectorField.getSerializationTypeVirtual(); int vectorFieldSerializationTypeLength=vectorFieldSerializationType.getLength(); MPI_File_write(file,&vectorFieldSerializationTypeLength,1,MPI_INT,&wstatus); MPI_Get_count(&wstatus,MPI_INT,&count); size+=count*sizeof(int); MPI_File_write(file,vectorFieldSerializationType.getString(),vectorFieldSerializationType.getLength(),MPI_CHAR,&wstatus); MPI_Get_count(&wstatus,MPI_CHAR,&count); size+=count*sizeof(char); return size; } /* static bool load(const String& fileName,MeshFunctionType &meshFunction) { #ifdef HAVE_MPI if(Communicators::MpiCommunicator::IsInitialized())//i.e. - isUsed { using HostVectorType = Containers::Vector<typename MeshFunctionType::RealType, Devices::Host, typename MeshFunctionType::IndexType >; HostVectorType hostVector; hostVector.setLike(meshFunction.getData()); double * data=hostVector.getData(); DistributedGridIO_MPIIOBase<MeshFunctionType>::load(fileName,meshFunction,data); meshFunction.getData()=hostVector; return true; } #endif std::cout << "MPIIO can be used only with MPICommunicator." << std::endl; return false; }; #ifdef HAVE MPI private: static unsigned int writeVectorFieldHeader(MPI_File &file,Functions::VectorField<Size,MeshFunctionType> &vectorField ) { unsigned int size=0; int count; MPI_Status wstatus; //Magic MPI_File_write( file, const_cast< void* >( ( const void* ) "TNLMN" ), 5, MPI_CHAR,&wstatus ); MPI_Get_count(&wstatus,MPI_CHAR,&count); size+=count*sizeof(char); //Meshfunction type String vectorFieldSerializationType=vectorField.getSerializationTypeVirtual(); int vectorFieldSerializationTypeLength=vectorFieldSerializationType.getLength(); MPI_File_write(file,&vectorFieldSerializationTypeLength,1,MPI_INT,&wstatus); MPI_Get_count(&wstatus,MPI_INT,&count); size+=count*sizeof(int); MPI_File_write(file,vectorFieldSerializationType.getString(),vectorFieldSerializationType.getLength(),MPI_CHAR,&wstatus); MPI_Get_count(&wstatus,MPI_CHAR,&count); size+=count*sizeof(char); return size; }; #endif */ }; } } } Loading
src/TNL/Functions/VectorField.h +4 −2 Original line number Diff line number Diff line Loading @@ -96,6 +96,8 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > static constexpr int getMeshDimension() { return MeshType::getMeshDimension(); } static constexpr int getVectorDimension() { return Size; } static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ) Loading Loading @@ -192,8 +194,8 @@ class VectorField< Size, MeshFunction< Mesh, MeshEntityDimension, Real > > "Attempt to bind vector which is not large enough." ); for( int i = 0; i < Size; i ++ ) { this->vectorField[ i ].bind( meshPointer, data, offset ); offset += this->vectorField[ i ]->getDofs(); this->vectorField[ i ]->bind( meshPointer, data, offset ); offset += this->vectorField[ i ]->getDofs(meshPointer); } } Loading
src/TNL/Meshes/DistributedMeshes/CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ SET( headers BufferEntitiesHelper.h DistributedGrid_Base.hpp DistributedGridSynchronizer.h DistributedGridIO.h DistributedGridIO_MeshFunction.h DistributedGridIO_VectorField.h Directions.h ) Loading
src/TNL/Meshes/DistributedMeshes/DistributedGridIO.h +2 −0 Original line number Diff line number Diff line Loading @@ -56,4 +56,6 @@ class DistributedGridIO<MeshFunctionType,Dummy,Device> } } //not clean logic of includes... #include <TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h> #include <TNL/Meshes/DistributedMeshes/DistributedGridIO_VectorField.h>
src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h +15 −9 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ #pragma once #include <TNL/Functions/MeshFunction.h> namespace TNL { namespace Meshes { namespace DistributedMeshes { Loading @@ -19,14 +21,13 @@ namespace DistributedMeshes { * This variant cerate copy of MeshFunction but smaller, reduced to local entities, without overlap. * It is slow and has high RAM consumption */ template<typename MeshFunctionType, template<typename MeshType, typename Device> class DistributedGridIO<MeshFunctionType,LocalCopy,Device> class DistributedGridIO<Functions::MeshFunction<MeshType>,LocalCopy,Device> { public: typedef typename MeshFunctionType::MeshType MeshType; typedef typename Functions::MeshFunction<MeshType> MeshFunctionType; typedef typename MeshFunctionType::MeshType::CoordinatesType CoordinatesType; typedef typename MeshFunctionType::MeshType::PointType PointType; typedef typename MeshFunctionType::VectorType VectorType; Loading Loading @@ -360,7 +361,7 @@ class DistributedGridIO_MPIIOBase return headerSize+dataCount*sizeof(RealType); //size of readed data; }; //tak mohlo by to něco kontrolovat...ale nic to nekontroluje //it shoudl check some loaded files...... but chcek nothing... static int readMeshFunctionHeader(MPI_File file,MeshFunctionType &meshFunction, int length) { MPI_Status rstatus; Loading Loading @@ -396,10 +397,12 @@ class DistributedGridIO_MPIIOBase }; #endif template<typename MeshFunctionType> class DistributedGridIO<MeshFunctionType,MpiIO,TNL::Devices::Cuda> template<typename MeshType> class DistributedGridIO<Functions::MeshFunction<MeshType>,MpiIO,TNL::Devices::Cuda> { public: typedef typename Functions::MeshFunction<MeshType> MeshFunctionType; static bool save(const String& fileName, MeshFunctionType &meshFunction) { #ifdef HAVE_MPI Loading Loading @@ -437,10 +440,13 @@ class DistributedGridIO<MeshFunctionType,MpiIO,TNL::Devices::Cuda> }; template<typename MeshFunctionType> class DistributedGridIO<MeshFunctionType,MpiIO,TNL::Devices::Host> template<typename MeshType> class DistributedGridIO<Functions::MeshFunction<MeshType>,MpiIO,TNL::Devices::Host> { public: typedef typename Functions::MeshFunction<MeshType> MeshFunctionType; static bool save(const String& fileName, MeshFunctionType &meshFunction) { #ifdef HAVE_MPI Loading
src/TNL/Meshes/DistributedMeshes/DistributedGridIO_VectorField.h 0 → 100644 +150 −0 Original line number Diff line number Diff line /*************************************************************************** DistributedGridIO_NeshFunction.h - description ------------------- begin : October 5, 2017 copyright : (C) 2017 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <TNL/Functions/VectorField.h> namespace TNL { namespace Meshes { namespace DistributedMeshes { //VCT field template< int Size, typename MeshFunctionType, typename Device> class DistributedGridIO<Functions::VectorField<Size,MeshFunctionType>,MpiIO,Device> { public: static bool save(const String& fileName, Functions::VectorField<Size,MeshFunctionType> &vectorField) { #ifdef HAVE_MPI std::cout << "saving VCT filed" << endl; if(Communicators::MpiCommunicator::IsInitialized())//i.e. - isUsed { auto *distrGrid=vectorField.getMesh().getDistributedMesh(); if(distrGrid==NULL) { return vectorField.save(fileName); } MPI_Comm group=*((MPI_Comm*)(distrGrid->getCommunicationGroup())); //write MPI_File file; MPI_File_open( group, const_cast< char* >( fileName.getString() ), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &file); int offset=0; //global offset -> every meshfunctoion creates it's own datatypes we need manage global offset if(Communicators::MpiCommunicator::GetRank(group)==0) offset+=writeVectorFieldHeader(file,vectorField); MPI_Bcast(&offset, 1, MPI_INT,0, group); for( int i = 0; i < vectorField.getVectorDimension(); i++ ) { typename MeshFunctionType::RealType * data=vectorField[i]->getData().getData(); //here manage data transfer Device... int size = DistributedGridIO_MPIIOBase<MeshFunctionType>::save(file,*(vectorField[i]),data,offset); offset+=size; if( size==0 ) return false; } MPI_File_close(&file); return true; } #endif std::cout << "MPIIO can be used only with MPICommunicator." << std::endl; return false; }; private: static unsigned int writeVectorFieldHeader(MPI_File &file,Functions::VectorField<Size,MeshFunctionType> &vectorField) { unsigned int size=0; int count; MPI_Status wstatus; //Magic MPI_File_write( file, const_cast< void* >( ( const void* ) "TNLMN" ), 5, MPI_CHAR,&wstatus ); MPI_Get_count(&wstatus,MPI_CHAR,&count); size+=count*sizeof(char); //Meshfunction type String vectorFieldSerializationType=vectorField.getSerializationTypeVirtual(); int vectorFieldSerializationTypeLength=vectorFieldSerializationType.getLength(); MPI_File_write(file,&vectorFieldSerializationTypeLength,1,MPI_INT,&wstatus); MPI_Get_count(&wstatus,MPI_INT,&count); size+=count*sizeof(int); MPI_File_write(file,vectorFieldSerializationType.getString(),vectorFieldSerializationType.getLength(),MPI_CHAR,&wstatus); MPI_Get_count(&wstatus,MPI_CHAR,&count); size+=count*sizeof(char); return size; } /* static bool load(const String& fileName,MeshFunctionType &meshFunction) { #ifdef HAVE_MPI if(Communicators::MpiCommunicator::IsInitialized())//i.e. - isUsed { using HostVectorType = Containers::Vector<typename MeshFunctionType::RealType, Devices::Host, typename MeshFunctionType::IndexType >; HostVectorType hostVector; hostVector.setLike(meshFunction.getData()); double * data=hostVector.getData(); DistributedGridIO_MPIIOBase<MeshFunctionType>::load(fileName,meshFunction,data); meshFunction.getData()=hostVector; return true; } #endif std::cout << "MPIIO can be used only with MPICommunicator." << std::endl; return false; }; #ifdef HAVE MPI private: static unsigned int writeVectorFieldHeader(MPI_File &file,Functions::VectorField<Size,MeshFunctionType> &vectorField ) { unsigned int size=0; int count; MPI_Status wstatus; //Magic MPI_File_write( file, const_cast< void* >( ( const void* ) "TNLMN" ), 5, MPI_CHAR,&wstatus ); MPI_Get_count(&wstatus,MPI_CHAR,&count); size+=count*sizeof(char); //Meshfunction type String vectorFieldSerializationType=vectorField.getSerializationTypeVirtual(); int vectorFieldSerializationTypeLength=vectorFieldSerializationType.getLength(); MPI_File_write(file,&vectorFieldSerializationTypeLength,1,MPI_INT,&wstatus); MPI_Get_count(&wstatus,MPI_INT,&count); size+=count*sizeof(int); MPI_File_write(file,vectorFieldSerializationType.getString(),vectorFieldSerializationType.getLength(),MPI_CHAR,&wstatus); MPI_Get_count(&wstatus,MPI_CHAR,&count); size+=count*sizeof(char); return size; }; #endif */ }; } } }