Skip to content

Commit

Permalink
removing most cases of pcout and deleting timer object. The timer obj…
Browse files Browse the repository at this point in the history
…ect should be its own class like we do for conditional ostreams.

There are still somes cases where std::cout should be replaced with the pout_base of an assertion
  • Loading branch information
landinjm committed Jan 15, 2025
1 parent 7a2e97a commit dc3507f
Show file tree
Hide file tree
Showing 21 changed files with 236 additions and 283 deletions.
23 changes: 8 additions & 15 deletions include/core/ParseCommandLineOpts.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <deal.II/base/mpi.h>

#include <algorithm>
#include <core/conditional_ostreams.h>
#include <fstream>
#include <iostream>
#include <string>
Expand All @@ -29,11 +30,8 @@ class ParseCommandLineOpts
if (cmdOptionExists("-i"))
{
parameters_filename = getCmdOption("-i");
if (dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
{
std::cout << "Using the input parameter file: " << parameters_filename
<< std::endl;
}
conditionalOStreams::pout_base
<< "Using the input parameter file: " << parameters_filename << std::endl;
}
else
{
Expand All @@ -52,11 +50,8 @@ class ParseCommandLineOpts
throw("The previous extension .in for the parameters file is no "
"longer accepted. Please rename parameters.in as "
"parameters.prm");
if (dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
{
std::cout << "Using the input parameter file: " << parameters_filename
<< std::endl;
}
conditionalOStreams::pout_base
<< "Using the input parameter file: " << parameters_filename << std::endl;
}
else
{
Expand All @@ -72,11 +67,9 @@ class ParseCommandLineOpts
if (!ifs_prm && ifs_in)
throw("The previous extension .in for the parameters file is no longer "
"accepted. Please rename parameters.in as parameters.prm");
if (dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
{
std::cout << "Using the input parameter file: " << parameters_filename
<< std::endl;
}

conditionalOStreams::pout_base
<< "Using the input parameter file: " << parameters_filename << std::endl;
}
else
{
Expand Down
8 changes: 0 additions & 8 deletions include/core/matrixFreePDE.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ class MatrixFreePDE : public Subscriptor
void
buildFields();

/**
* \brief Parallel message stream.
*/
ConditionalOStream pcout;

/**
* \brief Set the initial condition for all fields. This function is overriden in each
* application.
Expand Down Expand Up @@ -421,9 +416,6 @@ class MatrixFreePDE : public Subscriptor
unsigned int currentIncrement, currentOutput, currentCheckpoint,
current_grain_reassignment;

/*Timer and logging object*/
mutable TimerOutput computing_timer;

bool first_integrated_var_output_complete;

// Methods and variables for integration
Expand Down
59 changes: 32 additions & 27 deletions include/core/temp_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <deal.II/numerics/data_out.h>
#include <deal.II/numerics/vector_tools.h>

#include <core/conditional_ostreams.h>
#include <core/matrix_free_operator.h>
#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -71,9 +72,7 @@ class LaplaceProblem
LinearAlgebra::distributed::Vector<double> solution;
LinearAlgebra::distributed::Vector<double> system_rhs;

double setup_time {};
ConditionalOStream pcout;
ConditionalOStream time_details;
double setup_time {};
};

template <int dim>
Expand All @@ -84,8 +83,6 @@ LaplaceProblem<dim>::LaplaceProblem()
parallel::distributed::Triangulation<dim>::construct_multigrid_hierarchy)
, fe(degree_finite_element)
, dof_handler(triangulation)
, pcout(std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
, time_details(std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
{}

template <int dim>
Expand All @@ -101,7 +98,8 @@ LaplaceProblem<dim>::setup_system()
dof_handler.distribute_dofs(fe);
dof_handler.distribute_mg_dofs();

pcout << "Number of degrees of freedom: " << dof_handler.n_dofs() << std::endl;
conditionalOStreams::pout_base
<< "Number of degrees of freedom: " << dof_handler.n_dofs() << std::endl;

constraints.clear();
constraints.reinit(dof_handler.locally_owned_dofs(),
Expand All @@ -115,8 +113,9 @@ LaplaceProblem<dim>::setup_system()
constraints.close();
}
setup_time += time.wall_time();
time_details << "Distribute DoFs & B.C. (CPU/wall) " << time.cpu_time() << "s/"
<< time.wall_time() << 's' << std::endl;
conditionalOStreams::pout_base << "Distribute DoFs & B.C. (CPU/wall) "
<< time.cpu_time() << "s/" << time.wall_time() << 's'
<< std::endl;
time.restart();
{
{
Expand All @@ -139,8 +138,9 @@ LaplaceProblem<dim>::setup_system()
system_matrix.initialize_dof_vector(system_rhs);
}
setup_time += time.wall_time();
time_details << "Setup matrix-free system (CPU/wall) " << time.cpu_time() << "s/"
<< time.wall_time() << 's' << std::endl;
conditionalOStreams::pout_base << "Setup matrix-free system (CPU/wall) "
<< time.cpu_time() << "s/" << time.wall_time() << 's'
<< std::endl;
time.restart();

{
Expand Down Expand Up @@ -182,8 +182,9 @@ LaplaceProblem<dim>::setup_system()
}
}
setup_time += time.wall_time();
time_details << "Setup matrix-free levels (CPU/wall) " << time.cpu_time() << "s/"
<< time.wall_time() << 's' << std::endl;
conditionalOStreams::pout_base << "Setup matrix-free levels (CPU/wall) "
<< time.cpu_time() << "s/" << time.wall_time() << 's'
<< std::endl;
}

template <int dim>
Expand All @@ -208,8 +209,9 @@ LaplaceProblem<dim>::assemble_rhs()
system_rhs.compress(VectorOperation::add);

setup_time += time.wall_time();
time_details << "Assemble right hand side (CPU/wall) " << time.cpu_time() << "s/"
<< time.wall_time() << 's' << std::endl;
conditionalOStreams::pout_base << "Assemble right hand side (CPU/wall) "
<< time.cpu_time() << "s/" << time.wall_time() << 's'
<< std::endl;
}

template <int dim>
Expand All @@ -220,8 +222,8 @@ LaplaceProblem<dim>::solve()
MGTransferMatrixFree<dim, float> mg_transfer(mg_constrained_dofs);
mg_transfer.build(dof_handler);
setup_time += time.wall_time();
time_details << "MG build transfer time (CPU/wall) " << time.cpu_time() << "s/"
<< time.wall_time() << "s\n";
conditionalOStreams::pout_base << "MG build transfer time (CPU/wall) "
<< time.cpu_time() << "s/" << time.wall_time() << "s\n";
time.restart();

using SmootherType =
Expand Down Expand Up @@ -280,9 +282,10 @@ LaplaceProblem<dim>::solve()
SolverControl solver_control(100, 1e-12 * system_rhs.l2_norm());
SolverCG<LinearAlgebra::distributed::Vector<double>> cg(solver_control);
setup_time += time.wall_time();
time_details << "MG build smoother time (CPU/wall) " << time.cpu_time() << "s/"
<< time.wall_time() << "s\n";
pcout << "Total setup time (wall) " << setup_time << "s\n";
conditionalOStreams::pout_base << "MG build smoother time (CPU/wall) "
<< time.cpu_time() << "s/" << time.wall_time() << "s\n";
conditionalOStreams::pout_base << "Total setup time (wall) " << setup_time
<< "s\n";

time.reset();
time.start();
Expand All @@ -291,9 +294,10 @@ LaplaceProblem<dim>::solve()

constraints.distribute(solution);

pcout << "Time solve (" << solver_control.last_step() << " iterations)"
<< (solver_control.last_step() < 10 ? " " : " ") << "(CPU/wall) "
<< time.cpu_time() << "s/" << time.wall_time() << "s\n";
conditionalOStreams::pout_base
<< "Time solve (" << solver_control.last_step() << " iterations)"
<< (solver_control.last_step() < 10 ? " " : " ") << "(CPU/wall) " << time.cpu_time()
<< "s/" << time.wall_time() << "s\n";
}

template <int dim>
Expand All @@ -318,8 +322,8 @@ LaplaceProblem<dim>::output_results(unsigned int cycle) const
data_out.set_flags(flags);
data_out.write_vtu_with_pvtu_record("./", "solution", cycle, MPI_COMM_WORLD, 3);

time_details << "Time write output (CPU/wall) " << time.cpu_time() << "s/"
<< time.wall_time() << "s\n";
conditionalOStreams::pout_base << "Time write output (CPU/wall) "
<< time.cpu_time() << "s/" << time.wall_time() << "s\n";
}

template <int dim>
Expand All @@ -330,9 +334,10 @@ LaplaceProblem<dim>::run()
const unsigned int n_vect_doubles = VectorizedArray<double>::size();
const unsigned int n_vect_bits = 8 * sizeof(double) * n_vect_doubles;

pcout << "Vectorization over " << n_vect_doubles << " doubles = " << n_vect_bits
<< " bits (" << Utilities::System::get_current_vectorization_level() << ')'
<< std::endl;
conditionalOStreams::pout_base
<< "Vectorization over " << n_vect_doubles << " doubles = " << n_vect_bits
<< " bits (" << Utilities::System::get_current_vectorization_level() << ')'
<< std::endl;
}

GridGenerator::hyper_cube(triangulation, 0.0, 1.0);
Expand Down
4 changes: 1 addition & 3 deletions include/core/userInputParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,7 @@ class userInputParameters
const std::string &elastic_const_symmetry) const;

dealii::Tensor<2, 2 * dim - 1 + dim / 3>
getCIJMatrix(const elasticityModel model,
const std::vector<double> &constants,
dealii::ConditionalOStream &pcout) const;
getCIJMatrix(const elasticityModel model, const std::vector<double> &constants) const;

// Private nucleation variables
std::vector<nucleationParameters<dim>> nucleation_parameters_list;
Expand Down
6 changes: 3 additions & 3 deletions src/core/boundary_conditions/boundaryConditions.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// methods to apply boundary conditons

#include <core/boundary_conditions/nonUniformDirichletBC.h>
#include <core/boundary_conditions/varBCs.h>
#include <core/boundary_conditions/vectorBCFunction.h>
#include <core/conditional_ostreams.h>
#include <core/matrixFreePDE.h>

// =================================================================================
Expand Down Expand Up @@ -236,7 +235,8 @@ MatrixFreePDE<dim, degree>::setPeriodicity()
}

triangulation.add_periodicity(periodicity_vector);
pcout << "periodic facepairs: " << periodicity_vector.size() << std::endl;
conditionalOStreams::pout_base << "periodic facepairs: " << periodicity_vector.size()
<< std::endl;
}

// Set constraints to enforce periodic boundary conditions
Expand Down
7 changes: 3 additions & 4 deletions src/core/checkpoint.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>

#include <core/conditional_ostreams.h>
#include <core/exceptions.h>
#include <core/matrixFreePDE.h>
#include <filesystem>
Expand All @@ -15,7 +16,6 @@ template <int dim, int degree>
void
MatrixFreePDE<dim, degree>::save_checkpoint()
{
computing_timer.enter_subsection("matrixFreePDE: save_checkpoint");
unsigned int my_id = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);

if (my_id == 0)
Expand Down Expand Up @@ -118,8 +118,7 @@ MatrixFreePDE<dim, degree>::save_checkpoint()
time_info_file.close();
}

pcout << "*** Checkpoint created! ***\n\n";
computing_timer.leave_subsection("matrixFreePDE: save_checkpoint");
conditionalOStreams::pout_base << "*** Checkpoint created! ***\n\n";
}

// Load from a previously created checkpoint
Expand All @@ -132,7 +131,7 @@ MatrixFreePDE<dim, degree>::load_checkpoint_triangulation()
verify_checkpoint_file_exists("restart.mesh");
verify_checkpoint_file_exists("restart.mesh.info");

pcout << "\n*** Resuming from a checkpoint! ***\n\n";
conditionalOStreams::pout_base << "\n*** Resuming from a checkpoint! ***\n\n";

try
{
Expand Down
Loading

0 comments on commit dc3507f

Please sign in to comment.