From be349bed8a8c86e66a342c698ea94dfa8de57726 Mon Sep 17 00:00:00 2001 From: Ralf Hartmann Date: Wed, 26 May 2004 16:57:00 +0000 Subject: [PATCH] Simplify by using the ConditionalOStream pout. git-svn-id: https://svn.dealii.org/trunk@9336 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/examples/step-17/step-17.cc | 79 ++++++++++++++++------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/deal.II/examples/step-17/step-17.cc b/deal.II/examples/step-17/step-17.cc index 357060eaee..ce3a2ace8d 100644 --- a/deal.II/examples/step-17/step-17.cc +++ b/deal.II/examples/step-17/step-17.cc @@ -38,9 +38,17 @@ #include #include - // And here come the things that we need - // particularly for this example program and - // that weren't in step-8. First, we are + // And here come the things that we + // need particularly for this example + // program and that weren't in + // step-8. First, we replace the + // standard output ``std::cout'' by a + // new stream ``pout'' which is used + // in parallel computations for + // generating output only on one of + // the processes. +#include + // Then, we are // going to replace all linear algebra // components that involve the (global) // linear system by classes that wrap @@ -1203,25 +1211,31 @@ void ElasticProblem::refine_grid () - // Lastly, here is the driver function. It is - // almost unchanged from step-8, with the - // exception that we make sure that output is - // only generated from the first process (by - // checking that ``this_mpi_process'' equals - // zero), to avoid getting the same lines of - // output over and over again, once per - // process. Apart from this, the only other - // cosmetic change is that we output how many - // degrees of freedom there are per process, - // and how many iterations it took for the + // Lastly, here is the driver + // function. It is almost unchanged + // from step-8, with the exception + // that we replace ``std::cout'' by + // the ``pout'' stream. By setting + // its condition to + // ``this_mpi_process==0'', we make + // sure that output is only generated + // from the first process and that we + // don't get the same lines of output + // over and over again, once per + // process. Apart from this, the only + // other cosmetic change is that we + // output how many degrees of freedom + // there are per process, and how + // many iterations it took for the // linear solver to converge: template void ElasticProblem::run () { + pout.set_condition(this_mpi_process == 0); + for (unsigned int cycle=0; cycle<10; ++cycle) { - if (this_mpi_process == 0) - std::cout << "Cycle " << cycle << ':' << std::endl; + pout << "Cycle " << cycle << ':' << std::endl; if (cycle == 0) { @@ -1231,32 +1245,27 @@ void ElasticProblem::run () else refine_grid (); - if (this_mpi_process == 0) - std::cout << " Number of active cells: " - << triangulation.n_active_cells() - << std::endl; + pout << " Number of active cells: " + << triangulation.n_active_cells() + << std::endl; setup_system (); - if (this_mpi_process == 0) - { - std::cout << " Number of degrees of freedom: " - << dof_handler.n_dofs() - << " (by partition:"; - for (unsigned int p=0; p