Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/src/t8_cmesh/t8_cmesh_internal/t8_cmesh_offset.h
914 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 classes 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
/** \file t8_cmesh_offset.h
24
* In this file we collect functions that deal with
25
* the cmesh partition offset.
26
*/
27
28
#ifndef T8_CMESH_OFFSET_H
29
#define T8_CMESH_OFFSET_H
30
31
#include <t8.h>
32
#include <t8_cmesh/t8_cmesh.h>
33
34
T8_EXTERN_C_BEGIN ();
35
36
/** Return the global id of the first local tree
37
* of a given process in a partition.
38
* \param [in] proc The rank of the process.
39
* \param [in] offset The partition table.
40
* \return The global id of the first local tree
41
* of \a proc in the partition \a offset.
42
*/
43
t8_gloidx_t
44
t8_offset_first (const int proc, const t8_gloidx_t *offset);
45
46
/** Given the global tree id of the first local tree of a process and
47
* the flag whether it is shared or not, compute the entry in the offset array.
48
* This entry is the first_tree if it is not shared and
49
* -first_tree - 1 if it is shared.
50
* \param [in] first_tree The global tree id of a process's first tree.
51
* \param [in] shared 0 if \a first_tree is not shared with a smaller rank,
52
* 1 if it is.
53
* \return The entry that represents the process in an offset array.
54
* \a first_tree if \a shared == 0
55
* - \a first_tree - 1 if \a shared != 0
56
*/
57
t8_gloidx_t
58
t8_offset_first_tree_to_entry (const t8_gloidx_t first_tree, const int shared);
59
60
/** The number of trees of a given process in a partition.
61
* \param [in] proc A mpi rank.
62
* \param [in] offset A partition table.
63
* \return The number of local trees of \a proc
64
* in the partition \a offset.
65
*/
66
t8_gloidx_t
67
t8_offset_num_trees (const int proc, const t8_gloidx_t *offset);
68
69
/** Return the last local tree of a given process in a partition.
70
* \param [in] proc A mpi rank.
71
* \param [in] offset A partition table.
72
* \return The global tree id of the last local tree of
73
* \a proc in \a offset.
74
*/
75
t8_gloidx_t
76
t8_offset_last (const int proc, const t8_gloidx_t *offset);
77
78
/** Check whether a given process has no local trees in a given partition.
79
* \param [in] proc A mpi rank.
80
* \param [in] offset A partition table.
81
* \return nonzero if \a proc does not have local trees in \a offset.
82
* 0 otherwise.
83
*/
84
int
85
t8_offset_empty (const int proc, const t8_gloidx_t *offset);
86
87
/** Find the next higher rank that is not empty.
88
* returns mpisize if this rank does not exist.
89
* \param [in] rank An MPI rank.
90
* \param [in] mpisize The number of total MPI ranks.
91
* \param [in] offset An array with at least \a mpisize + 1 entries.
92
* \return A rank \a p such that \a p > \a rank and
93
* t8_offset_empty (\a p, \a offset) is True and
94
* t8_offset_empty (\a q, \a offset) is False for all
95
* \a rank < \a q < \a p.
96
* If no such \a q exists, \a mpisize is returned.
97
*/
98
int
99
t8_offset_next_nonempty_rank (const int rank, const int mpisize, const t8_gloidx_t *offset);
100
101
#if T8_ENABLE_DEBUG
102
/** Check whether a given offset array represents a valid
103
* partition.
104
* That is:
105
* - the entries in the offset array are increasing,
106
* - if a process is empty then its first tree is not shared,
107
* - if a process is not empty its first tree must be bigger than the last
108
* tree of the previous non-empty process, or equal to it if it is shared.
109
* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.
110
* \param [in] offset_shmem The partition to be considered.
111
* \param [in] num_trees The total number of global trees in the partition.
112
* \return nonzero if the partition is valid,
113
* 0 if not.
114
*/
115
int
116
t8_offset_consistent (const int mpisize, const t8_shmem_array_t offset_shmem, const t8_gloidx_t num_trees);
117
#endif
118
119
/** Determine whether a given global tree id is a local tree of
120
* a given process in a certain partition.
121
* \param [in] tree_id A global tree id.
122
* \param [in] proc A mpi rank.
123
* \param [in] offset A partition table.
124
* \return nonzero if \a tree_id is a local tree of \a proc in \a offset.
125
* 0 if it is not.
126
*/
127
int
128
t8_offset_in_range (const t8_gloidx_t tree_id, const int proc, const t8_gloidx_t *offset);
129
130
/** Find any process that has a given tree as local tree.
131
* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.
132
* \param [in] gtree The global id of a tree.
133
* \param [in] offset The partition to be considered.
134
* \return An MPI rank that has \a gtree as a local tree.
135
*/
136
int
137
t8_offset_any_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset);
138
139
/** Find any process that has a given tree as local tree.
140
* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.
141
* \param [in] start_proc The mpirank to start the search with.
142
* \param [in] gtree The global id of a tree.
143
* \param [in] offset The partition to be considered.
144
* \return An MPI rank that has \a gtree as a local tree.
145
*/
146
int
147
t8_offset_any_owner_of_tree_ext (const int mpisize, const int start_proc, const t8_gloidx_t gtree,
148
const t8_gloidx_t *offset);
149
150
/** Find the smallest process that has a given tree as local tree.
151
* To increase the runtime, an arbitrary process having this tree as local tree
152
* can be passed as an argument.
153
* Otherwise, such an owner is computed during the call.
154
* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.
155
* \param [in] gtree The global id of a tree.
156
* \param [in] offset The partition to be considered.
157
* \param [in] some_owner If >= 0 considered as input: a process that has \a gtree as local tree.
158
* If < 0 on output a process that has \a gtree as local tree.
159
* Specifying \a some_owner increases the runtime from
160
* O(log mpisize) to O(n), where n is the number of owners of the tree.
161
* \return The smallest rank that has \a gtree as a local tree.
162
*/
163
int
164
t8_offset_first_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset, int *some_owner);
165
166
/** Find the biggest process that has a given tree as local tree.
167
* To increase the runtime, an arbitrary process having this tree as local tree
168
* can be passed as an argument.
169
* Otherwise, such an owner is computed during the call.
170
* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.
171
* \param [in] gtree The global id of a tree.
172
* \param [in] offset The partition to be considered.
173
* \param [in,out] some_owner If >= 0 considered as input: a process that has \a gtree as local tree.
174
* If < 0 on output a process that has \a gtree as local tree.
175
* Specifying \a some_owner increases the runtime from
176
* O(log mpisize) to O(n), where n is the number of owners of the tree.
177
* \return The biggest rank that has \a gtree as a local tree.
178
*/
179
int
180
t8_offset_last_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset, int *some_owner);
181
182
/** Given a process current_owner that has the tree gtree as local tree,
183
* find the next bigger rank that also has this tree as local tree.
184
* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.
185
* \param [in] gtree The global id of a tree.
186
* \param [in] offset The partition to be considered.
187
* \param [in] current_owner A process that has \a gtree as local tree.
188
* \return The MPI rank of the next bigger rank than \a current_owner
189
* that has \a gtree as local tree.
190
* -1 if non such rank exists.
191
*/
192
int
193
t8_offset_next_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset, int current_owner);
194
195
/** Given a process current_owner that has the tree gtree as local tree,
196
* find the next smaller rank that also has this tree as local tree.
197
* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.
198
* \param [in] gtree The global id of a tree.
199
* \param [in] offset The partition to be considered.
200
* \param [in] current_owner A process that has \a gtree as local tree.
201
* \return The MPI rank of the next smaller rank than \a current_owner
202
* that has \a gtree as local tree.
203
* -1 if non such rank exists.
204
*/
205
int
206
t8_offset_prev_owner_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset,
207
const int current_owner);
208
209
/** Compute a list of all processes that own a specific tree.n \a offset minus 1.
210
* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.
211
* \param [in] gtree The global index of a tree.
212
* \param [in] offset The partition to be considered.
213
* \param [in,out] owners On input an initialized sc_array with integer entries and
214
* zero elements. On output a sorted list of all MPI ranks that have
215
* \a gtree as a local tree in \a offset.
216
*/
217
void
218
t8_offset_all_owners_of_tree (const int mpisize, const t8_gloidx_t gtree, const t8_gloidx_t *offset,
219
sc_array_t *owners);
220
221
/** Query whether in a repartition setting a given process
222
* does send any of its local trees to any other process (including itself)
223
* \param [in] proc A mpi rank.
224
* \param [in] mpisize The number of MPI ranks, also the number of entries in \a offset minus 1.
225
* \param [in] offset_from The partition table of the current partition.
226
* \param [in] offset_to The partition table of the next partition.
227
* \return nonzero if \a proc will not send any local trees if we repartition
228
* from \a offset_from to \a offset_to
229
* 0 if it does send local trees.
230
*/
231
int
232
t8_offset_nosend (int proc, int mpisize, const t8_gloidx_t *offset_from, const t8_gloidx_t *offset_to);
233
234
/** Query whether in a repartitioning setting, a given process sends local trees (and then possibly ghosts) to a
235
* given other process.
236
* \param [in] proca Mpi rank of the possible sending process.
237
* \param [in] procb Mpi rank of the possible receiver.
238
* \param [in] t8_offset_from The partition table of the current partition.
239
* \param [in] t8_offset_to The partition table of the next partition.
240
* \return nonzero if \a proca does send local trees to \a procb when
241
* we repartition from \a offset_from to \a offset_to.
242
* 0 else.
243
*/
244
int
245
t8_offset_sendsto (int proca, int procb, const t8_gloidx_t *t8_offset_from, const t8_gloidx_t *t8_offset_to);
246
247
/** Query whether in a repartitioning setting, a given process sends a given
248
* tree to a second process.
249
* \param [in] proc_send Mpi rank of the possible sending process.
250
* \param [in] proc_to Mpi rank of the possible receiver.
251
* \param [in] gtree A global tree id.
252
* \param [in] offset_from The partition table of the current partition.
253
* \param [in] offset_to The partition table of the next partition.
254
* \return nonzero if \a proc_send will send the tree \a gtree
255
* to \a proc_recv.
256
* 0 else.
257
* When calling, \a gtree must not be a local tree of \a proc_send in \a offset_from.
258
* In this case, 0 is always returned.
259
*/
260
int
261
t8_offset_sendstree (int proc_send, int proc_to, t8_gloidx_t gtree, const t8_gloidx_t *offset_from,
262
const t8_gloidx_t *offset_to);
263
264
/** Count the number of processes in a given range [a,b] that send to
265
* a given other process in a repartitioning setting.
266
* \param [in] start The first mpi rank to be considered as sender.
267
* \param [in] end The last mpi rank to be considered as sender.
268
* \param [in] mpirank The mpirank to be considered as receiver.
269
* \param [in] offset_from The partition table of the current partition.
270
* \param [in] offset_to The partition table of the next partition.
271
* \return The number of processes p, such that
272
* \a start <= p <= \a end and p does send local trees (and possibly ghosts)
273
* to \a mpirank.
274
*/
275
int
276
t8_offset_range_send (int start, int end, int mpirank, const t8_gloidx_t *offset_from, const t8_gloidx_t *offset_to);
277
278
/**
279
* Print the offsets of a partition.
280
*
281
* This function prints the offsets of a partition in a debug message.
282
*
283
* \param [in] offset The offsets to print.
284
* \param [in] comm The MPI communicator to use for printing.
285
*/
286
void
287
t8_offset_print (t8_shmem_array_t offset, sc_MPI_Comm comm);
288
289
T8_EXTERN_C_END ();
290
291
#endif /* !T8_CMESH_OFFSET_H */
292
293