Loading examples/heat-equation/tnl-heat-equation-eoc.h +3 −4 Original line number Diff line number Diff line Loading @@ -8,8 +8,9 @@ /* See Copyright Notice in tnl/Copyright */ #ifndef TNL_HEAT_EQUATION_EOC_H_ #define TNL_HEAT_EQUATION_EOC_H_ #pragma once #define MPIIO #include <TNL/Solvers/Solver.h> #include <TNL/Solvers/FastBuildConfigTag.h> Loading Loading @@ -78,5 +79,3 @@ int main( int argc, char* argv[] ) return EXIT_FAILURE; return EXIT_SUCCESS; } #endif /* TNL_HEAT_EQUATION_EOC_H_ */ examples/heat-equation/tnl-heat-equation.h +4 −5 Original line number Diff line number Diff line Loading @@ -8,8 +8,9 @@ /* See Copyright Notice in tnl/Copyright */ #ifndef TNL_HEAT_EQUATION_H_ #define TNL_HEAT_EQUATION_H_ #pragma once #define MPIIO #include <TNL/Solvers/Solver.h> #include <TNL/Solvers/FastBuildConfigTag.h> Loading Loading @@ -109,5 +110,3 @@ int main( int argc, char* argv[] ) return EXIT_FAILURE; return EXIT_SUCCESS; } No newline at end of file #endif /* TNL_HEAT_EQUATION_H_ */ src/TNL/Communicators/CMakeLists.txt +1 −1 Original line number Diff line number Diff line SET( headers MpiCommunicator.h NoDistrCommunicator.h ) INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/TNL/Communicators ) INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY}/Communicators ) src/TNL/Communicators/MpiCommunicator.h +122 −89 Original line number Diff line number Diff line Loading @@ -10,14 +10,15 @@ #pragma once #ifdef HAVE_MPI #include <mpi.h> #include <TNL/String.h> #include <iostream> #include <fstream> #include <mpi.h> #include <TNL/String.h> #include <TNL/Logger.h> #include <TNL/Config/ConfigDescription.h> namespace TNL { namespace Communicators { Loading @@ -25,7 +26,8 @@ namespace Communicators { class MpiCommunicator { private: public: // TODO: this was private inline static MPI_Datatype MPIDataType( const signed char* ) { return MPI_CHAR; }; inline static MPI_Datatype MPIDataType( const signed short int* ) { return MPI_SHORT; }; inline static MPI_Datatype MPIDataType( const signed int* ) { return MPI_INT; }; Loading @@ -38,31 +40,46 @@ namespace Communicators { inline static MPI_Datatype MPIDataType( const double* ) { return MPI_DOUBLE; }; inline static MPI_Datatype MPIDataType( const long double* ) { return MPI_LONG_DOUBLE; }; public: //can be call before init static bool isAvailable() { return true; } using Request = MPI::Request; //can be called only after init static bool isDistributed() { return GetSize()>1; }; typedef MPI::Request Request; static MPI::Request NullRequest; static std::streambuf *psbuf; static std::streambuf *backup; static std::ofstream filestr; static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ) { #ifdef HAVE_MPI config.addEntry< bool >( "redirect-mpi-output", "Only process with rank 0 prints to console. Other processes are redirected to files.", true ); #endif } static void Init(int argc, char **argv,bool redirect=false) static bool setup( const Config::ParameterContainer& parameters, const String& prefix = "" ) { #ifdef HAVE_MPI redirect = parameters.getParameter< bool >( "redirect-mpi-output" ); setupRedirection(); #endif return true; } static void Init(int argc, char **argv ) { #ifdef HAVE_MPI MPI::Init( argc, argv ); NullRequest=MPI::REQUEST_NULL; redirect = true; #endif } static void setRedirection( bool redirect_ ) { redirect = redirect_; } static void setupRedirection() { if(isDistributed() && redirect ) { //redirect all stdout to files, only 0 take to go to console Loading @@ -72,9 +89,9 @@ namespace Communicators { if(MPI::COMM_WORLD.Get_rank()!=0) { std::cout<< GetRank() <<": Redirecting std::out to file" <<std::endl; String stdoutfile; stdoutfile=String( "./stdout-")+convertToString(MPI::COMM_WORLD.Get_rank())+String(".txt"); filestr.open (stdoutfile.getString()); String stdoutFile; stdoutFile=String( "./stdout-")+convertToString(MPI::COMM_WORLD.Get_rank())+String(".txt"); filestr.open (stdoutFile.getString()); psbuf = filestr.rdbuf(); std::cout.rdbuf(psbuf); } Loading Loading @@ -178,12 +195,28 @@ namespace Communicators { { MPI::COMM_WORLD.Reduce((void*) &data, (void*) &reduced_data,count,MPIDataType(data),op,root); };*/ static void writeProlog( Logger& logger ) { if( isDistributed() ) { logger.writeParameter( "MPI processes:", GetSize() ); } } static MPI::Request NullRequest; static std::streambuf *psbuf; static std::streambuf *backup; static std::ofstream filestr; static bool redirect; }; MPI::Request MpiCommunicator::NullRequest; std::streambuf *MpiCommunicator::psbuf; std::streambuf *MpiCommunicator::backup; std::ofstream MpiCommunicator::filestr; bool MpiCommunicator::redirect; }//namespace Communicators } // namespace TNL Loading src/TNL/Communicators/NoDistrCommunicator.h +107 −97 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ #pragma once #include <TNL/Logger.h> namespace TNL { namespace Communicators { Loading @@ -22,7 +24,10 @@ namespace Communicators { typedef int Request; static Request NullRequest; static bool isAvailable() static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ){}; static bool setup( const Config::ParameterContainer& parameters, const String& prefix = "" ) { return true; } Loading @@ -30,11 +35,13 @@ namespace Communicators { static void Init(int argc, char **argv, bool redirect=false) { NullRequest=-1; }; } static void Finalize() { }; static void setRedirection( bool redirect_ ) {} static void setupRedirection(){} static void Finalize(){} static bool IsInitialized() { Loading Loading @@ -107,8 +114,11 @@ namespace Communicators { { MPI::COMM_WORLD.Reduce((void*) &data, (void*) &reduced_data,count,MPIDataType(data),op,root); };*/ static void writeProlog( Logger& logger ){}; }; int NoDistrCommunicator::NullRequest; } // namespace Communicators Loading Loading
examples/heat-equation/tnl-heat-equation-eoc.h +3 −4 Original line number Diff line number Diff line Loading @@ -8,8 +8,9 @@ /* See Copyright Notice in tnl/Copyright */ #ifndef TNL_HEAT_EQUATION_EOC_H_ #define TNL_HEAT_EQUATION_EOC_H_ #pragma once #define MPIIO #include <TNL/Solvers/Solver.h> #include <TNL/Solvers/FastBuildConfigTag.h> Loading Loading @@ -78,5 +79,3 @@ int main( int argc, char* argv[] ) return EXIT_FAILURE; return EXIT_SUCCESS; } #endif /* TNL_HEAT_EQUATION_EOC_H_ */
examples/heat-equation/tnl-heat-equation.h +4 −5 Original line number Diff line number Diff line Loading @@ -8,8 +8,9 @@ /* See Copyright Notice in tnl/Copyright */ #ifndef TNL_HEAT_EQUATION_H_ #define TNL_HEAT_EQUATION_H_ #pragma once #define MPIIO #include <TNL/Solvers/Solver.h> #include <TNL/Solvers/FastBuildConfigTag.h> Loading Loading @@ -109,5 +110,3 @@ int main( int argc, char* argv[] ) return EXIT_FAILURE; return EXIT_SUCCESS; } No newline at end of file #endif /* TNL_HEAT_EQUATION_H_ */
src/TNL/Communicators/CMakeLists.txt +1 −1 Original line number Diff line number Diff line SET( headers MpiCommunicator.h NoDistrCommunicator.h ) INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/TNL/Communicators ) INSTALL( FILES ${headers} DESTINATION ${TNL_TARGET_INCLUDE_DIRECTORY}/Communicators )
src/TNL/Communicators/MpiCommunicator.h +122 −89 Original line number Diff line number Diff line Loading @@ -10,14 +10,15 @@ #pragma once #ifdef HAVE_MPI #include <mpi.h> #include <TNL/String.h> #include <iostream> #include <fstream> #include <mpi.h> #include <TNL/String.h> #include <TNL/Logger.h> #include <TNL/Config/ConfigDescription.h> namespace TNL { namespace Communicators { Loading @@ -25,7 +26,8 @@ namespace Communicators { class MpiCommunicator { private: public: // TODO: this was private inline static MPI_Datatype MPIDataType( const signed char* ) { return MPI_CHAR; }; inline static MPI_Datatype MPIDataType( const signed short int* ) { return MPI_SHORT; }; inline static MPI_Datatype MPIDataType( const signed int* ) { return MPI_INT; }; Loading @@ -38,31 +40,46 @@ namespace Communicators { inline static MPI_Datatype MPIDataType( const double* ) { return MPI_DOUBLE; }; inline static MPI_Datatype MPIDataType( const long double* ) { return MPI_LONG_DOUBLE; }; public: //can be call before init static bool isAvailable() { return true; } using Request = MPI::Request; //can be called only after init static bool isDistributed() { return GetSize()>1; }; typedef MPI::Request Request; static MPI::Request NullRequest; static std::streambuf *psbuf; static std::streambuf *backup; static std::ofstream filestr; static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ) { #ifdef HAVE_MPI config.addEntry< bool >( "redirect-mpi-output", "Only process with rank 0 prints to console. Other processes are redirected to files.", true ); #endif } static void Init(int argc, char **argv,bool redirect=false) static bool setup( const Config::ParameterContainer& parameters, const String& prefix = "" ) { #ifdef HAVE_MPI redirect = parameters.getParameter< bool >( "redirect-mpi-output" ); setupRedirection(); #endif return true; } static void Init(int argc, char **argv ) { #ifdef HAVE_MPI MPI::Init( argc, argv ); NullRequest=MPI::REQUEST_NULL; redirect = true; #endif } static void setRedirection( bool redirect_ ) { redirect = redirect_; } static void setupRedirection() { if(isDistributed() && redirect ) { //redirect all stdout to files, only 0 take to go to console Loading @@ -72,9 +89,9 @@ namespace Communicators { if(MPI::COMM_WORLD.Get_rank()!=0) { std::cout<< GetRank() <<": Redirecting std::out to file" <<std::endl; String stdoutfile; stdoutfile=String( "./stdout-")+convertToString(MPI::COMM_WORLD.Get_rank())+String(".txt"); filestr.open (stdoutfile.getString()); String stdoutFile; stdoutFile=String( "./stdout-")+convertToString(MPI::COMM_WORLD.Get_rank())+String(".txt"); filestr.open (stdoutFile.getString()); psbuf = filestr.rdbuf(); std::cout.rdbuf(psbuf); } Loading Loading @@ -178,12 +195,28 @@ namespace Communicators { { MPI::COMM_WORLD.Reduce((void*) &data, (void*) &reduced_data,count,MPIDataType(data),op,root); };*/ static void writeProlog( Logger& logger ) { if( isDistributed() ) { logger.writeParameter( "MPI processes:", GetSize() ); } } static MPI::Request NullRequest; static std::streambuf *psbuf; static std::streambuf *backup; static std::ofstream filestr; static bool redirect; }; MPI::Request MpiCommunicator::NullRequest; std::streambuf *MpiCommunicator::psbuf; std::streambuf *MpiCommunicator::backup; std::ofstream MpiCommunicator::filestr; bool MpiCommunicator::redirect; }//namespace Communicators } // namespace TNL Loading
src/TNL/Communicators/NoDistrCommunicator.h +107 −97 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ #pragma once #include <TNL/Logger.h> namespace TNL { namespace Communicators { Loading @@ -22,7 +24,10 @@ namespace Communicators { typedef int Request; static Request NullRequest; static bool isAvailable() static void configSetup( Config::ConfigDescription& config, const String& prefix = "" ){}; static bool setup( const Config::ParameterContainer& parameters, const String& prefix = "" ) { return true; } Loading @@ -30,11 +35,13 @@ namespace Communicators { static void Init(int argc, char **argv, bool redirect=false) { NullRequest=-1; }; } static void Finalize() { }; static void setRedirection( bool redirect_ ) {} static void setupRedirection(){} static void Finalize(){} static bool IsInitialized() { Loading Loading @@ -107,8 +114,11 @@ namespace Communicators { { MPI::COMM_WORLD.Reduce((void*) &data, (void*) &reduced_data,count,MPIDataType(data),op,root); };*/ static void writeProlog( Logger& logger ){}; }; int NoDistrCommunicator::NullRequest; } // namespace Communicators Loading