From 9c061e9d846262af36528481e0df59a1fa8d4884 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Tue, 8 Mar 2011 12:06:47 +0100 Subject: [PATCH] MPI: redirect output for ranks>0 to file changes to main.cpp: read global command line arguments first to allow for immediate output redirection Signed-off-by: Thorsten Liebig --- FDTD/openems_fdtd_mpi.cpp | 15 +++++++++++++++ FDTD/openems_fdtd_mpi.h | 3 +++ main.cpp | 10 +++++++--- matlab/RunOpenEMS_MPI.m | 8 ++++++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/FDTD/openems_fdtd_mpi.cpp b/FDTD/openems_fdtd_mpi.cpp index 4c9c16f..3b1d570 100644 --- a/FDTD/openems_fdtd_mpi.cpp +++ b/FDTD/openems_fdtd_mpi.cpp @@ -60,6 +60,19 @@ openEMS_FDTD_MPI::openEMS_FDTD_MPI() : openEMS() } m_Original_Grid = NULL; + + //redirect output to file for all ranks > 0 + if ((m_MyID>0) && (g_settings.GetVerboseLevel()==0)) + { + stringstream out_name; + out_name << "ID" << m_MyID << "_" << "output.txt"; + m_Output = new ofstream(); + m_Output->open(out_name.str().c_str()); + cout.rdbuf(m_Output->rdbuf()); + cerr.rdbuf(m_Output->rdbuf()); + } + else + m_Output = NULL; } openEMS_FDTD_MPI::~openEMS_FDTD_MPI() @@ -70,6 +83,8 @@ openEMS_FDTD_MPI::~openEMS_FDTD_MPI() m_Energy_Buffer = NULL; delete m_Original_Grid; m_Original_Grid = NULL; + delete m_Output; + m_Output=NULL; } bool openEMS_FDTD_MPI::parseCommandLineArgument( const char *argv ) diff --git a/FDTD/openems_fdtd_mpi.h b/FDTD/openems_fdtd_mpi.h index dd38bfd..efa84fe 100644 --- a/FDTD/openems_fdtd_mpi.h +++ b/FDTD/openems_fdtd_mpi.h @@ -58,6 +58,9 @@ protected: double CalcEnergy(); virtual bool SetupProcessing(); + + //output redirection to file for ranks > 0 + ofstream* m_Output; }; #endif // OPENEMS_FDTD_MPI_H diff --git a/main.cpp b/main.cpp index bc64168..ea3101d 100644 --- a/main.cpp +++ b/main.cpp @@ -38,6 +38,13 @@ using namespace std; int main(int argc, char *argv[]) { + //read global command line arguments first + for (int n=2; n