From 19c4bc69508f7a8fcd1be722463a9411348d6f31 Mon Sep 17 00:00:00 2001 From: Lukas Dreyer Date: Tue, 21 Oct 2025 16:16:56 +0200 Subject: [PATCH 1/3] Add timing for search --- src/t8_forest/t8_forest.cxx | 40 +++++++++++++++++ src/t8_forest/t8_forest_profiling.h | 43 +++++++++++++++++++ .../t8_forest_search/t8_forest_search.cxx | 39 ++++++++++++++++- src/t8_forest/t8_forest_types.h | 7 ++- 4 files changed, 126 insertions(+), 3 deletions(-) diff --git a/src/t8_forest/t8_forest.cxx b/src/t8_forest/t8_forest.cxx index fae7583008..e4c9f5f435 100644 --- a/src/t8_forest/t8_forest.cxx +++ b/src/t8_forest/t8_forest.cxx @@ -3799,6 +3799,10 @@ t8_forest_compute_profile (t8_forest_t forest) sc_stats_set1 (&forest->stats[14], profile->balance_rounds, "forest: Tree offset runtime."); sc_stats_set1 (&forest->stats[15], profile->balance_rounds, "forest: offset runtime."); sc_stats_set1 (&forest->stats[16], profile->balance_rounds, "forest: first descendant runtime."); + sc_stats_set1 (&forest->stats[17], profile->balance_rounds, "forest: search check element runtime."); + sc_stats_set1 (&forest->stats[18], profile->balance_rounds, "forest: search check queries runtime."); + sc_stats_set1 (&forest->stats[19], profile->balance_rounds, "forest: search split_array runtime."); + sc_stats_set1 (&forest->stats[20], profile->balance_rounds, "forest: search total runtime."); /* compute stats */ sc_stats_compute (sc_MPI_COMM_WORLD, T8_PROFILE_NUM_STATS, forest->stats); forest->stats_computed = 1; @@ -3968,6 +3972,42 @@ t8_forest_profile_get_first_descendant_runtime (t8_forest_t forest) } return 0; } +double +t8_forest_profile_get_search_check_element_runtime (t8_forest_t forest) +{ + T8_ASSERT (t8_forest_is_committed (forest)); + if (forest->profile != NULL) { + return forest->profile->search_check_element_time; + } + return 0; +} +double +t8_forest_profile_search_check_query_runtime (t8_forest_t forest) +{ + T8_ASSERT (t8_forest_is_committed (forest)); + if (forest->profile != NULL) { + return forest->profile->search_check_query_time; + } + return 0; +} +double +t8_forest_profile_search_split_array_runtime (t8_forest_t forest) +{ + T8_ASSERT (t8_forest_is_committed (forest)); + if (forest->profile != NULL) { + return forest->profile->search_split_array_time; + } + return 0; +} +double +t8_forest_profile_search_total_runtime (t8_forest_t forest) +{ + T8_ASSERT (t8_forest_is_committed (forest)); + if (forest->profile != NULL) { + return forest->profile->search_time; + } + return 0; +} void t8_forest_compute_elements_offset (t8_forest_t forest) diff --git a/src/t8_forest/t8_forest_profiling.h b/src/t8_forest/t8_forest_profiling.h index d4ffd3ee6c..ca350f5a3c 100644 --- a/src/t8_forest/t8_forest_profiling.h +++ b/src/t8_forest/t8_forest_profiling.h @@ -210,6 +210,49 @@ t8_forest_profile_get_forest_offsets_runtime (t8_forest_t forest); */ double t8_forest_profile_get_first_descendant_runtime (t8_forest_t forest); + +/** Get the sum of the runtimes of the last calls to \ref check_element in search. + * \param [in] forest The forest. + * \return The time + * \a forest must be committed before calling this function. + * \see t8_forest_set_profiling + */ +double +t8_forest_profile_get_search_check_element_runtime (t8_forest_t forest); +/** Get the sum of the runtimes of the last calls to \ref check_element in search. + * \param [in] forest The forest. + * \return The time + * \a forest must be committed before calling this function. + * \see t8_forest_set_profiling + */ +double +t8_forest_profile_get_search_check_query_runtime (t8_forest_t forest); +/** Get the sum of the runtimes of the last calls to \ref check_query in search. + * \param [in] forest The forest. + * \return The time + * \a forest must be committed before calling this function. + * \see t8_forest_set_profiling + */ +double +t8_forest_profile_get_search_split_array_runtime (t8_forest_t forest); +/** Get the sum of the runtimes of the last calls to \ref split_array in search. + * \param [in] forest The forest. + * \return The time + * \a forest must be committed before calling this function. + * \see t8_forest_set_profiling + */ +double +t8_forest_profile_get_search_check_element_runtime (t8_forest_t forest); +/** Get the runtime of the last call to \ref search. + * \param [in] forest The forest. + * \return The time + * \a forest must be committed before calling this function. + * \see t8_forest_set_profiling + */ +double +t8_forest_profile_get_search_total_runtime (t8_forest_t forest); + + T8_EXTERN_C_END (); #endif /* !T8_FOREST_PROFILING_H */ diff --git a/src/t8_forest/t8_forest_search/t8_forest_search.cxx b/src/t8_forest/t8_forest_search/t8_forest_search.cxx index a2a11cc2ee..c6516b7d34 100644 --- a/src/t8_forest/t8_forest_search/t8_forest_search.cxx +++ b/src/t8_forest/t8_forest_search/t8_forest_search.cxx @@ -64,19 +64,40 @@ t8_search_base::search_recursion (const t8_locidx_t ltreeid, t8_element_t *eleme } } /* Call the callback function for the element */ + if (forest->profile != NULL) { + /* If profiling is enabled, we measure the runtime of partition */ + forest->profile->search_check_element_time -= sc_MPI_Wtime (); + } const bool ret = check_element (ltreeid, element, is_leaf, leaf_elements, tree_lindex_of_first_leaf); + if (forest->profile != NULL) { + /* If profiling is enabled, we measure the runtime of partition */ + forest->profile->search_check_element_time += sc_MPI_Wtime (); + } if (!ret) { /* The function returned false. We abort the recursion */ return; } std::vector new_active_queries; + if (forest->profile != NULL) { + /* If profiling is enabled, we measure the runtime of partition */ + forest->profile->search_check_query_time -= sc_MPI_Wtime (); + } this->check_queries (new_active_queries, ltreeid, element, is_leaf, leaf_elements, tree_lindex_of_first_leaf); - + if (forest->profile != NULL) { + /* If profiling is enabled, we measure the runtime of partition */ + forest->profile->search_check_query_time += sc_MPI_Wtime (); + } if (is_leaf) { return; } + + if (forest->profile != NULL) { + /* If profiling is enabled, we measure the runtime of partition */ + forest->profile->search_split_array_time -= sc_MPI_Wtime (); + } + /* Enter the recursion (the element is definitely not a leaf at this point) */ /* We compute all children of E, compute their leaf arrays and call search_recursion */ /* 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 ts->element_get_children (eclass, element, num_children, children); /* Split the leaves array in portions belonging to the children of element */ t8_forest_split_array (element, leaf_elements, split_offsets); + if (forest->profile != NULL) { + /* If profiling is enabled, we measure the runtime of partition */ + forest->profile->search_split_array_time += sc_MPI_Wtime (); + } + for (int ichild = 0; ichild < num_children; ichild++) { /* Check if there are any leaf elements for this child */ 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) void t8_search_base::do_search () { + if (forest->profile != NULL) { + /* If profiling is enabled, we measure the runtime of partition */ + forest->profile->search_time = -sc_MPI_Wtime (); + forest->profile->search_check_element_time = 0; + forest->profile->search_check_query_time = 0; + forest->profile->search_split_array_time = 0; + } T8_ASSERT (t8_forest_is_committed (forest)); const t8_locidx_t num_local_trees = t8_forest_get_num_local_trees (this->forest); for (t8_locidx_t itree = 0; itree < num_local_trees; itree++) { this->init_queries (); this->search_tree (itree); } + if (forest->profile != NULL) { + /* If profiling is enabled, we measure the runtime of partition */ + forest->profile->search_time += sc_MPI_Wtime (); + } } /* #################### t8_forest_search c interface #################### */ diff --git a/src/t8_forest/t8_forest_types.h b/src/t8_forest/t8_forest_types.h index 7a6f5ab3cb..ed31e0dbdd 100644 --- a/src/t8_forest/t8_forest_types.h +++ b/src/t8_forest/t8_forest_types.h @@ -62,7 +62,7 @@ typedef int8_t t8_forest_from_t; #define T8_FOREST_BALANCE_NO_REPART 2 /**< Value of forest->set_balance if balancing without repartitioning */ /** The number of statistics collected by a profile struct. */ -#define T8_PROFILE_NUM_STATS 17 +#define T8_PROFILE_NUM_STATS 21 /** This structure is private to the implementation. */ typedef struct t8_forest @@ -187,7 +187,10 @@ typedef struct t8_profile double cmesh_offsets_runtime; /**< The runtime of the last call to \a t8_forest_partition_create_tree_offsets. */ double forest_offsets_runtime; /**< The runtime of the last call to \a t8_forest_partition_create_offsets. */ double first_descendant_runtime; /**< The runtime of the last call to \a t8_forest_partition_create_first_desc. */ - + double search_time; + double search_check_element_time; + double search_check_query_time; + double search_split_array_time; } t8_profile_struct_t; /** From e7879588d2389cb6f12475135457ffc382149285 Mon Sep 17 00:00:00 2001 From: "Dreyer, Lukas" Date: Wed, 22 Oct 2025 16:03:24 +0200 Subject: [PATCH 2/3] indent --- src/t8_forest/t8_forest_search/t8_forest_search.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/t8_forest/t8_forest_search/t8_forest_search.cxx b/src/t8_forest/t8_forest_search/t8_forest_search.cxx index c6516b7d34..ee28f93486 100644 --- a/src/t8_forest/t8_forest_search/t8_forest_search.cxx +++ b/src/t8_forest/t8_forest_search/t8_forest_search.cxx @@ -92,7 +92,6 @@ t8_search_base::search_recursion (const t8_locidx_t ltreeid, t8_element_t *eleme return; } - if (forest->profile != NULL) { /* If profiling is enabled, we measure the runtime of partition */ forest->profile->search_split_array_time -= sc_MPI_Wtime (); From 98ed04c6a25f59e419fc968c22166536e3de182a Mon Sep 17 00:00:00 2001 From: "Dreyer, Lukas" Date: Wed, 22 Oct 2025 16:15:24 +0200 Subject: [PATCH 3/3] indent --- src/t8_forest/t8_forest_profiling.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/t8_forest/t8_forest_profiling.h b/src/t8_forest/t8_forest_profiling.h index ca350f5a3c..b9277b8e5d 100644 --- a/src/t8_forest/t8_forest_profiling.h +++ b/src/t8_forest/t8_forest_profiling.h @@ -252,7 +252,6 @@ t8_forest_profile_get_search_check_element_runtime (t8_forest_t forest); double t8_forest_profile_get_search_total_runtime (t8_forest_t forest); - T8_EXTERN_C_END (); #endif /* !T8_FOREST_PROFILING_H */