ExaDG
Loading...
Searching...
No Matches
throughput.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_POISSON_THROUGHPUT_H_
23#define INCLUDE_EXADG_POISSON_THROUGHPUT_H_
24
25// likwid
26#ifdef EXADG_WITH_LIKWID
27# include <likwid.h>
28#endif
29
30// deal.II
31#include <deal.II/base/exceptions.h>
32#include <deal.II/base/parameter_handler.h>
33
34// driver
35#include <exadg/poisson/driver.h>
36
37// utilities
38#include <exadg/operators/finite_element.h>
39#include <exadg/operators/hypercube_resolution_parameters.h>
40#include <exadg/operators/throughput_parameters.h>
41#include <exadg/utilities/enum_patterns.h>
42#include <exadg/utilities/general_parameters.h>
43
44// application
45#include <exadg/poisson/user_interface/declare_get_application.h>
46
47namespace ExaDG
48{
49void
50create_input_file(std::string const & input_file)
51{
52 dealii::ParameterHandler prm;
53
54 GeneralParameters general;
55 general.add_parameters(prm);
56
57 HypercubeResolutionParameters resolution;
58 resolution.add_parameters(prm);
59
60 ThroughputParameters<Poisson::OperatorType> throughput;
61 throughput.add_parameters(prm);
62
63 try
64 {
65 // we have to assume a default dimension and default Number type
66 // for the automatic generation of a default input file
67 unsigned int const Dim = 2;
68 typedef double Number;
69 Poisson::get_application<Dim, 1, Number>(input_file, MPI_COMM_WORLD)->add_parameters(prm);
70 }
71 catch(...)
72 {
73 }
74
75 prm.print_parameters(input_file,
76 dealii::ParameterHandler::Short |
77 dealii::ParameterHandler::KeepDeclarationOrder);
78}
79
80template<int dim, typename Number>
81void
82run(ThroughputParameters<Poisson::OperatorType> const & throughput,
83 std::string const & input_file,
84 unsigned int const degree,
85 unsigned int const refine_space,
86 unsigned int const n_cells_1d,
87 MPI_Comm const & mpi_comm,
88 bool const is_test)
89{
90 std::shared_ptr<Poisson::ApplicationBase<dim, 1, Number>> application =
91 Poisson::get_application<dim, 1, Number>(input_file, mpi_comm);
92
93 application->set_parameters_throughput_study(degree, refine_space, n_cells_1d);
94
95 std::shared_ptr<Poisson::Driver<dim, Number>> driver =
96 std::make_shared<Poisson::Driver<dim, Number>>(mpi_comm, application, is_test, true);
97
98 driver->setup();
99
100 std::tuple<unsigned int, dealii::types::global_dof_index, double> wall_time =
101 driver->apply_operator(throughput.operator_type,
102 throughput.n_repetitions_inner,
103 throughput.n_repetitions_outer);
104
105 throughput.wall_times.push_back(wall_time);
106}
107} // namespace ExaDG
108
109int
110main(int argc, char ** argv)
111{
112#ifdef EXADG_WITH_LIKWID
113 LIKWID_MARKER_INIT;
114#endif
115
116 dealii::Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1);
117
118 MPI_Comm mpi_comm(MPI_COMM_WORLD);
119
120 std::string input_file;
121
122 if(argc == 1)
123 {
124 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
125 {
126 std::cout << "To run the program, use: ./throughput input_file" << std::endl
127 << "To setup the input file, use: ./throughput input_file --help" << std::endl;
128 }
129
130 return 0;
131 }
132 else if(argc >= 2)
133 {
134 input_file = std::string(argv[1]);
135
136 if(argc == 3 and std::string(argv[2]) == "--help")
137 {
138 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
139 ExaDG::create_input_file(input_file);
140
141 return 0;
142 }
143 }
144
145 ExaDG::GeneralParameters general(input_file);
146 ExaDG::HypercubeResolutionParameters resolution(input_file, general.dim);
148
149 // get additional parameters
150 ExaDG::Poisson::SpatialDiscretization spatial_discretization =
151 ExaDG::Poisson::SpatialDiscretization::Undefined;
152
153 dealii::ParameterHandler prm;
154 prm.enter_subsection("Throughput");
155 {
156 prm.add_parameter("SpatialDiscretization",
157 spatial_discretization,
158 "Spatial discretization (CG vs. DG).",
159 ExaDG::Patterns::Enum<ExaDG::Poisson::SpatialDiscretization>(),
160 true);
161 }
162 prm.leave_subsection();
163
164 prm.parse_input(input_file, "", true, true);
165
166 auto const lambda_get_dofs_per_element =
167 [&](unsigned int const dim, unsigned int const degree, ExaDG::ElementType const element_type) {
168 return ExaDG::get_dofs_per_element(element_type,
169 spatial_discretization ==
170 ExaDG::Poisson::SpatialDiscretization::DG,
171 1 /* n_components */,
172 degree,
173 dim);
174 };
175
176 // fill resolution vector depending on the operator_type
177 resolution.fill_resolution_vector(lambda_get_dofs_per_element);
178
179 // loop over resolutions vector and run simulations
180 for(auto iter = resolution.resolutions.begin(); iter != resolution.resolutions.end(); ++iter)
181 {
182 unsigned int const degree = std::get<0>(*iter);
183 unsigned int const refine_space = std::get<1>(*iter);
184 unsigned int const n_cells_1d = std::get<2>(*iter);
185
186 if(general.dim == 2 and general.precision == "float")
187 {
188 ExaDG::run<2, float>(
189 throughput, input_file, degree, refine_space, n_cells_1d, mpi_comm, general.is_test);
190 }
191 else if(general.dim == 2 and general.precision == "double")
192 {
193 ExaDG::run<2, double>(
194 throughput, input_file, degree, refine_space, n_cells_1d, mpi_comm, general.is_test);
195 }
196 else if(general.dim == 3 and general.precision == "float")
197 {
198 ExaDG::run<3, float>(
199 throughput, input_file, degree, refine_space, n_cells_1d, mpi_comm, general.is_test);
200 }
201 else if(general.dim == 3 and general.precision == "double")
202 {
203 ExaDG::run<3, double>(
204 throughput, input_file, degree, refine_space, n_cells_1d, mpi_comm, general.is_test);
205 }
206 else
207 {
208 AssertThrow(false,
209 dealii::ExcMessage("Only dim = 2|3 and precision=float|double implemented."));
210 }
211 }
212
213 if(not(general.is_test))
214 throughput.print_results(mpi_comm);
215
216#ifdef EXADG_WITH_LIKWID
217 LIKWID_MARKER_CLOSE;
218#endif
219
220 return 0;
221}
222
223
224#endif /* INCLUDE_EXADG_POISSON_THROUGHPUT_H_ */
Definition driver.cpp:33
Definition general_parameters.h:32
Definition hypercube_resolution_parameters.h:182
Definition throughput_parameters.h:92