OpenLB 1.7
Loading...
Searching...
No Matches
ostreamManager.cpp
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2011 Lukas Baron, Mathias Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#include "ostreamManager.h"
25#include "core/singleton.h"
26
29
30namespace olb {
31
32bool OMBuf::multiOutput = 0;
33
35 : output(nullptr), text("")
36{ }
37
40
42 : output(rhs.output), text(rhs.text)
43{ }
44
46{
47 output = rhs.output;
48 text = rhs.text;
49
50 return *this;
51}
52
53OMBuf::OMBuf(std::ostream& str, std::string classname)
54 : output(&str), text(classname)
55{ }
56
58{
59 (*this).multiOutput = b;
60}
61
63{
64#ifdef PARALLEL_MODE_MPI
65 #ifdef PARALLEL_MODE_OMP
66 if (multiOutput==true) {
67 *output << "["
68 << text << ":" << singleton::mpi().getRank()
69 << ":" << singleton::omp().getRank()
70 << "] " << str();
71 }
72 else { // multiOutput==false
73 if (singleton::mpi().getRank() == 0 && singleton::omp().getRank() == 0) {
74 *output << "[" << text << "] " << str();
75 }
76 }
77 #else
78 if (multiOutput==true) {
79 *output << "["
80 << text << ":" << singleton::mpi().getRank()
81 << "] " << str();
82 }
83 else { // multiOutput==false
84 if (singleton::mpi().getRank()==0) {
85 *output << "[" << text << "] " << str();
86 }
87 }
88 #endif
89#elif PARALLEL_MODE_OMP
90 if (multiOutput==true) {
91 *output << "["
92 << text << ":" << singleton::omp().getRank()
93 << "] " << str();
94 }
95 else { // multiOutput==false
96 if (singleton::omp().getRank()==0) {
97 *output << "[" << text << "] " << str();
98 }
99 }
100#else
101 *output << "[" << text << "] " << str();
102#endif
103 str("");
104 output->flush();
105 return 0;
106}
107
108// class OstreamManager /////////////////////////////////
109
110OstreamManager::OstreamManager(std::string classname)
111 : std::ostream(&buffer), buffer(std::cout, classname)
112{ }
113
114OstreamManager::OstreamManager(std::ostream& str, std::string classname)
115 : std::ostream(&buffer), buffer(str, classname)
116{ }
117
119 : std::ostream(&buffer), buffer(rhs.buffer)
120{ }
121
123{
124 buffer = rhs.buffer;
125 return *this;
126}
127
129{
130 buffer.setMultiOutput(b);
131}
132
133}
userdefined stream buffer for OstreamManager
void setMultiOutput(bool b)
~OMBuf() override
OMBuf & operator=(const OMBuf &rhs)
int sync() override
sync the stream with the output:
class for marking output with some text
OstreamManager & operator=(const OstreamManager &rhs)
OstreamManager(std::string classname)
constructor that uses std::cout by default
void setMultiOutput(bool b)
enable message output for all MPI processes, disabled by default
int getRank() const
Returns the process ID.
Wrapper functions that simplify the use of MPI.
MpiManager & mpi()
ompManager omp()
Top level namespace for all of OpenLB.
Definition of singletons: global, publicly available information.
int getRank() const