Skip to content

Commit 19c4bc6

Browse files
committed
Add timing for search
1 parent d360380 commit 19c4bc6

File tree

4 files changed

+126
-3
lines changed

4 files changed

+126
-3
lines changed

src/t8_forest/t8_forest.cxx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3799,6 +3799,10 @@ t8_forest_compute_profile (t8_forest_t forest)
37993799
sc_stats_set1 (&forest->stats[14], profile->balance_rounds, "forest: Tree offset runtime.");
38003800
sc_stats_set1 (&forest->stats[15], profile->balance_rounds, "forest: offset runtime.");
38013801
sc_stats_set1 (&forest->stats[16], profile->balance_rounds, "forest: first descendant runtime.");
3802+
sc_stats_set1 (&forest->stats[17], profile->balance_rounds, "forest: search check element runtime.");
3803+
sc_stats_set1 (&forest->stats[18], profile->balance_rounds, "forest: search check queries runtime.");
3804+
sc_stats_set1 (&forest->stats[19], profile->balance_rounds, "forest: search split_array runtime.");
3805+
sc_stats_set1 (&forest->stats[20], profile->balance_rounds, "forest: search total runtime.");
38023806
/* compute stats */
38033807
sc_stats_compute (sc_MPI_COMM_WORLD, T8_PROFILE_NUM_STATS, forest->stats);
38043808
forest->stats_computed = 1;
@@ -3968,6 +3972,42 @@ t8_forest_profile_get_first_descendant_runtime (t8_forest_t forest)
39683972
}
39693973
return 0;
39703974
}
3975+
double
3976+
t8_forest_profile_get_search_check_element_runtime (t8_forest_t forest)
3977+
{
3978+
T8_ASSERT (t8_forest_is_committed (forest));
3979+
if (forest->profile != NULL) {
3980+
return forest->profile->search_check_element_time;
3981+
}
3982+
return 0;
3983+
}
3984+
double
3985+
t8_forest_profile_search_check_query_runtime (t8_forest_t forest)
3986+
{
3987+
T8_ASSERT (t8_forest_is_committed (forest));
3988+
if (forest->profile != NULL) {
3989+
return forest->profile->search_check_query_time;
3990+
}
3991+
return 0;
3992+
}
3993+
double
3994+
t8_forest_profile_search_split_array_runtime (t8_forest_t forest)
3995+
{
3996+
T8_ASSERT (t8_forest_is_committed (forest));
3997+
if (forest->profile != NULL) {
3998+
return forest->profile->search_split_array_time;
3999+
}
4000+
return 0;
4001+
}
4002+
double
4003+
t8_forest_profile_search_total_runtime (t8_forest_t forest)
4004+
{
4005+
T8_ASSERT (t8_forest_is_committed (forest));
4006+
if (forest->profile != NULL) {
4007+
return forest->profile->search_time;
4008+
}
4009+
return 0;
4010+
}
39714011

39724012
void
39734013
t8_forest_compute_elements_offset (t8_forest_t forest)

src/t8_forest/t8_forest_profiling.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,49 @@ t8_forest_profile_get_forest_offsets_runtime (t8_forest_t forest);
210210
*/
211211
double
212212
t8_forest_profile_get_first_descendant_runtime (t8_forest_t forest);
213+
214+
/** Get the sum of the runtimes of the last calls to \ref check_element in search.
215+
* \param [in] forest The forest.
216+
* \return The time
217+
* \a forest must be committed before calling this function.
218+
* \see t8_forest_set_profiling
219+
*/
220+
double
221+
t8_forest_profile_get_search_check_element_runtime (t8_forest_t forest);
222+
/** Get the sum of the runtimes of the last calls to \ref check_element in search.
223+
* \param [in] forest The forest.
224+
* \return The time
225+
* \a forest must be committed before calling this function.
226+
* \see t8_forest_set_profiling
227+
*/
228+
double
229+
t8_forest_profile_get_search_check_query_runtime (t8_forest_t forest);
230+
/** Get the sum of the runtimes of the last calls to \ref check_query in search.
231+
* \param [in] forest The forest.
232+
* \return The time
233+
* \a forest must be committed before calling this function.
234+
* \see t8_forest_set_profiling
235+
*/
236+
double
237+
t8_forest_profile_get_search_split_array_runtime (t8_forest_t forest);
238+
/** Get the sum of the runtimes of the last calls to \ref split_array in search.
239+
* \param [in] forest The forest.
240+
* \return The time
241+
* \a forest must be committed before calling this function.
242+
* \see t8_forest_set_profiling
243+
*/
244+
double
245+
t8_forest_profile_get_search_check_element_runtime (t8_forest_t forest);
246+
/** Get the runtime of the last call to \ref search.
247+
* \param [in] forest The forest.
248+
* \return The time
249+
* \a forest must be committed before calling this function.
250+
* \see t8_forest_set_profiling
251+
*/
252+
double
253+
t8_forest_profile_get_search_total_runtime (t8_forest_t forest);
254+
255+
213256
T8_EXTERN_C_END ();
214257

215258
#endif /* !T8_FOREST_PROFILING_H */

src/t8_forest/t8_forest_search/t8_forest_search.cxx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,40 @@ t8_search_base::search_recursion (const t8_locidx_t ltreeid, t8_element_t *eleme
6464
}
6565
}
6666
/* Call the callback function for the element */
67+
if (forest->profile != NULL) {
68+
/* If profiling is enabled, we measure the runtime of partition */
69+
forest->profile->search_check_element_time -= sc_MPI_Wtime ();
70+
}
6771
const bool ret = check_element (ltreeid, element, is_leaf, leaf_elements, tree_lindex_of_first_leaf);
72+
if (forest->profile != NULL) {
73+
/* If profiling is enabled, we measure the runtime of partition */
74+
forest->profile->search_check_element_time += sc_MPI_Wtime ();
75+
}
6876

6977
if (!ret) {
7078
/* The function returned false. We abort the recursion */
7179
return;
7280
}
7381
std::vector<size_t> new_active_queries;
82+
if (forest->profile != NULL) {
83+
/* If profiling is enabled, we measure the runtime of partition */
84+
forest->profile->search_check_query_time -= sc_MPI_Wtime ();
85+
}
7486
this->check_queries (new_active_queries, ltreeid, element, is_leaf, leaf_elements, tree_lindex_of_first_leaf);
75-
87+
if (forest->profile != NULL) {
88+
/* If profiling is enabled, we measure the runtime of partition */
89+
forest->profile->search_check_query_time += sc_MPI_Wtime ();
90+
}
7691
if (is_leaf) {
7792
return;
7893
}
7994

95+
96+
if (forest->profile != NULL) {
97+
/* If profiling is enabled, we measure the runtime of partition */
98+
forest->profile->search_split_array_time -= sc_MPI_Wtime ();
99+
}
100+
80101
/* Enter the recursion (the element is definitely not a leaf at this point) */
81102
/* We compute all children of E, compute their leaf arrays and call search_recursion */
82103
/* allocate the memory to store the children */
@@ -89,6 +110,11 @@ t8_search_base::search_recursion (const t8_locidx_t ltreeid, t8_element_t *eleme
89110
ts->element_get_children (eclass, element, num_children, children);
90111
/* Split the leaves array in portions belonging to the children of element */
91112
t8_forest_split_array (element, leaf_elements, split_offsets);
113+
if (forest->profile != NULL) {
114+
/* If profiling is enabled, we measure the runtime of partition */
115+
forest->profile->search_split_array_time += sc_MPI_Wtime ();
116+
}
117+
92118
for (int ichild = 0; ichild < num_children; ichild++) {
93119
/* Check if there are any leaf elements for this child */
94120
const size_t indexa = split_offsets[ichild]; /* first leaf of this child */
@@ -135,12 +161,23 @@ t8_search_base::search_tree (const t8_locidx_t ltreeid)
135161
void
136162
t8_search_base::do_search ()
137163
{
164+
if (forest->profile != NULL) {
165+
/* If profiling is enabled, we measure the runtime of partition */
166+
forest->profile->search_time = -sc_MPI_Wtime ();
167+
forest->profile->search_check_element_time = 0;
168+
forest->profile->search_check_query_time = 0;
169+
forest->profile->search_split_array_time = 0;
170+
}
138171
T8_ASSERT (t8_forest_is_committed (forest));
139172
const t8_locidx_t num_local_trees = t8_forest_get_num_local_trees (this->forest);
140173
for (t8_locidx_t itree = 0; itree < num_local_trees; itree++) {
141174
this->init_queries ();
142175
this->search_tree (itree);
143176
}
177+
if (forest->profile != NULL) {
178+
/* If profiling is enabled, we measure the runtime of partition */
179+
forest->profile->search_time += sc_MPI_Wtime ();
180+
}
144181
}
145182

146183
/* #################### t8_forest_search c interface #################### */

src/t8_forest/t8_forest_types.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef int8_t t8_forest_from_t;
6262
#define T8_FOREST_BALANCE_NO_REPART 2 /**< Value of forest->set_balance if balancing without repartitioning */
6363

6464
/** The number of statistics collected by a profile struct. */
65-
#define T8_PROFILE_NUM_STATS 17
65+
#define T8_PROFILE_NUM_STATS 21
6666

6767
/** This structure is private to the implementation. */
6868
typedef struct t8_forest
@@ -187,7 +187,10 @@ typedef struct t8_profile
187187
double cmesh_offsets_runtime; /**< The runtime of the last call to \a t8_forest_partition_create_tree_offsets. */
188188
double forest_offsets_runtime; /**< The runtime of the last call to \a t8_forest_partition_create_offsets. */
189189
double first_descendant_runtime; /**< The runtime of the last call to \a t8_forest_partition_create_first_desc. */
190-
190+
double search_time;
191+
double search_check_element_time;
192+
double search_check_query_time;
193+
double search_split_array_time;
191194
} t8_profile_struct_t;
192195

193196
/**

0 commit comments

Comments
 (0)