A class that allows printing to an output stream, e.g.
std::cout, depending on the ConditionalOStream object being active (default) or not. The condition of this object can be changed by set_condition() and in the constructor. This class is used in the step-17, step-18, step-32, step-33, and step-35 tutorial programs.
This class is mostly useful in parallel computations. Ordinarily, you would use
std::cout to print messages like what the program is presently doing, or the number of degrees of freedom in each step. However, in parallel programs, this means that each of the MPI processes write to the screen, which yields many repetitions of the same text. To avoid it, one would have to have a designated process, say the one with MPI process number zero, do the output, and guard each write statement with an if- condition. This becomes cumbersome and clutters up the code. Rather than doing so, the present class can be used: objects of its type act just like a standard output stream, but they only print something based on a condition that can be set to, for example,
mpi_process==0, so that only one process has a true condition and in all other processes writes to this object just disappear in nirvana.
The usual usage of this class is as follows:
std::cout << "Reading parameter file on process "
pout << "Solving ..." << std::endl;
pout << "done" << std::endl;
Here, `Reading parameter file on process xy' is printed by each process separately. In contrast to that, `Solving ...' and `done' is printed to standard output only once, namely by process 0.
This class is not derived from ostream. Therefore
is not possible. Instead use the is_active() function for a work- around:
- Ralf Hartmann, Wolfgang Bangerth, 2004
Definition at line 83 of file conditional_ostream.h.