diff --git a/src/Tools/tnl-init.cpp b/src/Tools/tnl-init.cpp index f42b9ad3c9aeb02690ef4f7def74acf6c2ce3087..0152677521ac7605dffba112ef2524dc41272106 100644 --- a/src/Tools/tnl-init.cpp +++ b/src/Tools/tnl-init.cpp @@ -8,6 +8,10 @@ /* See Copyright Notice in tnl/Copyright */ +#ifdef HAVE_MPI + #define USE_MPI +#endif + #include "tnl-init.h" #include <TNL/File.h> @@ -17,6 +21,8 @@ #include <TNL/Meshes/DummyMesh.h> #include <TNL/Meshes/Grid.h> +#include <TNL/mpi-supp.h> + using namespace TNL; void setupConfig( Config::ConfigDescription& config ) @@ -45,6 +51,10 @@ void setupConfig( Config::ConfigDescription& config ) int main( int argc, char* argv[] ) { +#ifdef USE_MPI + MPI::Init(argc,argv); +#endif + Config::ParameterContainer parameters; Config::ConfigDescription conf_desc; @@ -69,5 +79,10 @@ int main( int argc, char* argv[] ) } if( ! resolveMeshType( parsedMeshType, parameters ) ) return EXIT_FAILURE; + +#ifdef USE_MPI + MPI::Finalize(); +#endif + return EXIT_SUCCESS; } diff --git a/src/Tools/tnl-init.h b/src/Tools/tnl-init.h index 355c553f02695d28f45c3994ef80891ead05b4cd..4d83009aa658319b27dd273074e82213e70e28cb 100644 --- a/src/Tools/tnl-init.h +++ b/src/Tools/tnl-init.h @@ -19,6 +19,9 @@ #include <TNL/FileName.h> #include <TNL/Functions/MeshFunction.h> +#include <TNL/Meshes/DistributedGrid.h> +#include <TNL/Meshes/DistributedGridIO.h> + using namespace TNL; template< typename MeshType, @@ -28,11 +31,28 @@ template< typename MeshType, int zDiff > bool renderFunction( const Config::ParameterContainer& parameters ) { +#ifdef USE_MPI + //suppose global mesh loaded from file - EXPLOSIVE CODE + SharedPointer< MeshType > globalMeshPointer; + String meshFile = parameters.getParameter< String >( "mesh" ); + std::cout << "+ -> Loading mesh from " << meshFile << " ... " << std::endl; + if( ! globalMeshPointer->load( meshFile ) ) + return false; + + typename Meshes::DistributedGrid<MeshType>::CoordinatesType overlap; + overlap.setValue(1); + Meshes::DistributedGrid<MeshType> distrgrid(*globalMeshPointer,overlap); + + SharedPointer< MeshType > meshPointer; + distrgrid.SetupGrid(*meshPointer); +#else + SharedPointer< MeshType > meshPointer; String meshFile = parameters.getParameter< String >( "mesh" ); std::cout << "+ -> Loading mesh from " << meshFile << " ... " << std::endl; if( ! meshPointer->load( meshFile ) ) return false; +#endif typedef Functions::TestFunction< MeshType::getMeshDimension(), RealType > FunctionType; typedef SharedPointer< FunctionType, typename MeshType::DeviceType > FunctionPointer; @@ -87,8 +107,15 @@ bool renderFunction( const Config::ParameterContainer& parameters ) } else std::cout << "+ -> Writing the function to " << outputFile << " ... " << std::endl; +#ifdef USE_MPI + File file; + file.open( outputFile+convertToString(MPI::COMM_WORLD.Get_rank()), IOMode::write ); + Meshes::DistributedGridIO<MeshFunctionType> ::save(file, *meshFunction ); + file.close(); +#else if( ! meshFunction->save( outputFile) ) return false; +#endif time += tau; step ++; }