From 7bea8d2b64ce66516f4c9127ee46e2adf281069c Mon Sep 17 00:00:00 2001 From: Norihiro Watanabe <norihiro.watanabe@ufz.de> Date: Wed, 15 Oct 2014 17:33:11 +0200 Subject: [PATCH] add Logog Cout which allows one computing core (rank 0) to print the log --- BaseLib/LogogCustomCout.h | 49 +++++++++++++++++++++++++++++++++++++++ Tests/testrunner.cpp | 18 ++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 BaseLib/LogogCustomCout.h diff --git a/BaseLib/LogogCustomCout.h b/BaseLib/LogogCustomCout.h new file mode 100644 index 00000000000..9cfdc152ec8 --- /dev/null +++ b/BaseLib/LogogCustomCout.h @@ -0,0 +1,49 @@ +/** + * \copyright + * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef LOGOGCUSTOMCOUT_H_ +#define LOGOGCUSTOMCOUT_H_ + +#include "logog/include/logog.hpp" + +#ifdef USE_MPI +#include <mpi.h> +#endif + +namespace BaseLib +{ + +/// Custom target for logog output +class LogogCustomCout : public logog::Target +{ +public: +#ifdef USE_MPI + LogogCustomCout(MPI_Comm mpi_comm) + { + MPI_Comm_rank(mpi_comm, &_mpi_rank); + } +#endif + + virtual int Output( const LOGOG_STRING &data ) + { +#ifdef USE_MPI + if (_mpi_rank == 0) +#endif + LOGOG_COUT << (const LOGOG_CHAR *)data; + return 0; + } + +#ifdef USE_MPI + int _mpi_rank; +#endif +}; + +#endif // LOGOGCUSTOMCOUT_H_ + +} // namespace BaseLib diff --git a/Tests/testrunner.cpp b/Tests/testrunner.cpp index c66b003e74c..e806c85704f 100644 --- a/Tests/testrunner.cpp +++ b/Tests/testrunner.cpp @@ -16,6 +16,10 @@ #include "gtest/gtest.h" #include "logog/include/logog.hpp" +#ifdef USE_MPI +#include <mpi.h> +#endif + #ifdef USE_LIS #include <lis.h> #endif @@ -24,6 +28,7 @@ #include <petscksp.h> #endif +#include "BaseLib/LogogCustomCout.h" #include "BaseLib/TemplateLogogFormatterSuppressedGCC.h" #ifdef QT4_FOUND #include <QApplication> @@ -33,12 +38,17 @@ int main(int argc, char* argv[]) { #ifdef QT4_FOUND - QApplication app(argc, argv, false); + QApplication app(argc, argv, false); #endif int ret = 0; LOGOG_INITIALIZE(); { - logog::Cout out; +#ifdef USE_MPI + MPI_Init(&argc, &argv); + BaseLib::LogogCustomCout out(MPI_COMM_WORLD); +#else + BaseLib::LogogCustomCout out; +#endif BaseLib::TemplateLogogFormatterSuppressedGCC<TOPIC_LEVEL_FLAG | TOPIC_FILE_NAME_FLAG | TOPIC_LINE_NUMBER_FLAG> custom_format; out.SetFormatter(custom_format); @@ -78,6 +88,10 @@ int main(int argc, char* argv[]) PetscFinalize(); #endif +#ifdef USE_MPI + MPI_Finalize(); +#endif + } // make sure no logog objects exist when LOGOG_SHUTDOWN() is called. LOGOG_SHUTDOWN(); -- GitLab