Path: blob/main/src/t8_cmesh/t8_cmesh_internal/t8_cmesh_offset.h
914 views
/*1This file is part of t8code.2t8code is a C library to manage a collection (a forest) of multiple3connected adaptive space-trees of general element classes in parallel.45Copyright (C) 2015 the developers67t8code is free software; you can redistribute it and/or modify8it under the terms of the GNU General Public License as published by9the Free Software Foundation; either version 2 of the License, or10(at your option) any later version.1112t8code is distributed in the hope that it will be useful,13but WITHOUT ANY WARRANTY; without even the implied warranty of14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15GNU General Public License for more details.1617You should have received a copy of the GNU General Public License18along with t8code; if not, write to the Free Software Foundation, Inc.,1951 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.20*/2122/** \file t8_cmesh_offset.h23* In this file we collect functions that deal with24* the cmesh partition offset.25*/2627#ifndef T8_CMESH_OFFSET_H28#define T8_CMESH_OFFSET_H2930#include <t8.h>31#include <t8_cmesh/t8_cmesh.h>3233T8_EXTERN_C_BEGIN ();3435/** Return the global id of the first local tree36* of a given process in a partition.37* \param [in] proc The rank of the process.38* \param [in] offset The partition table.39* \return The global id of the first local tree40* of \a proc in the partition \a offset.41*/42t8_gloidx_t43t8_offset_first (const int proc, const t8_gloidx_t *offset);4445/** Given the global tree id of the first local tree of a process and46* the flag whether it is shared or not, compute the entry in the offset array.47* This entry is the first_tree if it is not shared and48* -first_tree - 1 if it is shared.49* \param [in] first_tree The global tree id of a process's first tree.50* \param [in] shared 0 if \a first_tree is not shared with a smaller rank,51* 1 if it is.52* \return The entry that represents the process in an offset array.53* \a first_tree if \a shared == 054* - \a first_tree - 1 if \a shared != 055*/56t8_gloidx_t57t8_offset_first_tree_to_entry (const t8_gloidx_t first_tree, const int shared);5859/** The number of trees of a given process in a partition.60* \param [in] proc A mpi rank.61* \param [in] offset A partition table.62* \return The number of local trees of \a proc63* in the partition \a offset.64*/65t8_gloidx_t66t8_offset_num_trees (const int proc, const t8_gloidx_t *offset);6768/** Return the last local tree of a given process in a partition.69* \param [in] proc A mpi rank.70* \param [in] offset A partition table.71* \return The global tree id of the last local tree of72* \a proc in \a offset.73*/74t8_gloidx_t75t8_offset_last (const int proc, const t8_gloidx_t *offset);7677/** Check whether a given process has no local trees in a given partition.78* \param [in] proc A mpi rank.79* \param [in] offset A partition table.80* \return nonzero if \a proc does not have local trees in \a offset.81* 0 otherwise.82*/83int84t8_offset_empty (const int proc, const t8_gloidx_t *offset);8586/** Find the next higher rank that is not empty.87* returns mpisize if this rank does not exist.88* \param [in] rank An MPI rank.89* \param [in] mpisize The number of total MPI ranks.90* \param [in] offset An array with at least \a mpisize + 1 entries.91* \return A rank \a p such that \a p > \a rank and92* t8_offset_empty (\a p, \a offset) is True and93* t8_offset_empty (\a q, \a offset) is False for all94* \a rank < \a q < \a p.95* If no such \a q exists, \a mpisize is returned.96*/97int98t8_offset_next_nonempty_rank (const int rank, const int mpisize, const t8_gloidx_t *offset);99100#if T8_ENABLE_DEBUG101/** Check whether a given offset array represents a valid102* partition.103* That is:104* - the entries in the offset array are increasing,105* - if a process is empty then its first tree is not shared,106* - if a process is not empty its first tree must be bigger than the last107* tree of the previous non-empty process, or equal to it if it is shared.108* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.109* \param [in] offset_shmem The partition to be considered.110* \param [in] num_trees The total number of global trees in the partition.111* \return nonzero if the partition is valid,112* 0 if not.113*/114int115t8_offset_consistent (const int mpisize, const t8_shmem_array_t offset_shmem, const t8_gloidx_t num_trees);116#endif117118/** Determine whether a given global tree id is a local tree of119* a given process in a certain partition.120* \param [in] tree_id A global tree id.121* \param [in] proc A mpi rank.122* \param [in] offset A partition table.123* \return nonzero if \a tree_id is a local tree of \a proc in \a offset.124* 0 if it is not.125*/126int127t8_offset_in_range (const t8_gloidx_t tree_id, const int proc, const t8_gloidx_t *offset);128129/** Find any process that has a given tree as local tree.130* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.131* \param [in] gtree The global id of a tree.132* \param [in] offset The partition to be considered.133* \return An MPI rank that has \a gtree as a local tree.134*/135int136t8_offset_any_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset);137138/** Find any process that has a given tree as local tree.139* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.140* \param [in] start_proc The mpirank to start the search with.141* \param [in] gtree The global id of a tree.142* \param [in] offset The partition to be considered.143* \return An MPI rank that has \a gtree as a local tree.144*/145int146t8_offset_any_owner_of_tree_ext (const int mpisize, const int start_proc, const t8_gloidx_t gtree,147const t8_gloidx_t *offset);148149/** Find the smallest process that has a given tree as local tree.150* To increase the runtime, an arbitrary process having this tree as local tree151* can be passed as an argument.152* Otherwise, such an owner is computed during the call.153* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.154* \param [in] gtree The global id of a tree.155* \param [in] offset The partition to be considered.156* \param [in] some_owner If >= 0 considered as input: a process that has \a gtree as local tree.157* If < 0 on output a process that has \a gtree as local tree.158* Specifying \a some_owner increases the runtime from159* O(log mpisize) to O(n), where n is the number of owners of the tree.160* \return The smallest rank that has \a gtree as a local tree.161*/162int163t8_offset_first_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset, int *some_owner);164165/** Find the biggest process that has a given tree as local tree.166* To increase the runtime, an arbitrary process having this tree as local tree167* can be passed as an argument.168* Otherwise, such an owner is computed during the call.169* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.170* \param [in] gtree The global id of a tree.171* \param [in] offset The partition to be considered.172* \param [in,out] some_owner If >= 0 considered as input: a process that has \a gtree as local tree.173* If < 0 on output a process that has \a gtree as local tree.174* Specifying \a some_owner increases the runtime from175* O(log mpisize) to O(n), where n is the number of owners of the tree.176* \return The biggest rank that has \a gtree as a local tree.177*/178int179t8_offset_last_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset, int *some_owner);180181/** Given a process current_owner that has the tree gtree as local tree,182* find the next bigger rank that also has this tree as local tree.183* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.184* \param [in] gtree The global id of a tree.185* \param [in] offset The partition to be considered.186* \param [in] current_owner A process that has \a gtree as local tree.187* \return The MPI rank of the next bigger rank than \a current_owner188* that has \a gtree as local tree.189* -1 if non such rank exists.190*/191int192t8_offset_next_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset, int current_owner);193194/** Given a process current_owner that has the tree gtree as local tree,195* find the next smaller rank that also has this tree as local tree.196* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.197* \param [in] gtree The global id of a tree.198* \param [in] offset The partition to be considered.199* \param [in] current_owner A process that has \a gtree as local tree.200* \return The MPI rank of the next smaller rank than \a current_owner201* that has \a gtree as local tree.202* -1 if non such rank exists.203*/204int205t8_offset_prev_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset,206const int current_owner);207208/** Compute a list of all processes that own a specific tree.n \a offset minus 1.209* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.210* \param [in] gtree The global index of a tree.211* \param [in] offset The partition to be considered.212* \param [in,out] owners On input an initialized sc_array with integer entries and213* zero elements. On output a sorted list of all MPI ranks that have214* \a gtree as a local tree in \a offset.215*/216void217t8_offset_all_owners_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset,218sc_array_t *owners);219220/** Query whether in a repartition setting a given process221* does send any of its local trees to any other process (including itself)222* \param [in] proc A mpi rank.223* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.224* \param [in] offset_from The partition table of the current partition.225* \param [in] offset_to The partition table of the next partition.226* \return nonzero if \a proc will not send any local trees if we repartition227* from \a offset_from to \a offset_to228* 0 if it does send local trees.229*/230int231t8_offset_nosend (int proc, int mpisize, const t8_gloidx_t *offset_from, const t8_gloidx_t *offset_to);232233/** Query whether in a repartitioning setting, a given process sends local trees (and then possibly ghosts) to a234* given other process.235* \param [in] proca Mpi rank of the possible sending process.236* \param [in] procb Mpi rank of the possible receiver.237* \param [in] t8_offset_from The partition table of the current partition.238* \param [in] t8_offset_to The partition table of the next partition.239* \return nonzero if \a proca does send local trees to \a procb when240* we repartition from \a offset_from to \a offset_to.241* 0 else.242*/243int244t8_offset_sendsto (int proca, int procb, const t8_gloidx_t *t8_offset_from, const t8_gloidx_t *t8_offset_to);245246/** Query whether in a repartitioning setting, a given process sends a given247* tree to a second process.248* \param [in] proc_send Mpi rank of the possible sending process.249* \param [in] proc_to Mpi rank of the possible receiver.250* \param [in] gtree A global tree id.251* \param [in] offset_from The partition table of the current partition.252* \param [in] offset_to The partition table of the next partition.253* \return nonzero if \a proc_send will send the tree \a gtree254* to \a proc_recv.255* 0 else.256* When calling, \a gtree must not be a local tree of \a proc_send in \a offset_from.257* In this case, 0 is always returned.258*/259int260t8_offset_sendstree (int proc_send, int proc_to, t8_gloidx_t gtree, const t8_gloidx_t *offset_from,261const t8_gloidx_t *offset_to);262263/** Count the number of processes in a given range [a,b] that send to264* a given other process in a repartitioning setting.265* \param [in] start The first mpi rank to be considered as sender.266* \param [in] end The last mpi rank to be considered as sender.267* \param [in] mpirank The mpirank to be considered as receiver.268* \param [in] offset_from The partition table of the current partition.269* \param [in] offset_to The partition table of the next partition.270* \return The number of processes p, such that271* \a start <= p <= \a end and p does send local trees (and possibly ghosts)272* to \a mpirank.273*/274int275t8_offset_range_send (int start, int end, int mpirank, const t8_gloidx_t *offset_from, const t8_gloidx_t *offset_to);276277/**278* Print the offsets of a partition.279*280* This function prints the offsets of a partition in a debug message.281*282* \param [in] offset The offsets to print.283* \param [in] comm The MPI communicator to use for printing.284*/285void286t8_offset_print (t8_shmem_array_t offset, sc_MPI_Comm comm);287288T8_EXTERN_C_END ();289290#endif /* !T8_CMESH_OFFSET_H */291292293