Skip to content

Commit 659bb2a

Browse files
authored
Merge pull request geodynamics#2087 from bangerth/scoped-timers
Use scoped timers.
2 parents 4e0a02a + ca339c5 commit 659bb2a

File tree

6 files changed

+114
-144
lines changed

6 files changed

+114
-144
lines changed

source/simulator/assembly.cc

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ namespace aspect
396396
if (parameters.use_direct_stokes_solver)
397397
return;
398398

399-
computing_timer.enter_section (" Build Stokes preconditioner");
399+
TimerOutput::Scope timer (computing_timer, " Build Stokes preconditioner");
400400
pcout << " Rebuilding Stokes preconditioner..." << std::flush;
401401

402402
// first assemble the raw matrices necessary for the preconditioner
@@ -457,10 +457,10 @@ namespace aspect
457457
rebuild_stokes_preconditioner = false;
458458

459459
pcout << std::endl;
460-
computing_timer.exit_section();
461460
}
462461

463462

463+
464464
template <int dim>
465465
void
466466
Simulator<dim>::
@@ -608,17 +608,15 @@ namespace aspect
608608
template <int dim>
609609
void Simulator<dim>::assemble_stokes_system ()
610610
{
611-
if (!assemble_newton_stokes_system)
612-
computing_timer.enter_section (" Assemble Stokes system");
613-
else if (assemble_newton_stokes_matrix)
614-
{
615-
if (newton_handler->get_newton_derivative_scaling_factor() == 0)
616-
computing_timer.enter_section (" Assemble Stokes system picard");
617-
else
618-
computing_timer.enter_section (" Assemble Stokes system newton");
619-
}
620-
else
621-
computing_timer.enter_section (" Assemble Stokes system rhs");
611+
TimerOutput::Scope timer (computing_timer,
612+
(!assemble_newton_stokes_system ?
613+
" Assemble Stokes system" :
614+
(assemble_newton_stokes_matrix ?
615+
(newton_handler->get_newton_derivative_scaling_factor() == 0 ?
616+
" Assemble Stokes system picard" :
617+
" Assemble Stokes system newton")
618+
:
619+
" Assemble Stokes system rhs")));
622620

623621
if (rebuild_stokes_matrix == true)
624622
system_matrix = 0;
@@ -719,39 +717,25 @@ namespace aspect
719717

720718
// record that we have just rebuilt the matrix
721719
rebuild_stokes_matrix = false;
722-
723-
computing_timer.exit_section();
724720
}
725721

722+
723+
726724
template <int dim>
727725
void
728726
Simulator<dim>::build_advection_preconditioner(const AdvectionField &advection_field,
729727
LinearAlgebra::PreconditionILU &preconditioner)
730728
{
731-
switch (advection_field.field_type)
732-
{
733-
case AdvectionField::temperature_field:
734-
{
735-
computing_timer.enter_section (" Build temperature preconditioner");
736-
break;
737-
}
738-
739-
case AdvectionField::compositional_field:
740-
{
741-
computing_timer.enter_section (" Build composition preconditioner");
742-
break;
743-
}
744-
745-
default:
746-
Assert (false, ExcNotImplemented());
747-
}
729+
TimerOutput::Scope timer (computing_timer, (advection_field.is_temperature() ?
730+
" Build temperature preconditioner" :
731+
" Build composition preconditioner"));
748732

749733
const unsigned int block_idx = advection_field.block_index(introspection);
750734
preconditioner.initialize (system_matrix.block(block_idx, block_idx));
751-
computing_timer.exit_section();
752735
}
753736

754737

738+
755739
template <int dim>
756740
void Simulator<dim>::
757741
local_assemble_advection_system (const AdvectionField &advection_field,
@@ -1008,10 +992,9 @@ namespace aspect
1008992
template <int dim>
1009993
void Simulator<dim>::assemble_advection_system (const AdvectionField &advection_field)
1010994
{
1011-
if (advection_field.is_temperature())
1012-
computing_timer.enter_section (" Assemble temperature system");
1013-
else
1014-
computing_timer.enter_section (" Assemble composition system");
995+
TimerOutput::Scope timer (computing_timer, (advection_field.is_temperature() ?
996+
" Assemble temperature system" :
997+
" Assemble composition system"));
1015998

1016999
const unsigned int block_idx = advection_field.block_index(introspection);
10171000

@@ -1111,8 +1094,6 @@ namespace aspect
11111094

11121095
system_matrix.compress(VectorOperation::add);
11131096
system_rhs.compress(VectorOperation::add);
1114-
1115-
computing_timer.exit_section();
11161097
}
11171098
}
11181099

source/simulator/checkpoint_restart.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace aspect
7171
template <int dim>
7272
void Simulator<dim>::create_snapshot()
7373
{
74-
computing_timer.enter_section ("Create snapshot");
74+
TimerOutput::Scope timer (computing_timer, "Create snapshot");
7575
unsigned int my_id = Utilities::MPI::this_mpi_process (mpi_communicator);
7676

7777
if (my_id == 0)
@@ -189,7 +189,6 @@ namespace aspect
189189
}
190190

191191
pcout << "*** Snapshot created!" << std::endl << std::endl;
192-
computing_timer.exit_section();
193192
}
194193

195194

source/simulator/core.cc

Lines changed: 84 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ namespace aspect
220220
print_aspect_header(log_file_stream);
221221
}
222222

223-
computing_timer.enter_section("Initialization");
223+
224+
// now that we have output set up, we can start timer sections
225+
TimerOutput::Scope timer (computing_timer, "Initialization");
224226

225227
// first do some error checking for the parameters we got
226228
{
@@ -652,8 +654,6 @@ namespace aspect
652654
// now that all member variables have been set up, also
653655
// connect the functions that will actually do the assembly
654656
set_assemblers();
655-
656-
computing_timer.exit_section();
657657
}
658658

659659

@@ -1258,7 +1258,7 @@ namespace aspect
12581258
{
12591259
signals.edit_parameters_pre_setup_dofs(*this, parameters);
12601260

1261-
computing_timer.enter_section("Setup dof systems");
1261+
TimerOutput::Scope timer (computing_timer, "Setup dof systems");
12621262

12631263
dof_handler.distribute_dofs(finite_element);
12641264

@@ -1390,9 +1390,6 @@ namespace aspect
13901390

13911391
rebuild_stokes_matrix = true;
13921392
rebuild_stokes_preconditioner = true;
1393-
1394-
1395-
computing_timer.exit_section();
13961393
}
13971394

13981395

@@ -1463,7 +1460,7 @@ namespace aspect
14631460
template <int dim>
14641461
void Simulator<dim>::postprocess ()
14651462
{
1466-
computing_timer.enter_section ("Postprocessing");
1463+
TimerOutput::Scope timer (computing_timer, "Postprocessing");
14671464
pcout << " Postprocessing:" << std::endl;
14681465

14691466
// run all the postprocessing routines and then write
@@ -1501,108 +1498,109 @@ namespace aspect
15011498

15021499
// finally, write the entire set of current results to disk
15031500
output_statistics();
1504-
1505-
computing_timer.exit_section ();
15061501
}
15071502

15081503

15091504
template <int dim>
15101505
void Simulator<dim>::refine_mesh (const unsigned int max_grid_level)
15111506
{
1512-
computing_timer.enter_section ("Refine mesh structure, part 1");
1507+
parallel::distributed::SolutionTransfer<dim,LinearAlgebra::BlockVector>
1508+
system_trans(dof_handler);
15131509

1514-
Vector<float> estimated_error_per_cell (triangulation.n_active_cells());
1515-
mesh_refinement_manager.execute (estimated_error_per_cell);
1510+
std_cxx11::unique_ptr<parallel::distributed::SolutionTransfer<dim,LinearAlgebra::Vector> >
1511+
freesurface_trans;
15161512

1517-
if (parameters.adapt_by_fraction_of_cells)
1518-
parallel::distributed::GridRefinement::
1519-
refine_and_coarsen_fixed_number (triangulation,
1520-
estimated_error_per_cell,
1521-
parameters.refinement_fraction,
1522-
parameters.coarsening_fraction);
1523-
else
1524-
parallel::distributed::GridRefinement::
1525-
refine_and_coarsen_fixed_fraction (triangulation,
1526-
estimated_error_per_cell,
1527-
parameters.refinement_fraction,
1528-
parameters.coarsening_fraction);
1513+
{
1514+
TimerOutput::Scope timer (computing_timer, "Refine mesh structure, part 1");
15291515

1530-
mesh_refinement_manager.tag_additional_cells ();
1516+
Vector<float> estimated_error_per_cell (triangulation.n_active_cells());
1517+
mesh_refinement_manager.execute (estimated_error_per_cell);
15311518

1519+
if (parameters.adapt_by_fraction_of_cells)
1520+
parallel::distributed::GridRefinement::
1521+
refine_and_coarsen_fixed_number (triangulation,
1522+
estimated_error_per_cell,
1523+
parameters.refinement_fraction,
1524+
parameters.coarsening_fraction);
1525+
else
1526+
parallel::distributed::GridRefinement::
1527+
refine_and_coarsen_fixed_fraction (triangulation,
1528+
estimated_error_per_cell,
1529+
parameters.refinement_fraction,
1530+
parameters.coarsening_fraction);
15321531

1533-
// clear refinement flags if parameter.refinement_fraction=0.0
1534-
if (parameters.refinement_fraction==0.0)
1535-
{
1536-
for (typename Triangulation<dim>::active_cell_iterator
1537-
cell = triangulation.begin_active();
1538-
cell != triangulation.end(); ++cell)
1539-
cell->clear_refine_flag ();
1540-
}
1541-
else
1542-
{
1543-
// limit maximum refinement level
1544-
if (triangulation.n_levels() > max_grid_level)
1532+
mesh_refinement_manager.tag_additional_cells ();
1533+
1534+
1535+
// clear refinement flags if parameter.refinement_fraction=0.0
1536+
if (parameters.refinement_fraction==0.0)
1537+
{
15451538
for (typename Triangulation<dim>::active_cell_iterator
1546-
cell = triangulation.begin_active(max_grid_level);
1539+
cell = triangulation.begin_active();
15471540
cell != triangulation.end(); ++cell)
15481541
cell->clear_refine_flag ();
1549-
}
1550-
1551-
// clear coarsening flags if parameter.coarsening_fraction=0.0
1552-
if (parameters.coarsening_fraction==0.0)
1553-
{
1554-
for (typename Triangulation<dim>::active_cell_iterator
1555-
cell = triangulation.begin_active();
1556-
cell != triangulation.end(); ++cell)
1557-
cell->clear_coarsen_flag ();
1558-
}
1559-
else
1560-
{
1561-
// limit minimum refinement level
1562-
for (typename Triangulation<dim>::active_cell_iterator
1563-
cell = triangulation.begin_active(0);
1564-
cell != triangulation.end_active(parameters.min_grid_level); ++cell)
1565-
cell->clear_coarsen_flag ();
1566-
}
1542+
}
1543+
else
1544+
{
1545+
// limit maximum refinement level
1546+
if (triangulation.n_levels() > max_grid_level)
1547+
for (typename Triangulation<dim>::active_cell_iterator
1548+
cell = triangulation.begin_active(max_grid_level);
1549+
cell != triangulation.end(); ++cell)
1550+
cell->clear_refine_flag ();
1551+
}
15671552

1568-
std::vector<const LinearAlgebra::BlockVector *> x_system (2);
1569-
x_system[0] = &solution;
1570-
x_system[1] = &old_solution;
1553+
// clear coarsening flags if parameter.coarsening_fraction=0.0
1554+
if (parameters.coarsening_fraction==0.0)
1555+
{
1556+
for (typename Triangulation<dim>::active_cell_iterator
1557+
cell = triangulation.begin_active();
1558+
cell != triangulation.end(); ++cell)
1559+
cell->clear_coarsen_flag ();
1560+
}
1561+
else
1562+
{
1563+
// limit minimum refinement level
1564+
for (typename Triangulation<dim>::active_cell_iterator
1565+
cell = triangulation.begin_active(0);
1566+
cell != triangulation.end_active(parameters.min_grid_level); ++cell)
1567+
cell->clear_coarsen_flag ();
1568+
}
15711569

1572-
if (parameters.free_surface_enabled)
1573-
x_system.push_back( &free_surface->mesh_velocity );
1570+
std::vector<const LinearAlgebra::BlockVector *> x_system (2);
1571+
x_system[0] = &solution;
1572+
x_system[1] = &old_solution;
15741573

1575-
parallel::distributed::SolutionTransfer<dim,LinearAlgebra::BlockVector>
1576-
system_trans(dof_handler);
1574+
if (parameters.free_surface_enabled)
1575+
x_system.push_back( &free_surface->mesh_velocity );
15771576

1578-
std::vector<const LinearAlgebra::Vector *> x_fs_system (1);
1579-
std_cxx11::unique_ptr<parallel::distributed::SolutionTransfer<dim,LinearAlgebra::Vector> >
1580-
freesurface_trans;
1577+
std::vector<const LinearAlgebra::Vector *> x_fs_system (1);
15811578

1582-
if (parameters.free_surface_enabled)
1583-
{
1584-
x_fs_system[0] = &free_surface->mesh_displacements;
1585-
freesurface_trans.reset (new parallel::distributed::SolutionTransfer<dim,LinearAlgebra::Vector>
1586-
(free_surface->free_surface_dof_handler));
1587-
}
1579+
if (parameters.free_surface_enabled)
1580+
{
1581+
x_fs_system[0] = &free_surface->mesh_displacements;
1582+
freesurface_trans.reset (new parallel::distributed::SolutionTransfer<dim,LinearAlgebra::Vector>
1583+
(free_surface->free_surface_dof_handler));
1584+
}
15881585

15891586

1590-
// Possibly store data of plugins associated with cells
1591-
signals.pre_refinement_store_user_data(triangulation);
1587+
// Possibly store data of plugins associated with cells
1588+
signals.pre_refinement_store_user_data(triangulation);
15921589

1593-
triangulation.prepare_coarsening_and_refinement();
1594-
system_trans.prepare_for_coarsening_and_refinement(x_system);
1590+
triangulation.prepare_coarsening_and_refinement();
1591+
system_trans.prepare_for_coarsening_and_refinement(x_system);
15951592

1596-
if (parameters.free_surface_enabled)
1597-
freesurface_trans->prepare_for_coarsening_and_refinement(x_fs_system);
1593+
if (parameters.free_surface_enabled)
1594+
freesurface_trans->prepare_for_coarsening_and_refinement(x_fs_system);
15981595

1599-
triangulation.execute_coarsening_and_refinement ();
1600-
computing_timer.exit_section();
1596+
triangulation.execute_coarsening_and_refinement ();
1597+
} // leave the timed section
16011598

16021599
setup_dofs ();
16031600

1604-
computing_timer.enter_section ("Refine mesh structure, part 2");
16051601
{
1602+
TimerOutput::Scope timer (computing_timer, "Refine mesh structure, part 2");
1603+
16061604
LinearAlgebra::BlockVector distributed_system;
16071605
LinearAlgebra::BlockVector old_distributed_system;
16081606
LinearAlgebra::BlockVector distributed_mesh_velocity;
@@ -1662,11 +1660,10 @@ namespace aspect
16621660

16631661
// Possibly load data of plugins associated with cells
16641662
signals.post_refinement_load_user_data(triangulation);
1665-
}
1666-
computing_timer.exit_section();
16671663

1668-
// calculate global volume after displacing mesh (if we have, in fact, displaced it)
1669-
global_volume = GridTools::volume (triangulation, *mapping);
1664+
// calculate global volume after displacing mesh (if we have, in fact, displaced it)
1665+
global_volume = GridTools::volume (triangulation, *mapping);
1666+
}
16701667
}
16711668

16721669

@@ -1814,7 +1811,7 @@ namespace aspect
18141811

18151812
if (parameters.resume_computation == false)
18161813
{
1817-
computing_timer.enter_section ("Setup initial conditions");
1814+
TimerOutput::Scope timer (computing_timer, "Setup initial conditions");
18181815

18191816
// Add topography to box models after all initial refinement
18201817
// is completed.
@@ -1825,8 +1822,6 @@ namespace aspect
18251822
compute_initial_pressure_field ();
18261823

18271824
signals.post_set_initial_state (*this);
1828-
1829-
computing_timer.exit_section();
18301825
}
18311826

18321827
// start the principal loop over time steps:

0 commit comments

Comments
 (0)