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 EXADG_CONVECTION_DIFFUSION_THROUGHPUT_H_
23#define EXADG_CONVECTION_DIFFUSION_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// ExaDG
35#include <exadg/convection_diffusion/driver.h>
36#include <exadg/convection_diffusion/user_interface/declare_get_application.h>
37#include <exadg/operators/finite_element.h>
38#include <exadg/operators/hypercube_resolution_parameters.h>
39#include <exadg/operators/throughput_parameters.h>
40#include <exadg/utilities/enum_patterns.h>
41#include <exadg/utilities/general_parameters.h>
42
43namespace ExaDG
44{
45void
46create_input_file(std::string const & input_file)
47{
48 dealii::ParameterHandler prm;
49
50 GeneralParameters general;
51 general.add_parameters(prm);
52
54 resolution.add_parameters(prm);
55
57 throughput.add_parameters(prm);
58
59 try
60 {
61 // we have to assume a default dimension and default Number type
62 // for the automatic generation of a default input file
63 unsigned int const Dim = 2;
64 typedef double Number;
65 ConvDiff::get_application<Dim, Number>(input_file, MPI_COMM_WORLD)->add_parameters(prm);
66 }
67 catch(...)
68 {
69 }
70
71 prm.print_parameters(input_file,
72 dealii::ParameterHandler::Short |
73 dealii::ParameterHandler::KeepDeclarationOrder);
74}
75
76
77template<int dim, typename Number>
78void
80 std::string const & input_file,
81 unsigned int const degree,
82 unsigned int const refine_space,
83 unsigned int const n_cells_1d,
84 MPI_Comm const & mpi_comm,
85 bool const is_test)
86{
87 std::shared_ptr<ConvDiff::ApplicationBase<dim, Number>> application =
88 ConvDiff::get_application<dim, Number>(input_file, mpi_comm);
89
90 application->set_parameters_throughput_study(degree, refine_space, n_cells_1d);
91
92 std::shared_ptr<ConvDiff::Driver<dim, Number>> driver =
93 std::make_shared<ConvDiff::Driver<dim, Number>>(mpi_comm, application, is_test, true);
94
95 driver->setup();
96
97 std::tuple<unsigned int, dealii::types::global_dof_index, double> wall_time =
98 driver->apply_operator(throughput.operator_type,
99 throughput.n_repetitions_inner,
100 throughput.n_repetitions_outer);
101
102 throughput.wall_times.push_back(wall_time);
103}
104} // namespace ExaDG
105
106
107int
108main(int argc, char ** argv)
109{
110#ifdef EXADG_WITH_LIKWID
111 LIKWID_MARKER_INIT;
112#endif
113
114 dealii::Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1);
115
116 MPI_Comm mpi_comm(MPI_COMM_WORLD);
117
118 std::string input_file;
119
120 if(argc == 1)
121 {
122 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
123 {
124 // clang-format off
125 std::cout << "To run the program, use: ./throughput input_file" << std::endl
126 << "To setup the input file, use: ./throughput input_file --help" << std::endl;
127 // clang-format on
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 auto const lambda_get_dofs_per_element =
150 [&](unsigned int const dim, unsigned int const degree, ExaDG::ElementType const element_type) {
151 return ExaDG::get_dofs_per_element(
152 element_type, true /* is_dg */, 1 /* n_components */, degree, dim);
153 };
154
155 // fill resolution vector
156 resolution.fill_resolution_vector(lambda_get_dofs_per_element);
157
158 // loop over resolutions vector and run simulations
159 for(auto iter = resolution.resolutions.begin(); iter != resolution.resolutions.end(); ++iter)
160 {
161 unsigned int const degree = std::get<0>(*iter);
162 unsigned int const refine_space = std::get<1>(*iter);
163 unsigned int const n_cells_1d = std::get<2>(*iter);
164
165 if(general.dim == 2 and general.precision == "float")
166 {
167 ExaDG::run<2, float>(
168 throughput, input_file, degree, refine_space, n_cells_1d, mpi_comm, general.is_test);
169 }
170 else if(general.dim == 2 and general.precision == "double")
171 {
172 ExaDG::run<2, double>(
173 throughput, input_file, degree, refine_space, n_cells_1d, mpi_comm, general.is_test);
174 }
175 else if(general.dim == 3 and general.precision == "float")
176 {
177 ExaDG::run<3, float>(
178 throughput, input_file, degree, refine_space, n_cells_1d, mpi_comm, general.is_test);
179 }
180 else if(general.dim == 3 and general.precision == "double")
181 {
182 ExaDG::run<3, double>(
183 throughput, input_file, degree, refine_space, n_cells_1d, mpi_comm, general.is_test);
184 }
185 else
186 {
187 AssertThrow(false,
188 dealii::ExcMessage("Only dim = 2|3 and precision=float|double implemented."));
189 }
190 }
191
192 if(not(general.is_test))
193 throughput.print_results(mpi_comm);
194
195#ifdef EXADG_WITH_LIKWID
196 LIKWID_MARKER_CLOSE;
197#endif
198
199 return 0;
200}
201
202#endif /* EXADG_CONVECTION_DIFFUSION_THROUGHPUT_H_ */
Definition driver.cpp:33
Definition general_parameters.h:34
Definition hypercube_resolution_parameters.h:183
Definition throughput_parameters.h:91