Skip to content
Snippets Groups Projects
Commit be2c0161 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

write only rank 0 in parallel

parent e07d2372
No related branches found
No related tags found
2 merge requests!77WIP: Solver and Preconditioners for istl backend,!71write only rank 0 in parallel
......@@ -14,14 +14,11 @@
#include <stdexcept>
#endif
#ifdef HAVE_MPI
#include <mpi.h>
#endif
/// Use the formatting librart fmtlib::fmt
#include <fmt/core.h>
#include <fmt/ostream.h>
#include <amdis/Environment.hpp>
#include <amdis/common/TypeTraits.hpp>
/**
......@@ -59,21 +56,20 @@ namespace AMDiS
namespace Impl
{
template <class OStream, class... Args>
OStream& msg(OStream& out, Args&&... args)
OStream& msg(OStream& out, bool lineBreak, Args&&... args)
{
#ifdef AMDIS_HAS_MPI
int rank = -1;
int num_ranks = -1;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_ranks);
if (num_ranks > 1 && rank == 0) {
#if HAVE_MPI
if (Environment::mpiSize() > 1 && Environment::mpiRank() == 0) {
out << "[0] ";
fmt::print(out, FWD(args)...);
} else if (num_ranks == 1) {
if (lineBreak) { out << std::endl; }
} else if (Environment::mpiSize() == 1) {
fmt::print(out, FWD(args)...);
if (lineBreak) { out << std::endl; }
}
#else
fmt::print(out, FWD(args)...);
if (lineBreak) { out << std::endl; }
#endif
return out;
}
......@@ -91,7 +87,7 @@ namespace AMDiS
template <class... Args>
void msg(Args&&... args)
{
Impl::msg(std::cout, FWD(args)...) << std::endl;
Impl::msg(std::cout, true, FWD(args)...);
}
......@@ -105,7 +101,7 @@ namespace AMDiS
template <class... Args>
void msg_(Args&&... args)
{
Impl::msg(std::cout, FWD(args)...);
Impl::msg(std::cout, false, FWD(args)...);
}
......@@ -119,7 +115,7 @@ namespace AMDiS
void error_exit(Args&&... args)
{
#ifdef AMDIS_NO_THROW
Impl::msg(std::cerr << "ERROR: ", FWD(args)...) << std::endl;
Impl::msg(std::cerr << "ERROR: ", true, FWD(args)...);
#ifndef NDEBUG
assert(false);
#else
......@@ -150,7 +146,7 @@ namespace AMDiS
template <class... Args>
void warning(Args&&... args)
{
Impl::msg(std::cout << "WARNING: ", FWD(args)...) << std::endl;
Impl::msg(std::cout << "WARNING: ", true, FWD(args)...);
}
......
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