From aba708ed6ad41e0a3ef351d1762bebd61b41c766 Mon Sep 17 00:00:00 2001 From: Alex Dutka <97711898+dutkalex@users.noreply.github.com> Date: Tue, 30 Sep 2025 12:06:53 +0200 Subject: [PATCH 1/3] add t8_cmesh->mpicomm --- src/t8_cmesh.h | 47 +++++++++++++----------- src/t8_cmesh/t8_cmesh.cxx | 61 +++++++++++++++----------------- src/t8_cmesh/t8_cmesh_commit.cxx | 8 +++-- src/t8_cmesh/t8_cmesh_types.h | 1 + 4 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/t8_cmesh.h b/src/t8_cmesh.h index 9265632c98..fa49bb4b66 100644 --- a/src/t8_cmesh.h +++ b/src/t8_cmesh.h @@ -34,7 +34,7 @@ #include /** Forward pointer reference to hidden cmesh implementation. - * This reference needs to be known by t8_geometry, hence we + * This reference needs to be known by t8_geometry, hence we * put it before the include. */ typedef struct t8_cmesh *t8_cmesh_t; @@ -320,7 +320,7 @@ t8_cmesh_set_attribute_gloidx_array (t8_cmesh_t cmesh, t8_gloidx_t gtree_id, int * \param [in] face1 The face number of the first tree. * \param [in] face2 The face number of the second tree. * \param [in] orientation Specify how face1 and face2 are oriented to each other - * + * * \note The orientation is defined as: * Let my_face and other_face be the two face numbers of the connecting trees. * We chose a main_face from them as follows: Either both trees have the same @@ -405,7 +405,7 @@ t8_cmesh_reorder (t8_cmesh_t cmesh, sc_MPI_Comm comm); /** Register a geometry in the cmesh. The cmesh takes ownership of the geometry. * \param [in,out] cmesh The cmesh. * \param [in] geometry The geometry to register. - * + * * If no geometry is registered and cmesh is modified from another cmesh then * the other cmesh's geometries are used. * \note If you need to use \ref t8_cmesh_bcast, then all geometries must be @@ -435,10 +435,10 @@ t8_cmesh_commit (t8_cmesh_t cmesh, sc_MPI_Comm comm); /** * Save the cmesh to a file with the given fileprefix. - * + * * \param[in] cmesh The cmesh to save. * \param[in] fileprefix The prefix of the file to save the cmesh to. - * + * * \note Currently, it is only legal to save cmeshes that use the linear geometry. */ int @@ -446,7 +446,7 @@ t8_cmesh_save (t8_cmesh_t cmesh, const char *fileprefix); /** * Load a cmesh from a file. - * + * * \param[in] filename The name of the file to load the cmesh from. * \param[in] comm The MPI communicator to use. */ @@ -455,13 +455,13 @@ t8_cmesh_load (const char *filename, sc_MPI_Comm comm); /** * Load a cmesh from multiple files and distribute it across the processes. - * + * * \param[in] fileprefix The prefix of the files to load the cmesh from. * \param[in] num_files The number of files to load. * \param[in] comm The MPI communicator to use. * \param[in] mode The load mode to use, see \ref t8_load_mode_t. * \param[in] procs_per_node The number of processes per node, only relevant in JUQUEEN mode. - * + * * \note \a procs_per_node is only relevant in mode==JUQUEEN. If \a num_files = 1 a replicated cmesh is constructed. */ t8_cmesh_t @@ -480,6 +480,13 @@ t8_cmesh_load_and_distribute (const char *fileprefix, int num_files, sc_MPI_Comm int t8_cmesh_comm_is_valid (t8_cmesh_t cmesh, sc_MPI_Comm comm); +/** Get the MPI communicator associated to the cmesh + * \param [in] cmesh The cmesh, which must be committed + * \return The MPI communicator provided at the commit of the cmesh + */ +sc_MPI_Comm +t8_cmesh_get_mpicomm (t8_cmesh_t cmesh); + /** Query whether a committed cmesh is partitioned or replicated. * \param [in] cmesh A committed cmesh. * \return True if \a cmesh is partitioned. @@ -721,7 +728,7 @@ t8_cmesh_get_attribute (const t8_cmesh_t cmesh, const int package_id, const int * \param [in] key A key used to identify the attribute under all * attributes of this tree with the same \a package_id. * \param [in] ltree_id The local number of the tree. - * \param [in] data_count The number of entries in the array that are requested. + * \param [in] data_count The number of entries in the array that are requested. * This must be smaller or equal to the \a data_count parameter * of the corresponding call to \ref t8_cmesh_set_attribute_gloidx_array * \return The attribute pointer of the tree \a ltree_id or NULL if the attribute is not found. @@ -761,7 +768,7 @@ t8_cmesh_get_partition_table (t8_cmesh_t cmesh); * the calling processor anymore. Not computed if NULL. * \param [out] first_tree_shared If not NULL, 1 or 0 is stored here depending on whether \a first_local_tree is the * same as \a last_local_tree on the previous process. - * \a cmesh must be committed before calling this function. + * \a cmesh must be committed before calling this function. */ void t8_cmesh_uniform_bounds_equal_element_count (t8_cmesh_t cmesh, const int level, const t8_scheme_c *tree_scheme, @@ -770,11 +777,11 @@ t8_cmesh_uniform_bounds_equal_element_count (t8_cmesh_t cmesh, const int level, int8_t *first_tree_shared); /** - * Calculate the section of a uniform hybrid forest for the current rank. Needed for hybrid meshes, especially + * Calculate the section of a uniform hybrid forest for the current rank. Needed for hybrid meshes, especially * meshes where not all elements refine into 1:2^dim manner. The section is calculated without assuming such refinement * and each process computes its number of elements on the given \a level, communicates the number to other processes, - * and the correct section is computed based on this information. - * + * and the correct section is computed based on this information. + * * \param [in] cmesh The cmesh to be considered. * \param [in] level The uniform refinement level to be created. * \param [in] scheme The element scheme for which to compute the bounds. @@ -785,7 +792,7 @@ t8_cmesh_uniform_bounds_equal_element_count (t8_cmesh_t cmesh, const int level, * the calling process anymore. Not computed if NULL. * \param [out] first_tree_shared If not NULL, 1 or 0 is stored here depending on whether \a first_local_tree is the * same as \a last_local_tree on the previous process. - * \param [in] comm The communicator + * \param [in] comm The communicator */ void t8_cmesh_uniform_bounds_for_irregular_refinement (const t8_cmesh_t cmesh, const int level, const t8_scheme_c *scheme, @@ -826,7 +833,7 @@ void t8_cmesh_destroy (t8_cmesh_t *pcmesh); /** Compute y = ax + b on an array of doubles, interpreting - * each 3 as one vector x + * each 3 as one vector x * \param[in] coords_in The incoming coordinates of the vectors * \param[out] coords_out The computed coordinates of the vectors * \param[in] num_vertices The number of vertices/vectors @@ -836,7 +843,7 @@ t8_cmesh_destroy (t8_cmesh_t *pcmesh); void t8_cmesh_coords_axb (const double *coords_in, double *coords_out, int num_vertices, double alpha, const double b[3]); -/** Compute y = x + translate on an array of doubles, interpreting +/** Compute y = x + translate on an array of doubles, interpreting * each 3 as one vector x * \param[in] coords_in The incoming coordinates of the vectors * \param[out] coords_out The computed coordinates of the vectors @@ -853,11 +860,11 @@ t8_cmesh_new_translate_vertices_to_attributes (const t8_locidx_t *tvertices, con double *attr_vertices, const int num_vertices); /** - * \warning This function is only available in debug-modus and should only + * \warning This function is only available in debug-modus and should only * be used in debug-modus. - * + * * Prints the vertices of each tree of each process - * + * * \param[in] cmesh Source-cmesh, which trees get printed. * \param[in] comm The MPI communicator to use for printing. */ @@ -873,7 +880,7 @@ t8_cmesh_debug_print_trees (const t8_cmesh_t cmesh, sc_MPI_Comm comm); * bounds[3] = y_max * bounds[4] = z_min * bounds[5] = z_max - * + * * \param [in] cmesh The cmesh to be considered. * \param [out] bounds The bounding box of the cmesh. If the box is flat (for quads for example, z_min == z_max) * diff --git a/src/t8_cmesh/t8_cmesh.cxx b/src/t8_cmesh/t8_cmesh.cxx index 177a147d96..5e7d945719 100644 --- a/src/t8_cmesh/t8_cmesh.cxx +++ b/src/t8_cmesh/t8_cmesh.cxx @@ -175,16 +175,13 @@ t8_cmesh_validate_geometry (const t8_cmesh_t cmesh) int t8_cmesh_comm_is_valid (const t8_cmesh_t cmesh, sc_MPI_Comm comm) { - int mpiret, mpisize, mpirank; + return cmesh->mpicomm == comm; +} - mpiret = sc_MPI_Comm_rank (comm, &mpirank); - SC_CHECK_MPI (mpiret); - mpiret = sc_MPI_Comm_size (comm, &mpisize); - SC_CHECK_MPI (mpiret); - if (mpisize != cmesh->mpisize || mpirank != cmesh->mpirank) { - return 0; - } - return 1; +sc_MPI_Comm +t8_cmesh_get_mpicomm (const t8_cmesh_t cmesh) +{ + return cmesh->mpicomm; } void @@ -1623,7 +1620,7 @@ t8_cmesh_uniform_bounds_equal_element_count (t8_cmesh_t cmesh, const int level, *child_in_tree_end = (last_global_child - *last_local_tree * children_per_tree); } if (is_empty) { - /* This process is empty + /* This process is empty * We now set the first local tree to the first local tree that is owned by the * next nonempty rank, and the last local tree to first - 1 */ *first_local_tree = last_global_child / children_per_tree; @@ -1645,7 +1642,7 @@ t8_cmesh_uniform_bounds_equal_element_count (t8_cmesh_t cmesh, const int level, * \param[in] num_procs The total number of processes. * \param[in] process_offset The offset of the current process in the global numbering. * \return The rank of the process that will have the element in a uniform partition. - * + * * \note This function is used standalone and as a callback for vector splitting */ static size_t @@ -1753,7 +1750,7 @@ t8_cmesh_uniform_bounds_from_unpartioned (const t8_cmesh_t cmesh, const t8_gloid // Loop over all trees to find the ones containing the first and last element of this process for (t8_gloidx_t igtree = 0; igtree < num_trees; ++igtree) { const t8_eclass_t tree_class = t8_cmesh_get_tree_class (cmesh, (t8_locidx_t) igtree); - /* TODO: We can optimize by buffering the num_leaf_elems_in_tree value. Thus, if + /* TODO: We can optimize by buffering the num_leaf_elems_in_tree value. Thus, if the computation is expensive (may be for non-morton-type schemes), we do it only once. */ const t8_gloidx_t num_leaf_elems_in_tree = scheme->count_leaves_from_root (tree_class, level); @@ -1795,9 +1792,9 @@ t8_cmesh_uniform_bounds_from_unpartioned (const t8_cmesh_t cmesh, const t8_gloid } /** - * Send the start or end message to the process given by iproc. The message contains the global id of the first/last tree and + * Send the start or end message to the process given by iproc. The message contains the global id of the first/last tree and * the global id of the first/last element in the tree. - * + * * \param[in] cmesh The cmesh. * \param[in] start_message If true, send the start message, otherwise send the end message. * \param[in] proc_is_empty If true, the process the message will be send to is empty. @@ -1809,13 +1806,13 @@ t8_cmesh_uniform_bounds_from_unpartioned (const t8_cmesh_t cmesh, const t8_gloid * \param[in] current_pos_in_send_buffer The current position in the send buffer. * \param[in] first_or_last_element_in_tree_index_of_iproc The tree-local id of the first/last element in the tree. If we send an end message, this is the tree-local index of the last tree on this process. * \param[in, out] first_or_last_local_tree The global id of the first/last tree of the current process. - * \param[in, out] first_tree_shared The first tree shared flag. Only used if we send the start message. Set to NULL if not used. + * \param[in, out] first_tree_shared The first tree shared flag. Only used if we send the start message. Set to NULL if not used. * \param[in, out] child_in_tree_end_or_begin The tree-local id of the first/last element in the tree. Set to NULL if not used. * \param[in, out] expect_start_or_end_message If true, we expect a start or end message from the process. * \param[in] comm The MPI communicator. * \param[in, out] num_received_start_or_end_messages The number of received start or end messages. Only used if T8_ENABLE_DEBUG is defined. * \param[in, out] num_message_sent The number of sent messages. Only used if T8_ENABLE_DEBUG is defined. - * + * */ static void t8_cmesh_bounds_send_start_or_end (const t8_cmesh_t cmesh, const bool start_message, const bool proc_is_empty, @@ -1865,7 +1862,7 @@ t8_cmesh_bounds_send_start_or_end (const t8_cmesh_t cmesh, const bool start_mess } } if (child_in_tree_end_or_begin != NULL) { - /* If we send the last element add 1 to the id. During later processing of the cmesh we iterate + /* If we send the last element add 1 to the id. During later processing of the cmesh we iterate * as long as ielement < child_in_tree_end. Therefore we have to shift by one. */ *child_in_tree_end_or_begin = first_or_last_element_in_tree_index_of_iproc; } @@ -1875,8 +1872,8 @@ t8_cmesh_bounds_send_start_or_end (const t8_cmesh_t cmesh, const bool start_mess } /** - * Receive a start or end message. Which is defined by the \a start flag. - * + * Receive a start or end message. Which is defined by the \a start flag. + * * \param[in] start If true, receive the start message, otherwise receive the end message. * \param[in, out] first_last_local_tree On Input empty but allocated, on output the global id of the first or last tree of the current process. * \param[in, out] child_in_tree_begin_end On Input empty but allocated, on output the global id of the first or last element in the tree of the current process. @@ -1925,13 +1922,13 @@ recv_message (const bool start, t8_gloidx_t *first_last_local_tree, t8_gloidx_t } /** - * Find the bounds of a value in a given offset array. Used for a binary search to find the + * Find the bounds of a value in a given offset array. Used for a binary search to find the * rank that contains the value. - * + * * \param[in] array The offset array. * \param[in] guess The index to start searching from. * \param[in] value The value to find the bounds for. - * + * * \return 0 if the value is within the bounds, -1 if it is below the bounds, and 1 otherwise. */ inline int @@ -2001,7 +1998,7 @@ t8_cmesh_uniform_bounds_from_partition (const t8_cmesh_t cmesh, const t8_gloidx_ first_element_tree[0] = t8_shmem_array_get_gloidx (offset_array, cmesh->mpirank); /* Compute the first element in every pure local tree. - * This array stores for each tree the global element index offset. + * This array stores for each tree the global element index offset. * Example: 2 local trees, each has 8 Elements. First element index 12: | 12 | 20 | 28 | */ for (t8_locidx_t itree = 0; itree < num_pure_local_trees; ++itree, ++igtree) { const t8_eclass_t tree_class = t8_cmesh_get_tree_class (cmesh, igtree); @@ -2071,7 +2068,7 @@ t8_cmesh_uniform_bounds_from_partition (const t8_cmesh_t cmesh, const t8_gloidx_ belongs to send_first+i. If no such tree exists, then the index of the previous process is stored. - Examples: + Examples: We describe the situation via Proc i needs tree first local_tree_id, with i as the index in send_first + i. @@ -2125,7 +2122,7 @@ t8_cmesh_uniform_bounds_from_partition (const t8_cmesh_t cmesh, const t8_gloidx_ const t8_locidx_t possibly_first_puretree_of_next_proc = tree_offsets_partition[iproc + 1 - send_first]; const t8_gloidx_t first_el_index_of_first_tree = first_element_tree[possibly_first_puretree_of_iproc]; if (first_element_index_of_iproc >= first_element_tree[num_pure_local_trees]) { - /* We do not send to this process iproc at all. Its first element is in a tree that belongs + /* We do not send to this process iproc at all. Its first element is in a tree that belongs * to the next process. */ send_start_message = send_end_message = false; first_puretree_of_iproc = -1; @@ -2151,11 +2148,11 @@ t8_cmesh_uniform_bounds_from_partition (const t8_cmesh_t cmesh, const t8_gloidx_ } } /* Compute the last tree of this proc and whether we need to send an end message to it. */ - /* We know - * + /* We know + * * possibly_first_puretree_of_next_proc - The tree whose first element lies on the next process. - * - * + * + * * If the next process is empty, then possibly_first_puretree_of_next_proc = possibly_first_puretree_of_iproc * and this is our last tree. */ @@ -2237,7 +2234,7 @@ t8_cmesh_uniform_bounds_from_partition (const t8_cmesh_t cmesh, const t8_gloidx_ send_start_message = first_child_next_non_empty < first_element_tree[num_pure_local_trees]; if (send_start_message) { /* We might have detected a larger range of empty processes. We directly send to this range to avoid a recomputation - * of this information. We have to take into account, that in the last iteration of the above do-while-loop + * of this information. We have to take into account, that in the last iteration of the above do-while-loop * next_non_empty_proc has been added up by one again, so this loop goes [iproc, next_non_empty_proc - 1). */ for (t8_gloidx_t iempty_proc = iproc; iempty_proc < next_non_empty_proc; ++iempty_proc) { t8_cmesh_bounds_send_start_or_end (cmesh, send_start_message, proc_is_empty, first_puretree_of_iproc, @@ -2259,7 +2256,7 @@ t8_cmesh_uniform_bounds_from_partition (const t8_cmesh_t cmesh, const t8_gloidx_ /* * * MPI Communication for non-empty processes starts here - * + * */ /* Post the start message: We send the first tree id of the process @@ -2377,7 +2374,7 @@ t8_cmesh_uniform_bounds_for_irregular_refinement (const t8_cmesh_t cmesh, const int8_t *first_tree_shared, sc_MPI_Comm comm) { T8_ASSERT (cmesh != NULL); - /* TODO: Clean up size_t and gloidx_t data types, ensure that each variables has the + /* TODO: Clean up size_t and gloidx_t data types, ensure that each variables has the * matching type. */ t8_debugf ("Into t8_cmesh_uniform_bounds_for_irregular_refinement.\n"); diff --git a/src/t8_cmesh/t8_cmesh_commit.cxx b/src/t8_cmesh/t8_cmesh_commit.cxx index 60f4168ce1..151c083814 100644 --- a/src/t8_cmesh/t8_cmesh_commit.cxx +++ b/src/t8_cmesh/t8_cmesh_commit.cxx @@ -40,8 +40,8 @@ /** * A struct to hold the information about a ghost facejoin. - * - * It contains the global id of the ghost, the local id of the ghost, + * + * It contains the global id of the ghost, the local id of the ghost, * and the current number of inserted ghost attributes. */ typedef struct ghost_facejoins_struct @@ -514,7 +514,7 @@ t8_cmesh_commit_partitioned_new (t8_cmesh_t cmesh, sc_MPI_Comm comm) /** * Commit a cmesh from stash. - * + * * \param[in] cmesh The cmesh to commit. * \param[in] comm The MPI communicator to use. */ @@ -563,6 +563,8 @@ t8_cmesh_commit (t8_cmesh_t cmesh, sc_MPI_Comm comm) SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (comm, &cmesh->mpirank); SC_CHECK_MPI (mpiret); + cmesh->mpicomm = comm; + if (cmesh->set_from != NULL) { cmesh->dimension = cmesh->set_from->dimension; if (cmesh->face_knowledge == -1) { diff --git a/src/t8_cmesh/t8_cmesh_types.h b/src/t8_cmesh/t8_cmesh_types.h index 4f3a839660..3e7da53144 100644 --- a/src/t8_cmesh/t8_cmesh_types.h +++ b/src/t8_cmesh/t8_cmesh_types.h @@ -107,6 +107,7 @@ typedef struct t8_cmesh existing cmesh by copy or more elaborate modification, we store a pointer to this other cmesh here. */ + sc_MPI_Comm mpicomm; /**< MPI communicator associated to the cmesh */ int mpirank; /**< Number of this MPI process. */ int mpisize; /**< Number of MPI processes. */ t8_refcount_t rc; /**< The reference count of the cmesh. */ From bd6a0ef2c87e241fac6044fe9f1fdf00e7fc4d52 Mon Sep 17 00:00:00 2001 From: Alex Dutka <97711898+dutkalex@users.noreply.github.com> Date: Tue, 30 Sep 2025 13:45:19 +0200 Subject: [PATCH 2/3] comm_is_valid(cmesh, comm) -> get_mpicomm(cmesh) == comm --- src/t8_cmesh/t8_cmesh.cxx | 4 ++-- src/t8_cmesh/t8_cmesh_commit.cxx | 2 +- src/t8_cmesh/t8_cmesh_copy.c | 2 +- src/t8_cmesh/t8_cmesh_partition.cxx | 10 ++++----- src/t8_forest/t8_forest.cxx | 34 ++++++++++++++--------------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh.cxx b/src/t8_cmesh/t8_cmesh.cxx index 5e7d945719..aedd6fd70c 100644 --- a/src/t8_cmesh/t8_cmesh.cxx +++ b/src/t8_cmesh/t8_cmesh.cxx @@ -868,7 +868,7 @@ t8_cmesh_bcast (const t8_cmesh_t cmesh_in, const int root, sc_MPI_Comm comm) SC_CHECK_MPI (mpiret); if (!meta_info.pre_commit) { T8_ASSERT (t8_cmesh_is_committed (cmesh_out)); - T8_ASSERT (t8_cmesh_comm_is_valid (cmesh_out, comm)); + T8_ASSERT (t8_cmesh_get_mpicomm (cmesh_out) == comm); } #endif return cmesh_out; @@ -1242,7 +1242,7 @@ t8_cmesh_reset (t8_cmesh_t *pcmesh) * This is useful for debugging. */ if (t8_cmesh_is_committed (cmesh)) { comm = t8_shmem_array_get_comm (cmesh->tree_offsets); - T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm)); + T8_ASSERT (t8_cmesh_get_mpicomm (cmesh) == comm); } #endif /* Destroy the shared memory array */ diff --git a/src/t8_cmesh/t8_cmesh_commit.cxx b/src/t8_cmesh/t8_cmesh_commit.cxx index 151c083814..09786a5676 100644 --- a/src/t8_cmesh/t8_cmesh_commit.cxx +++ b/src/t8_cmesh/t8_cmesh_commit.cxx @@ -234,7 +234,7 @@ t8_cmesh_commit_partitioned_new (t8_cmesh_t cmesh, sc_MPI_Comm comm) sc_flops_snap (&fi, &snapshot); #endif - T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm)); + T8_ASSERT (t8_cmesh_get_mpicomm (cmesh) == comm); if (cmesh->face_knowledge != 3) { t8_global_errorf ("Expected a face knowledge of 3.\nAbort commit."); diff --git a/src/t8_cmesh/t8_cmesh_copy.c b/src/t8_cmesh/t8_cmesh_copy.c index 870a3aa8f7..78c74e65ad 100644 --- a/src/t8_cmesh/t8_cmesh_copy.c +++ b/src/t8_cmesh/t8_cmesh_copy.c @@ -54,7 +54,7 @@ t8_cmesh_copy (t8_cmesh_t cmesh, const t8_cmesh_t cmesh_from, sc_MPI_Comm comm) cmesh->num_trees = cmesh_from->num_trees; cmesh->set_partition = cmesh_from->set_partition; cmesh->set_partition_level = cmesh_from->set_partition_level; - T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm)); + T8_ASSERT (t8_cmesh_get_mpicomm (cmesh) == comm); /* Copy the tree_offsets */ if (cmesh_from->tree_offsets != NULL) { diff --git a/src/t8_cmesh/t8_cmesh_partition.cxx b/src/t8_cmesh/t8_cmesh_partition.cxx index 4f9a88a173..c27509ccbd 100644 --- a/src/t8_cmesh/t8_cmesh_partition.cxx +++ b/src/t8_cmesh/t8_cmesh_partition.cxx @@ -131,7 +131,7 @@ t8_cmesh_gather_trees_per_eclass (const t8_cmesh_t cmesh, sc_MPI_Comm comm) t8_gloidx_t temp_trees_per_eclass[T8_ECLASS_COUNT]; int ieclass; - T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm)); + T8_ASSERT (t8_cmesh_get_mpicomm (cmesh) == comm); if (cmesh->set_partition) { /* Copy the local values */ @@ -191,7 +191,7 @@ t8_cmesh_gather_treecount_ext (const t8_cmesh_t cmesh, sc_MPI_Comm comm, const i if (check_commit) { T8_ASSERT (t8_cmesh_is_committed (cmesh)); } - T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm)); + T8_ASSERT (t8_cmesh_get_mpicomm (cmesh) == comm); tree_offset = cmesh->first_tree_shared ? -cmesh->first_tree - 1 : cmesh->first_tree; if (cmesh->tree_offsets == NULL) { @@ -983,7 +983,7 @@ t8_cmesh_partition_sendloop (t8_cmesh_t cmesh, t8_cmesh_t cmesh_from, int *num_r int8_t *ghost_flag_send; /* For each local tree and ghost set to 1 if it is in send_as_ghost */ const t8_gloidx_t *offset_from, *offset_to; - T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm)); + T8_ASSERT (t8_cmesh_get_mpicomm (cmesh) == comm); /* We use two different flag arrays here, since ghost_flag_send needs to * be reset for each process we send to, while ghost_flag_keep keeps is entries. * Otherwise we could have set bitflags and only use one array */ @@ -1613,7 +1613,7 @@ t8_cmesh_partition (t8_cmesh_t cmesh, sc_MPI_Comm comm) /* Done with local num and tree_offset */ /***************************************************/ t8_cmesh_partition_given (cmesh, cmesh->set_from, tree_offsets, comm); - /* Deactivate the active tree. Tree related data (such as vertices) might have been moved by the new partition and + /* Deactivate the active tree. Tree related data (such as vertices) might have been moved by the new partition and * has to be loaded again if needed. */ if (cmesh->geometry_handler != NULL) { cmesh->geometry_handler->deactivate_tree (); @@ -1793,7 +1793,7 @@ t8_cmesh_offset_percent (const t8_cmesh_t cmesh, sc_MPI_Comm comm, const int per #endif T8_ASSERT (t8_cmesh_is_committed (cmesh)); - T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm)); + T8_ASSERT (t8_cmesh_get_mpicomm (cmesh) == comm); mpiret = sc_MPI_Comm_rank (comm, &mpirank); SC_CHECK_MPI (mpiret); diff --git a/src/t8_forest/t8_forest.cxx b/src/t8_forest/t8_forest.cxx index b607bb1fef..d8f1b46b3d 100644 --- a/src/t8_forest/t8_forest.cxx +++ b/src/t8_forest/t8_forest.cxx @@ -79,7 +79,7 @@ t8_forest_is_incomplete_family (const t8_forest_t forest, const t8_locidx_t ltre scheme->element_new (tree_class, 1, &element_parent_current); scheme->element_new (tree_class, 1, &element_compare); - /* We first assume that we have an (in)complete family with the size of array elements. + /* We first assume that we have an (in)complete family with the size of array elements. * In the following we try to disprove this. */ int family_size = elements_size; @@ -88,9 +88,9 @@ t8_forest_is_incomplete_family (const t8_forest_t forest, const t8_locidx_t ltre const int child_id_current = scheme->element_get_child_id (tree_class, elements[0]); scheme->element_get_parent (tree_class, elements[0], element_parent_current); - /* Elements of the current family could already be passed, so that + /* Elements of the current family could already be passed, so that * the element/family currently under consideration can no longer be coarsened. - * Also, there may be successors of a hypothetical previous family member + * Also, there may be successors of a hypothetical previous family member * that would be overlapped after coarsening. * */ if (child_id_current > 0 && el_considered > 0) { @@ -132,12 +132,12 @@ t8_forest_is_incomplete_family (const t8_forest_t forest, const t8_locidx_t ltre T8_ASSERT (family_size > 0); T8_ASSERT (family_size >= 0 && family_size <= elements_size); - /* There may be successors of a hypothetical later family member (with index + /* There may be successors of a hypothetical later family member (with index * family_size in this family) that would be overlapped after coarsening. */ if (family_size < elements_size) { /* Get level of element after last element of current possible family */ const int level = scheme->element_get_level (tree_class, elements[family_size]); - /* Only elements with higher level then level of current element, can get + /* Only elements with higher level then level of current element, can get * potentially be overlapped. */ if (level > level_current) { /* Compare ancestors */ @@ -160,7 +160,7 @@ t8_forest_is_incomplete_family (const t8_forest_t forest, const t8_locidx_t ltre const int num_siblings = scheme->element_get_num_siblings (tree_class, elements[0]); T8_ASSERT (family_size <= num_siblings); /* If the first/last element at a process boundary is not the first/last - * element of a possible family, we are not guaranteed to consider all + * element of a possible family, we are not guaranteed to consider all * family members.*/ if (el_considered == 0 && child_id_current > 0 && ltree_id == 0 && forest->mpirank > 0) { return 0; @@ -296,9 +296,9 @@ t8_forest_no_overlap ([[maybe_unused]] t8_forest_t forest) * More detailed: * Let e_a and e_b be two elements. * If the level of e_a is equal to the level of the nca of e_a and e_b, - * then e_b is a descendant of e_a. + * then e_b is a descendant of e_a. * If the level of e_b is equal to the level of the nca of e_a and e_b, - * then e_a is a descendant of e_b. + * then e_a is a descendant of e_b. * Thus e_a and e_b overlap in both cases. * Note: If e_a equals e_b, e_a is the descendant of e_b and vice versa. * */ @@ -1297,9 +1297,9 @@ t8_forest_tree_shared ([[maybe_unused]] t8_forest_t forest, [[maybe_unused]] int else { SC_ABORT ("For incomplete trees the method t8_forest_last_tree_shared aka " "t8_forest_tree_shared(forest, 1) is not implemented.\n"); - /* TODO: If last_local_tree is 0 of the current process and it gets 0 as the - * first_local_tree of the bigger process, then it cannot be said whether - * the tree with id 0 is shared or not, since the bigger process could also + /* TODO: If last_local_tree is 0 of the current process and it gets 0 as the + * first_local_tree of the bigger process, then it cannot be said whether + * the tree with id 0 is shared or not, since the bigger process could also * carry an empty forest. */ } /* If global_neighbour_tree_idx == forest->first_local_tree tree is shared */ @@ -1964,7 +1964,7 @@ t8_forest_element_is_leaf (const t8_forest_t forest, const t8_element_t *element T8_ASSERT (t8_forest_is_committed (forest)); T8_ASSERT (t8_forest_tree_is_local (forest, local_tree)); - /* We get the array of the tree's elements and then search in the array of elements for our + /* We get the array of the tree's elements and then search in the array of elements for our * element candidate. */ /* Get the array */ const t8_element_array_t *elements = t8_forest_get_tree_leaf_element_array (forest, local_tree); @@ -1986,7 +1986,7 @@ t8_forest_element_is_leaf (const t8_forest_t forest, const t8_element_t *element /* The element was not found. */ return 0; } - /* An element was found but it may not be the candidate element. + /* An element was found but it may not be the candidate element. * To identify whether the element was found, we compare these two. */ const t8_element_t *check_element = t8_element_array_index_locidx (elements, search_result); T8_ASSERT (check_element != NULL); @@ -2327,7 +2327,7 @@ t8_forest_element_find_owner_old (t8_forest_t forest, t8_gloidx_t gtreeid, t8_el return proc; } else { - /* Get the next owning process. Its first descendant is in fact an element of the tree. + /* Get the next owning process. Its first descendant is in fact an element of the tree. * If it is bigger than the descendant we look for, then proc is the owning process of element. */ proc_next = *(int *) sc_array_index (owners_of_tree, 1); if (*(t8_linearidx_t *) t8_shmem_array_index (forest->global_first_desc, (size_t) proc_next) @@ -2756,7 +2756,7 @@ t8_forest_set_cmesh (t8_forest_t forest, t8_cmesh_t cmesh, sc_MPI_Comm comm) t8_cmesh_unref (&forest->cmesh); } if (cmesh != NULL) { - T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm)); + T8_ASSERT (t8_cmesh_get_mpicomm (cmesh) == comm); } forest->cmesh = cmesh; do_dup = 0; @@ -2972,9 +2972,9 @@ t8_forest_comm_global_num_leaf_elements (t8_forest_t forest) * Check if any tree in a forest refines irregularly. * An irregular refining tree is a tree with an element that does not * refine into 2^dim children. For example the default implementation - * of pyramids. + * of pyramids. * \note This function is MPI collective - * + * * \param[in] forest The forest to check * \return Non-zero if any tree refines irregular */ From 3f2eb23cea164a956dffdbb6438f946a1f66687c Mon Sep 17 00:00:00 2001 From: Alex Dutka <97711898+dutkalex@users.noreply.github.com> Date: Tue, 7 Oct 2025 11:12:29 +0200 Subject: [PATCH 3/3] Update t8_cmesh_comm_is_valid documantation --- src/t8_cmesh.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/t8_cmesh.h b/src/t8_cmesh.h index fa49bb4b66..2509576fd4 100644 --- a/src/t8_cmesh.h +++ b/src/t8_cmesh.h @@ -468,12 +468,10 @@ t8_cmesh_t t8_cmesh_load_and_distribute (const char *fileprefix, int num_files, sc_MPI_Comm comm, t8_load_mode_t mode, int procs_per_node); -/** Check whether a given MPI communicator assigns the same rank and mpisize - * as stored in a cmesh. +/** Check whether a given MPI communicator matches the cmesh communicator. * \param [in] cmesh The cmesh to be considered. * \param [in] comm A MPI communicator. - * \return True if mpirank and mpisize from \a comm are the same as - * the values stored in \a cmesh. + * \return True if \a comm is the communicator \a cmesh was commited with. * False otherwise. * \a cmesh must be committed before calling this function. * */