Loading src/TNL/Communicators/MpiCommunicator.h +38 −1 Original line number Diff line number Diff line Loading @@ -13,6 +13,9 @@ #ifdef HAVE_MPI #include <mpi.h> #include <TNL/String.h> #include <iostream> #include <fstream> namespace TNL { namespace Communicators { Loading @@ -37,11 +40,30 @@ namespace Communicators { typedef MPI::Request Request; static MPI::Request NullRequest; static std::streambuf *psbuf; static std::streambuf *backup; static std::ofstream filestr; static void Init(int argc, char **argv) static void Init(int argc, char **argv,bool redirect=false) { MPI::Init(argc,argv); NullRequest=MPI::REQUEST_NULL; if(isDistributed() && redirect) { //redirect all stdout to files, only 0 take to go to console backup=std::cout.rdbuf(); //redirect output to files... 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()); psbuf = filestr.rdbuf(); std::cout.rdbuf(psbuf); } } }; static void Finalize() Loading @@ -54,6 +76,18 @@ namespace Communicators { return MPI::Is_initialized(); }; //can be call before init static bool isAvailable() { return true; } //can be called only after init static bool isDistributed() { return GetSize()>1; }; static int GetRank() { return MPI::COMM_WORLD.Get_rank(); Loading Loading @@ -121,6 +155,9 @@ namespace Communicators { }; MPI::Request MpiCommunicator::NullRequest; std::streambuf *MpiCommunicator::psbuf; std::streambuf *MpiCommunicator::backup; std::ofstream MpiCommunicator::filestr; }//namespace Communicators } // namespace TNL Loading src/TNL/Communicators/NoDistrCommunicator.h +14 −4 Original line number Diff line number Diff line Loading @@ -22,7 +22,12 @@ namespace Communicators { typedef int Request; static Request NullRequest; static void Init(int argc, char **argv) static bool isAvailable() { return true; } static void Init(int argc, char **argv, bool redirect=false) { NullRequest=-1; }; Loading @@ -36,6 +41,11 @@ namespace Communicators { return true; }; static bool isDistributed() { return false; }; static int GetRank() { return 0; Loading @@ -62,13 +72,13 @@ namespace Communicators { static Request ISend( const T *data, int count, int dest) { return 1; } }; template <typename T> static Request IRecv( const T *data, int count, int src) { return 1; } }; static void WaitAll(Request *reqs, int length) { Loading @@ -77,7 +87,7 @@ namespace Communicators { template< typename T > static void Bcast( T& data, int count, int root) { } }; /* template< typename T > static void Allreduce( T& data, Loading Loading
src/TNL/Communicators/MpiCommunicator.h +38 −1 Original line number Diff line number Diff line Loading @@ -13,6 +13,9 @@ #ifdef HAVE_MPI #include <mpi.h> #include <TNL/String.h> #include <iostream> #include <fstream> namespace TNL { namespace Communicators { Loading @@ -37,11 +40,30 @@ namespace Communicators { typedef MPI::Request Request; static MPI::Request NullRequest; static std::streambuf *psbuf; static std::streambuf *backup; static std::ofstream filestr; static void Init(int argc, char **argv) static void Init(int argc, char **argv,bool redirect=false) { MPI::Init(argc,argv); NullRequest=MPI::REQUEST_NULL; if(isDistributed() && redirect) { //redirect all stdout to files, only 0 take to go to console backup=std::cout.rdbuf(); //redirect output to files... 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()); psbuf = filestr.rdbuf(); std::cout.rdbuf(psbuf); } } }; static void Finalize() Loading @@ -54,6 +76,18 @@ namespace Communicators { return MPI::Is_initialized(); }; //can be call before init static bool isAvailable() { return true; } //can be called only after init static bool isDistributed() { return GetSize()>1; }; static int GetRank() { return MPI::COMM_WORLD.Get_rank(); Loading Loading @@ -121,6 +155,9 @@ namespace Communicators { }; MPI::Request MpiCommunicator::NullRequest; std::streambuf *MpiCommunicator::psbuf; std::streambuf *MpiCommunicator::backup; std::ofstream MpiCommunicator::filestr; }//namespace Communicators } // namespace TNL Loading
src/TNL/Communicators/NoDistrCommunicator.h +14 −4 Original line number Diff line number Diff line Loading @@ -22,7 +22,12 @@ namespace Communicators { typedef int Request; static Request NullRequest; static void Init(int argc, char **argv) static bool isAvailable() { return true; } static void Init(int argc, char **argv, bool redirect=false) { NullRequest=-1; }; Loading @@ -36,6 +41,11 @@ namespace Communicators { return true; }; static bool isDistributed() { return false; }; static int GetRank() { return 0; Loading @@ -62,13 +72,13 @@ namespace Communicators { static Request ISend( const T *data, int count, int dest) { return 1; } }; template <typename T> static Request IRecv( const T *data, int count, int src) { return 1; } }; static void WaitAll(Request *reqs, int length) { Loading @@ -77,7 +87,7 @@ namespace Communicators { template< typename T > static void Bcast( T& data, int count, int root) { } }; /* template< typename T > static void Allreduce( T& data, Loading