Skip to content

Commit 00c2eb5

Browse files
committed
Add detailed time measurements for assembly.
1 parent 83a1fd2 commit 00c2eb5

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

NumLib/ODESolver/NonlinearSolver.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include "NumLib/Exceptions.h"
2525
#include "PETScNonlinearSolver.h"
2626

27+
double time_pure_assembly {};
28+
double time_insert_in_matrix {};
29+
double time_dof_table_lookup {};
30+
2731
namespace NumLib
2832
{
2933
namespace detail
@@ -165,9 +169,15 @@ NonlinearSolverStatus NonlinearSolver<NonlinearSolverTag::Picard>::solve(
165169

166170
sys.preIteration(iteration, x_new_process);
167171

172+
// reset the time variables
173+
time_pure_assembly = 0;
174+
time_insert_in_matrix = 0;
175+
time_dof_table_lookup = 0;
176+
168177
BaseLib::RunTime time_assembly;
169178
time_assembly.start();
170179
sys.assemble(x_new, x_prev, process_id);
180+
double asm_time_elapsed = time_assembly.elapsed();
171181
sys.getA(A);
172182
sys.getRhs(*x_prev[process_id], rhs);
173183

@@ -186,6 +196,12 @@ NonlinearSolverStatus NonlinearSolver<NonlinearSolverTag::Picard>::solve(
186196
}
187197

188198
INFO("[time] Assembly took {:g} s.", time_assembly.elapsed());
199+
INFO(
200+
"[time] Pure assembly took {:g} s, insert in matrix took {:g} s, "
201+
"dof table lookup took {:g} s.",
202+
time_pure_assembly, time_insert_in_matrix, time_dof_table_lookup);
203+
INFO("[time] Assembly took {:g} s, getA + getRhs took {:g} s.",
204+
asm_time_elapsed, time_assembly.elapsed() - asm_time_elapsed);
189205

190206
// Subtract non-equilibrium initial residuum if set
191207
if (_r_neq != nullptr)
@@ -371,6 +387,11 @@ NonlinearSolverStatus NonlinearSolver<NonlinearSolverTag::Newton>::solve(
371387

372388
sys.preIteration(iteration, *x[process_id]);
373389

390+
// reset the time variables
391+
time_pure_assembly = 0;
392+
time_insert_in_matrix = 0;
393+
time_dof_table_lookup = 0;
394+
374395
BaseLib::RunTime time_assembly;
375396
time_assembly.start();
376397
bool mpi_rank_assembly_ok = true;
@@ -390,9 +411,13 @@ NonlinearSolverStatus NonlinearSolver<NonlinearSolverTag::Newton>::solve(
390411
{
391412
break;
392413
}
414+
INFO(
415+
"[time] Pure assembly took {:g} s, insert in matrix took {:g} s, "
416+
"dof table lookup took {:g} s.",
417+
time_pure_assembly, time_insert_in_matrix, time_dof_table_lookup);
418+
INFO("[time] Assembly took {:g} s.", time_assembly.elapsed());
393419
sys.getResidual(*x[process_id], *x_prev[process_id], res);
394420
sys.getJacobian(J);
395-
INFO("[time] Assembly took {:g} s.", time_assembly.elapsed());
396421

397422
// Subtract non-equilibrium initial residuum if set
398423
if (_r_neq != nullptr)

NumLib/ODESolver/NonlinearSolver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "NonlinearSystem.h"
2020
#include "Types.h"
2121

22+
extern double time_pure_assembly;
23+
extern double time_insert_in_matrix;
24+
extern double time_dof_table_lookup;
25+
2226
namespace BaseLib
2327
{
2428
class ConfigTree;

ProcessLib/VectorMatrixAssembler.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
#include "VectorMatrixAssembler.h"
1212

1313
#include <cassert>
14+
<<<<<<< HEAD
15+
=======
16+
#include <functional> // for std::reference_wrapper.
17+
18+
#include "BaseLib/RunTime.h"
19+
#include "NumLib/DOF/DOFTableUtil.h"
20+
#include "MathLib/LinAlg/Eigen/EigenMapTools.h"
21+
#include "LocalAssemblerInterface.h"
22+
>>>>>>> 82be5ea4a3 (Add detailed time measurements for assembly.)
1423

1524
#include "CoupledSolutionsForStaggeredScheme.h"
1625
#include "LocalAssemblerInterface.h"
@@ -43,6 +52,8 @@ void VectorMatrixAssembler::assemble(
4352
std::vector<GlobalVector*> const& x_prev, int const process_id,
4453
GlobalMatrix* M, GlobalMatrix* K, GlobalVector* b)
4554
{
55+
BaseLib::RunTime timer;
56+
timer.start();
4657
std::vector<std::vector<GlobalIndexType>> indices_of_processes;
4758
indices_of_processes.reserve(dof_tables.size());
4859
transform(cbegin(dof_tables), cend(dof_tables),
@@ -51,12 +62,15 @@ void VectorMatrixAssembler::assemble(
5162
{ return NumLib::getIndices(mesh_item_id, *dof_table); });
5263

5364
auto const& indices = indices_of_processes[process_id];
65+
time_dof_table_lookup += timer.elapsed();
66+
5467
_local_M_data.clear();
5568
_local_K_data.clear();
5669
_local_b_data.clear();
5770

5871
std::size_t const number_of_processes = x.size();
5972
// Monolithic scheme
73+
timer.start();
6074
if (number_of_processes == 1)
6175
{
6276
auto const local_x = x[process_id]->get(indices);
@@ -78,11 +92,15 @@ void VectorMatrixAssembler::assemble(
7892
t, dt, local_x, local_x_prev, process_id, _local_M_data,
7993
_local_K_data, _local_b_data);
8094
}
95+
time_pure_assembly += timer.elapsed();
8196

97+
timer.start();
8298
auto const num_r_c = indices.size();
8399
auto const r_c_indices =
84100
NumLib::LocalToGlobalIndexMap::RowColumnIndices(indices, indices);
101+
time_dof_table_lookup += timer.elapsed();
85102

103+
timer.start();
86104
if (M && !_local_M_data.empty())
87105
{
88106
auto const local_M = MathLib::toMatrix(_local_M_data, num_r_c, num_r_c);
@@ -99,6 +117,7 @@ void VectorMatrixAssembler::assemble(
99117
b->add(indices, _local_b_data);
100118
}
101119

120+
time_insert_in_matrix += timer.elapsed();
102121
_local_output(t, process_id, mesh_item_id, _local_M_data, _local_K_data,
103122
_local_b_data);
104123
}

0 commit comments

Comments
 (0)