Skip to content
Snippets Groups Projects
Commit 7bea8d2b authored by Norihiro Watanabe's avatar Norihiro Watanabe
Browse files

add Logog Cout which allows one computing core (rank 0) to print the log

parent 1a505299
No related branches found
No related tags found
No related merge requests found
/**
* \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
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment