Skip to content

Commit 6306faf

Browse files
committed
Print timers
1 parent 7d0a096 commit 6306faf

File tree

2 files changed

+96
-10
lines changed

2 files changed

+96
-10
lines changed

include/solvers/fluid_dynamics_matrix_free.h

+9
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ class MFNavierStokesPreconditionGMG
124124
const MGLevelObject<std::shared_ptr<OperatorType>> &
125125
get_mg_operators() const;
126126

127+
128+
/**
129+
* @brief Getter function for all level smoother preconditioners.
130+
*
131+
* @return Multigrid object that contains all level smoother preconditioners.
132+
*/
133+
const MGLevelObject<std::shared_ptr<PreconditionBase<VectorType>>> &
134+
get_mg_smoother_preconditioners() const;
135+
127136
private:
128137
/**
129138
* @brief Set up AMG object needed for coarse-grid solver or

source/solvers/fluid_dynamics_matrix_free.cc

+87-10
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,48 @@ template <typename VectorType>
5353
class PreconditionBase
5454
{
5555
public:
56+
/**
57+
* @brief Constructor.
58+
*/
59+
PreconditionBase()
60+
: comm(MPI_COMM_WORLD)
61+
, pcout(std::cout, Utilities::MPI::this_mpi_process(comm) == 0)
62+
, timer(pcout, TimerOutput::never, TimerOutput::wall_times)
63+
{}
64+
5665
/**
5766
* @brief Apply preconditioner.
5867
*/
5968
virtual void
6069
vmult(VectorType &dst, const VectorType &src) const = 0;
70+
71+
/**
72+
* @brief Print timers.
73+
*/
74+
void
75+
timer_print() const
76+
{
77+
timer.print_wall_time_statistics(comm);
78+
}
79+
80+
/**
81+
* @brief Reset timers.
82+
*/
83+
void
84+
timer_reset() const
85+
{
86+
timer.reset();
87+
}
88+
89+
protected:
90+
/// Communicator used for timer output.
91+
const MPI_Comm comm;
92+
93+
/// Stream used for timer output.
94+
ConditionalOStream pcout;
95+
96+
/// Timer.
97+
mutable TimerOutput timer;
6198
};
6299

63100
/**
@@ -152,6 +189,8 @@ class PreconditionASM : public PreconditionBase<VectorType>
152189
const AffineConstraints<Number> &constraints,
153190
const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner)
154191
{
192+
this->timer.enter_subsection("asm::inidices");
193+
155194
std::vector<std::vector<types::global_dof_index>> patches;
156195

157196
const auto add_indices = [&](const auto &local_dof_indices) {
@@ -195,13 +234,30 @@ class PreconditionASM : public PreconditionBase<VectorType>
195234
dst_internal.reinit(partition);
196235
}
197236

237+
// convert indices to local ones
238+
this->patches.resize(patches.size());
239+
for (unsigned int c = 0; c < patches.size(); ++c)
240+
{
241+
this->patches[c].resize(0);
242+
this->patches[c].reserve(patches[c].size());
243+
244+
for (const auto &i : patches[c])
245+
this->patches[c].emplace_back(partition->global_to_local(i));
246+
}
247+
248+
this->timer.leave_subsection("asm::inidices");
249+
this->timer.enter_subsection("asm::restrict");
250+
198251
std::vector<FullMatrix<Number>> blocks;
199252

200253
SparseMatrixTools::restrict_to_full_matrices(global_sparse_matrix,
201254
global_sparsity_pattern,
202255
patches,
203256
blocks);
204257

258+
this->timer.leave_subsection("asm::restrict");
259+
this->timer.enter_subsection("asm::invert");
260+
205261
this->blocks.resize(blocks.size());
206262

207263
for (unsigned int b = 0; b < blocks.size(); ++b)
@@ -212,8 +268,11 @@ class PreconditionASM : public PreconditionBase<VectorType>
212268
this->blocks[b].compute_lu_factorization();
213269
}
214270

271+
this->timer.leave_subsection("asm::invert");
272+
215273
if (weighting_type != WeightingType::none)
216274
{
275+
this->timer.enter_subsection("asm::weight");
217276
Vector<double> vector_weights;
218277
weights.reinit(partition);
219278

@@ -234,17 +293,8 @@ class PreconditionASM : public PreconditionBase<VectorType>
234293
i = (weighting_type == WeightingType::symm) ? std::sqrt(1.0 / i) :
235294
(1.0 / i);
236295
weights.update_ghost_values();
237-
}
238296

239-
// convert indices to local ones
240-
this->patches.resize(patches.size());
241-
for (unsigned int c = 0; c < patches.size(); ++c)
242-
{
243-
this->patches[c].resize(0);
244-
this->patches[c].reserve(patches[c].size());
245-
246-
for (const auto &i : patches[c])
247-
this->patches[c].emplace_back(partition->global_to_local(i));
297+
this->timer.leave_subsection("asm::weight");
248298
}
249299
}
250300

@@ -254,6 +304,8 @@ class PreconditionASM : public PreconditionBase<VectorType>
254304
void
255305
vmult(VectorType &dst, const VectorType &src) const override
256306
{
307+
this->timer.enter_subsection("asm::vmult");
308+
257309
const auto &src_ptr = (src_internal.size() != 0) ? src_internal : src;
258310
auto &dst_ptr = (dst_internal.size() != 0) ? dst_internal : dst;
259311

@@ -302,6 +354,8 @@ class PreconditionASM : public PreconditionBase<VectorType>
302354

303355
if (dst_internal.size() != 0)
304356
dst.copy_locally_owned_data_from(dst_internal);
357+
358+
this->timer.leave_subsection("asm::vmult");
305359
}
306360

307361
private:
@@ -1769,6 +1823,14 @@ MFNavierStokesPreconditionGMG<dim>::get_mg_operators() const
17691823
return this->mg_operators;
17701824
}
17711825

1826+
template <int dim>
1827+
const MGLevelObject<std::shared_ptr<
1828+
PreconditionBase<typename MFNavierStokesPreconditionGMG<dim>::VectorType>>> &
1829+
MFNavierStokesPreconditionGMG<dim>::get_mg_smoother_preconditioners() const
1830+
{
1831+
return this->mg_smoother_preconditioners;
1832+
}
1833+
17721834
template <int dim>
17731835
void
17741836
MFNavierStokesPreconditionGMG<dim>::setup_AMG()
@@ -2569,6 +2631,21 @@ FluidDynamicsMatrixFree<dim>::print_mg_setup_times()
25692631
mg_operators[level]->timer.reset();
25702632
}
25712633

2634+
auto mg_smoother_preconditioners =
2635+
this->gmg_preconditioner->get_mg_smoother_preconditioners();
2636+
for (unsigned int level = mg_operators.min_level();
2637+
level <= mg_operators.max_level();
2638+
level++)
2639+
{
2640+
announce_string(this->pcout,
2641+
"Preconditioner level " + std::to_string(level) +
2642+
" times");
2643+
mg_smoother_preconditioners[level]->timer_print();
2644+
2645+
// Reset timer if output is set to every iteration
2646+
mg_smoother_preconditioners[level]->timer_reset();
2647+
}
2648+
25722649
// Reset timers if output is set to every iteration
25732650
this->gmg_preconditioner->mg_setup_timer.reset();
25742651
this->gmg_preconditioner->mg_vmult_timer.reset();

0 commit comments

Comments
 (0)