Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/benchmarks/t8_time_new_refine.c
901 views
1
/*
2
This file is part of t8code.
3
t8code is a C library to manage a collection (a forest) of multiple
4
connected adaptive space-trees of general element types in parallel.
5
6
Copyright (C) 2015 the developers
7
8
t8code is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
13
t8code is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with t8code; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
*/
22
23
#include <sc_refcount.h>
24
#include <t8_cmesh/t8_cmesh_examples.h>
25
#include <t8_schemes/t8_scheme.h>
26
#include <t8_schemes/t8_default/t8_default_c_interface.h>
27
#include <t8_schemes/t8_default/t8_default_tri/t8_dtri.h>
28
#include <t8_schemes/t8_default/t8_default_tet/t8_dtet.h>
29
#include <t8_forest/t8_forest_adapt.h>
30
#include <t8_forest/t8_forest_general.h>
31
#include <sc_flops.h>
32
#include <sc_statistics.h>
33
#include <sc_options.h>
34
35
#include <t8_forest/t8_forest_types.h> /* TODO: This file should not be included from an application */
36
/* This function refines every element */
37
static int
38
t8_basic_adapt_refine (__attribute__ ((unused)) t8_forest_t forest, __attribute__ ((unused)) t8_forest_t forest_from,
39
__attribute__ ((unused)) t8_locidx_t which_tree, t8_eclass_t tree_class,
40
__attribute__ ((unused)) t8_locidx_t lelement_id, const t8_scheme_c *scheme,
41
__attribute__ ((unused)) const int is_family, const int num_elements, t8_element_t *elements[])
42
{
43
const int level = t8_element_get_level (scheme, tree_class, elements[0]);
44
/* coarsen */
45
if (num_elements > 1) {
46
if (level > 0)
47
return -1;
48
return 0;
49
}
50
return 1;
51
}
52
53
/* This function coarsens each element */
54
static int
55
t8_basic_adapt_coarsen (__attribute__ ((unused)) t8_forest_t forest, __attribute__ ((unused)) t8_forest_t forest_from,
56
__attribute__ ((unused)) t8_locidx_t which_tree,
57
__attribute__ ((unused)) t8_eclass_t tree_class,
58
__attribute__ ((unused)) t8_locidx_t lelement_id,
59
__attribute__ ((unused)) const t8_scheme_c *scheme, const int is_family,
60
__attribute__ ((unused)) int num_elements, __attribute__ ((unused)) t8_element_t *elements[])
61
{
62
if (is_family) {
63
return -1;
64
}
65
return 0;
66
}
67
68
static void
69
t8_timings_adapt (int start_l, int end_l, int runs, int dim)
70
{
71
t8_forest_t *forests;
72
int li, num_levels, cur_for, run;
73
t8_eclass_t eclass;
74
sc_flopinfo_t fi, snapshot;
75
sc_statinfo_t stats[1];
76
77
num_levels = end_l - start_l + 1;
78
T8_ASSERT (num_levels > 0);
79
T8_ASSERT (runs > 0);
80
81
forests = T8_ALLOC (t8_forest_t, 2 * num_levels * runs);
82
83
t8_forest_init (&forests[0]);
84
85
eclass = dim == 2 ? T8_ECLASS_TRIANGLE : T8_ECLASS_TET;
86
/*
87
t8_forest_set_cmesh (forests[0],
88
t8_cmesh_new_hypercube (eclass, sc_MPI_COMM_WORLD, 0), 0);
89
*/
90
t8_forest_set_cmesh (forests[0], t8_cmesh_new_bigmesh (eclass, 512, sc_MPI_COMM_WORLD), sc_MPI_COMM_WORLD);
91
t8_forest_set_scheme (forests[0], t8_scheme_new_default ());
92
t8_forest_set_level (forests[0], start_l);
93
t8_forest_commit (forests[0]);
94
95
sc_flops_start (&fi);
96
sc_flops_snap (&fi, &snapshot);
97
for (run = 0, cur_for = 1; run < runs; run++) {
98
for (li = 1; li < num_levels; li++, cur_for++) {
99
t8_forest_init (&forests[cur_for]);
100
t8_forest_set_adapt (forests[cur_for], forests[cur_for - 1], t8_basic_adapt_refine, 0);
101
t8_forest_commit (forests[cur_for]);
102
}
103
for (li = 1; li < num_levels; li++, cur_for++) {
104
t8_forest_init (&forests[cur_for]);
105
t8_forest_set_adapt (forests[cur_for], forests[cur_for - 1], t8_basic_adapt_coarsen, 0);
106
t8_forest_commit (forests[cur_for]);
107
}
108
}
109
110
sc_flops_shot (&fi, &snapshot);
111
sc_stats_set1 (&stats[0], snapshot.iwtime, "Adapt");
112
113
t8_forest_unref (&forests[cur_for - 1]);
114
T8_FREE (forests);
115
116
sc_stats_compute (sc_MPI_COMM_WORLD, 1, stats);
117
sc_stats_print (t8_get_package_id (), SC_LP_STATISTICS, 1, stats, 1, 1);
118
}
119
120
void
121
t8_timings_new (int level, int dim)
122
{
123
t8_forest_t forest;
124
t8_eclass_t eclass;
125
sc_flopinfo_t fi, snapshot;
126
sc_statinfo_t stats[1];
127
128
T8_ASSERT (level >= 0);
129
T8_ASSERT (dim == 2 || dim == 3);
130
131
eclass = dim == 2 ? T8_ECLASS_TRIANGLE : T8_ECLASS_TET;
132
133
t8_global_productionf ("=P= Starting forest_new with %.0f elements.\n", 512 * pow (2, dim * level));
134
135
sc_flops_start (&fi);
136
sc_flops_snap (&fi, &snapshot);
137
138
t8_forest_init (&forest);
139
t8_forest_set_cmesh (forest, t8_cmesh_new_hypercube (eclass, sc_MPI_COMM_WORLD, 0, 0, 0), sc_MPI_COMM_WORLD);
140
t8_forest_set_scheme (forest, t8_scheme_new_default ());
141
t8_forest_set_level (forest, level);
142
t8_forest_commit (forest);
143
144
sc_flops_shot (&fi, &snapshot);
145
sc_stats_set1 (&stats[0], snapshot.iwtime, "New");
146
147
t8_global_productionf ("=P= Done forest_new.\n");
148
149
t8_forest_unref (&forest);
150
151
sc_stats_compute (sc_MPI_COMM_WORLD, 1, stats);
152
sc_stats_print (t8_get_package_id (), SC_LP_STATISTICS, 1, stats, 1, 1);
153
}
154
155
int
156
main (int argc, char **argv)
157
{
158
int mpiret, mpisize;
159
int start_level, end_level, dim;
160
int first_argc;
161
int use_refine, use_new;
162
sc_options_t *opt;
163
164
mpiret = sc_MPI_Init (&argc, &argv);
165
SC_CHECK_MPI (mpiret);
166
167
sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_ESSENTIAL);
168
p4est_init (NULL, SC_LP_ESSENTIAL);
169
t8_init (SC_LP_DEFAULT);
170
171
mpiret = sc_MPI_Comm_size (sc_MPI_COMM_WORLD, &mpisize);
172
SC_CHECK_MPI (mpiret);
173
174
opt = sc_options_new (argv[0]);
175
sc_options_add_int (opt, 's', "slevel", &start_level, 0, "initial refine level");
176
sc_options_add_int (opt, 'e', "elevel", &end_level, 0,
177
"Final refine level: greater or equal to initial refine level");
178
sc_options_add_int (opt, 'd', "dim", &dim, 2, "dimension: 2 or 3");
179
sc_options_add_switch (opt, 'r', "refine", &use_refine,
180
"Time refining from start_level to end_level - this is default. ");
181
sc_options_add_switch (opt, 'n', "new", &use_new,
182
"Time new with start_level - If this is given -r has to be switched on by hand if desired.");
183
184
first_argc = sc_options_parse (t8_get_package_id (), SC_LP_DEFAULT, opt, argc, argv);
185
186
if (end_level < start_level) {
187
end_level = start_level;
188
}
189
190
if (first_argc < 0 || first_argc != argc || 2 > dim || dim > 3 || (use_refine && end_level < start_level)) {
191
sc_options_print_usage (t8_get_package_id (), SC_LP_ERROR, opt, NULL);
192
return 1;
193
}
194
195
if (use_refine || !use_new) {
196
t8_timings_adapt (start_level, end_level, 1, dim);
197
}
198
if (use_new) {
199
t8_timings_new (start_level, dim);
200
}
201
202
sc_options_destroy (opt);
203
204
sc_finalize ();
205
206
mpiret = sc_MPI_Finalize ();
207
SC_CHECK_MPI (mpiret);
208
209
return 0;
210
}
211
212