ExaDG
Loading...
Searching...
No Matches
throughput_parameters.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef INCLUDE_EXADG_OPERATORS_THROUGHPUT_PARAMETERS_H_
23#define INCLUDE_EXADG_OPERATORS_THROUGHPUT_PARAMETERS_H_
24
25// likwid
26#ifdef EXADG_WITH_LIKWID
27# include <likwid.h>
28#endif
29
30// deal.II
31#include <deal.II/base/parameter_handler.h>
32#include <deal.II/base/timer.h>
33
34// ExaDG
35#include <exadg/utilities/enum_patterns.h>
36#include <exadg/utilities/print_solver_results.h>
37
38
39namespace ExaDG
40{
41inline double
42measure_operator_evaluation_time(std::function<void(void)> const & evaluate_operator,
43 unsigned int const degree,
44 unsigned int const n_repetitions_inner,
45 unsigned int const n_repetitions_outer,
46 MPI_Comm const & mpi_comm)
47{
48 (void)degree;
49
50 dealii::Timer global_timer;
51 global_timer.restart();
52 dealii::Utilities::MPI::MinMaxAvg global_time;
53
54 double wall_time = std::numeric_limits<double>::max();
55
56 do
57 {
58 for(unsigned int i_outer = 0; i_outer < n_repetitions_outer; ++i_outer)
59 {
60 dealii::Timer timer;
61 timer.restart();
62
63#ifdef EXADG_WITH_LIKWID
64 LIKWID_MARKER_START(("degree_" + std::to_string(degree)).c_str());
65#endif
66
67 // apply matrix-vector product several times
68 for(unsigned int i = 0; i < n_repetitions_inner; ++i)
69 {
70 evaluate_operator();
71 }
72
73#ifdef EXADG_WITH_LIKWID
74 LIKWID_MARKER_STOP(("degree_" + std::to_string(degree)).c_str());
75#endif
76
77 MPI_Barrier(mpi_comm);
78 dealii::Utilities::MPI::MinMaxAvg wall_time_inner =
79 dealii::Utilities::MPI::min_max_avg(timer.wall_time(), mpi_comm);
80
81 wall_time = std::min(wall_time, wall_time_inner.avg / (double)n_repetitions_inner);
82 }
83
84 global_time = dealii::Utilities::MPI::min_max_avg(global_timer.wall_time(), mpi_comm);
85 } while(global_time.avg < 1.0 /*wall time in seconds*/);
86
87 return wall_time;
88}
89
90template<typename EnumOperatorType>
92{
94 {
95 }
96
97 ThroughputParameters(std::string const & input_file)
98 {
99 dealii::ParameterHandler prm;
100 add_parameters(prm);
101 prm.parse_input(input_file, "", true, true);
102 }
103
104 void
105 add_parameters(dealii::ParameterHandler & prm)
106 {
107 prm.enter_subsection("Throughput");
108 {
109 prm.add_parameter(
110 "OperatorType", operator_type, "Operator type.", Patterns::Enum<EnumOperatorType>(), true);
111 prm.add_parameter("RepetitionsInner",
112 n_repetitions_inner,
113 "Number of operator evaluations.",
114 dealii::Patterns::Integer(1),
115 true);
116 prm.add_parameter("RepetitionsOuter",
117 n_repetitions_outer,
118 "Number of runs (taking minimum wall time).",
119 dealii::Patterns::Integer(1, 10),
120 true);
121 }
122 prm.leave_subsection();
123 }
124
125 void
126 print_results(MPI_Comm const & mpi_comm)
127 {
128 print_throughput(wall_times, ExaDG::Utilities::enum_to_string(operator_type), mpi_comm);
129 }
130
131 // type of PDE operator
132 EnumOperatorType operator_type = Utilities::default_constructor<EnumOperatorType>();
133
134 // number of repetitions used to determine the average/minimum wall time required
135 // to compute the matrix-vector product
136 unsigned int n_repetitions_inner = 100; // take the average of inner repetitions
137 unsigned int n_repetitions_outer = 1; // take the minimum of outer repetitions
138
139 // variable used to store the wall times for different polynomial degrees and problem sizes
140 mutable std::vector<std::tuple<unsigned int, dealii::types::global_dof_index, double>> wall_times;
141};
142} // namespace ExaDG
143
144
145#endif /* INCLUDE_EXADG_OPERATORS_THROUGHPUT_PARAMETERS_H_ */
std::string enum_to_string(EnumType const enum_type)
Converts and enum to a string, returning the string.
Definition enum_utilities.h:67
Definition driver.cpp:33
Definition throughput_parameters.h:92