34#include <p4est_config.h>
37 (defined (P4EST_ENABLE_MPI) && !defined (SC_ENABLE_MPI)) || \
38 (!defined (P4EST_ENABLE_MPI) && defined (SC_ENABLE_MPI))
39#error "MPI configured differently in p4est and libsc"
42 (defined (P4EST_ENABLE_MPIIO) && !defined (SC_ENABLE_MPIIO)) || \
43 (!defined (P4EST_ENABLE_MPIIO) && defined (SC_ENABLE_MPIIO))
44#error "MPI I/O configured differently in p4est and libsc"
48#include <sc_containers.h>
49#define _p4est_const _sc_const
56#define P4EST_COMM_TRANSFER_NULL
60#define P4EST_CONN_DISK_PERIODIC
63#define P4EST_CONN_REORDER_NEWID
71#define P4EST_SEARCH_LOCAL
74#define P4EST_VTK_CELL_DATAV
82#define p4est_qcoord_compare sc_int32_compare
83#define P4EST_QCOORD_BITS 32
84#define P4EST_MPI_QCOORD sc_MPI_INT
85#define P4EST_VTK_QCOORD "Int32"
86#define P4EST_F90_QCOORD INTEGER(KIND=C_INT32_T)
87#define P4EST_QCOORD_MIN INT32_MIN
88#define P4EST_QCOORD_MAX INT32_MAX
89#define P4EST_QCOORD_1 ((p4est_qcoord_t) 1)
90#define P4EST_QCOORD_ABS(x) ((p4est_qcoord_t) labs ((long) (x)))
94#define p4est_topidx_compare sc_int32_compare
95#define P4EST_TOPIDX_BITS 32
96#define P4EST_MPI_TOPIDX sc_MPI_INT
97#define P4EST_VTK_TOPIDX "Int32"
98#define P4EST_F90_TOPIDX INTEGER(KIND=C_INT32_T)
99#define P4EST_TOPIDX_MIN INT32_MIN
100#define P4EST_TOPIDX_MAX INT32_MAX
101#define P4EST_TOPIDX_FITS_32 1
102#define P4EST_TOPIDX_1 ((p4est_topidx_t) 1)
103#define P4EST_TOPIDX_ABS(x) ((p4est_topidx_t) labs ((long) (x)))
107#define p4est_locidx_compare sc_int32_compare
108#define P4EST_LOCIDX_BITS 32
109#define P4EST_MPI_LOCIDX sc_MPI_INT
110#define P4EST_VTK_LOCIDX "Int32"
111#define P4EST_F90_LOCIDX INTEGER(KIND=C_INT32_T)
112#define P4EST_LOCIDX_MIN INT32_MIN
113#define P4EST_LOCIDX_MAX INT32_MAX
114#define P4EST_LOCIDX_1 ((p4est_locidx_t) 1)
115#define P4EST_LOCIDX_ABS(x) ((p4est_locidx_t) labs ((long) (x)))
119#define p4est_gloidx_compare sc_int64_compare
120#define P4EST_GLOIDX_BITS 64
121#define P4EST_MPI_GLOIDX sc_MPI_LONG_LONG_INT
122#define P4EST_VTK_GLOIDX "Int64"
123#define P4EST_F90_GLOIDX INTEGER(KIND=C_INT64_T)
124#define P4EST_GLOIDX_MIN INT64_MIN
125#define P4EST_GLOIDX_MAX INT64_MAX
126#define P4EST_GLOIDX_1 ((p4est_gloidx_t) 1)
127#define P4EST_GLOIDX_ABS(x) ((p4est_gloidx_t) llabs ((long long) (x)))
132 P4EST_COMM_TAG_FIRST = SC_TAG_FIRST,
133 P4EST_COMM_COUNT_PERTREE = SC_TAG_LAST,
134 P4EST_COMM_BALANCE_FIRST_COUNT,
135 P4EST_COMM_BALANCE_FIRST_LOAD,
136 P4EST_COMM_BALANCE_SECOND_COUNT,
137 P4EST_COMM_BALANCE_SECOND_LOAD,
138 P4EST_COMM_PARTITION_GIVEN,
139 P4EST_COMM_PARTITION_WEIGHTED_LOW,
140 P4EST_COMM_PARTITION_WEIGHTED_HIGH,
141 P4EST_COMM_PARTITION_CORRECTION,
142 P4EST_COMM_GHOST_COUNT,
143 P4EST_COMM_GHOST_LOAD,
144 P4EST_COMM_GHOST_EXCHANGE,
145 P4EST_COMM_GHOST_EXPAND_COUNT,
146 P4EST_COMM_GHOST_EXPAND_LOAD,
147 P4EST_COMM_GHOST_SUPPORT_COUNT,
148 P4EST_COMM_GHOST_SUPPORT_LOAD,
149 P4EST_COMM_GHOST_CHECKSUM,
150 P4EST_COMM_NODES_QUERY,
151 P4EST_COMM_NODES_REPLY,
153 P4EST_COMM_LNODES_TEST,
154 P4EST_COMM_LNODES_PASS,
155 P4EST_COMM_LNODES_OWNED,
156 P4EST_COMM_LNODES_ALL,
157 P4EST_COMM_TNODES_QUERY,
158 P4EST_COMM_TNODES_REPLY,
164#ifdef P4EST_ENABLE_DEBUG
165#define P4EST_ASSERT(c) SC_CHECK_ABORT ((c), "Assertion '" #c "'")
166#define P4EST_EXECUTE_ASSERT_FALSE(expression) \
167 do { int _p4est_i = (int) (expression); \
168 SC_CHECK_ABORT (!_p4est_i, "Expected false: '" #expression "'"); \
170#define P4EST_EXECUTE_ASSERT_TRUE(expression) \
171 do { int _p4est_i = (int) (expression); \
172 SC_CHECK_ABORT (_p4est_i, "Expected true: '" #expression "'"); \
174#define P4EST_EXECUTE_ASSERT_INT(expression,ival) \
175 do { int _p4est_i = (int) (expression); \
176 SC_CHECK_ABORT ((ival) == _p4est_i, \
177 "Expected '" #ival "': '" #expression "'"); \
179#define P4EST_EXECUTE_ASSERT_TOPIDX(expression,tval) \
180 do { p4est_topidx_t _p4est_t = (p4est_topidx_t) (expression); \
181 SC_CHECK_ABORT ((tval) == _p4est_t, \
182 "Expected '" #tval "': '" #expression "'"); \
184#define P4EST_DEBUG_EXECUTE(expression) \
185 do { (void) (expression); } while (0)
187#define P4EST_ASSERT(c) SC_NOOP ()
188#define P4EST_EXECUTE_ASSERT_FALSE(expression) \
189 do { (void) (expression); } while (0)
190#define P4EST_EXECUTE_ASSERT_TRUE(expression) \
191 do { (void) (expression); } while (0)
192#define P4EST_EXECUTE_ASSERT_INT(expression,ival) \
193 do { (void) (expression); } while (0)
194#define P4EST_EXECUTE_ASSERT_TOPIDX(expression,tval) \
195 do { (void) (expression); } while (0)
196#define P4EST_DEBUG_EXECUTE(expression) SC_NOOP ()
201#define P4EST_ALLOC(t,n) (t *) sc_malloc (p4est_package_id, \
204#define P4EST_ALLOC_ZERO(t,n) (t *) sc_calloc (p4est_package_id, \
205 (size_t) (n), sizeof(t))
207#define P4EST_REALLOC(p,t,n) (t *) sc_realloc (p4est_package_id, \
208 (p), (n) * sizeof(t))
210#define P4EST_STRDUP(s) sc_strdup (p4est_package_id, (s))
212#define P4EST_FREE(p) sc_free (p4est_package_id, (p))
215#define P4EST_GLOBAL_LOG(p,s) \
216 SC_GEN_LOG (p4est_package_id, SC_LC_GLOBAL, (p), (s))
217#define P4EST_LOG(p,s) \
218 SC_GEN_LOG (p4est_package_id, SC_LC_NORMAL, (p), (s))
219void P4EST_GLOBAL_LOGF (
int priority,
const char *fmt, ...)
220 __attribute__ ((format (printf, 2, 3)));
221void P4EST_LOGF (
int priority, const
char *fmt, ...)
222 __attribute__ ((format (printf, 2, 3)));
224#define P4EST_GLOBAL_LOGF(p,f,...) \
225 SC_GEN_LOGF (p4est_package_id, SC_LC_GLOBAL, (p), (f), __VA_ARGS__)
226#define P4EST_LOGF(p,f,...) \
227 SC_GEN_LOGF (p4est_package_id, SC_LC_NORMAL, (p), (f), __VA_ARGS__)
231#define P4EST_GLOBAL_TRACE(s) P4EST_GLOBAL_LOG (SC_LP_TRACE, (s))
232#define P4EST_GLOBAL_LDEBUG(s) P4EST_GLOBAL_LOG (SC_LP_DEBUG, (s))
233#define P4EST_GLOBAL_VERBOSE(s) P4EST_GLOBAL_LOG (SC_LP_VERBOSE, (s))
234#define P4EST_GLOBAL_INFO(s) P4EST_GLOBAL_LOG (SC_LP_INFO, (s))
235#define P4EST_GLOBAL_STATISTICS(s) P4EST_GLOBAL_LOG (SC_LP_STATISTICS, (s))
236#define P4EST_GLOBAL_PRODUCTION(s) P4EST_GLOBAL_LOG (SC_LP_PRODUCTION, (s))
237#define P4EST_GLOBAL_ESSENTIAL(s) P4EST_GLOBAL_LOG (SC_LP_ESSENTIAL, (s))
238#define P4EST_GLOBAL_LERROR(s) P4EST_GLOBAL_LOG (SC_LP_ERROR, (s))
239void P4EST_GLOBAL_TRACEF (
const char *fmt, ...)
240 __attribute__ ((format (printf, 1, 2)));
241void P4EST_GLOBAL_LDEBUGF (const
char *fmt, ...)
242 __attribute__ ((format (printf, 1, 2)));
243void P4EST_GLOBAL_VERBOSEF (const
char *fmt, ...)
244 __attribute__ ((format (printf, 1, 2)));
245void P4EST_GLOBAL_INFOF (const
char *fmt, ...)
246 __attribute__ ((format (printf, 1, 2)));
247void P4EST_GLOBAL_STATISTICSF (const
char *fmt, ...)
248 __attribute__ ((format (printf, 1, 2)));
249void P4EST_GLOBAL_PRODUCTIONF (const
char *fmt, ...)
250 __attribute__ ((format (printf, 1, 2)));
251void P4EST_GLOBAL_ESSENTIALF (const
char *fmt, ...)
252 __attribute__ ((format (printf, 1, 2)));
253void P4EST_GLOBAL_LERRORF (const
char *fmt, ...)
254 __attribute__ ((format (printf, 1, 2)));
256#define P4EST_GLOBAL_TRACEF(f,...) \
257 P4EST_GLOBAL_LOGF (SC_LP_TRACE, (f), __VA_ARGS__)
258#define P4EST_GLOBAL_LDEBUGF(f,...) \
259 P4EST_GLOBAL_LOGF (SC_LP_DEBUG, (f), __VA_ARGS__)
260#define P4EST_GLOBAL_VERBOSEF(f,...) \
261 P4EST_GLOBAL_LOGF (SC_LP_VERBOSE, (f), __VA_ARGS__)
262#define P4EST_GLOBAL_INFOF(f,...) \
263 P4EST_GLOBAL_LOGF (SC_LP_INFO, (f), __VA_ARGS__)
264#define P4EST_GLOBAL_STATISTICSF(f,...) \
265 P4EST_GLOBAL_LOGF (SC_LP_STATISTICS, (f), __VA_ARGS__)
266#define P4EST_GLOBAL_PRODUCTIONF(f,...) \
267 P4EST_GLOBAL_LOGF (SC_LP_PRODUCTION, (f), __VA_ARGS__)
268#define P4EST_GLOBAL_ESSENTIALF(f,...) \
269 P4EST_GLOBAL_LOGF (SC_LP_ESSENTIAL, (f), __VA_ARGS__)
270#define P4EST_GLOBAL_LERRORF(f,...) \
271 P4EST_GLOBAL_LOGF (SC_LP_ERROR, (f), __VA_ARGS__)
273#define P4EST_GLOBAL_NOTICE P4EST_GLOBAL_STATISTICS
274#define P4EST_GLOBAL_NOTICEF P4EST_GLOBAL_STATISTICSF
277#define P4EST_TRACE(s) P4EST_LOG (SC_LP_TRACE, (s))
278#define P4EST_LDEBUG(s) P4EST_LOG (SC_LP_DEBUG, (s))
279#define P4EST_VERBOSE(s) P4EST_LOG (SC_LP_VERBOSE, (s))
280#define P4EST_INFO(s) P4EST_LOG (SC_LP_INFO, (s))
281#define P4EST_STATISTICS(s) P4EST_LOG (SC_LP_STATISTICS, (s))
282#define P4EST_PRODUCTION(s) P4EST_LOG (SC_LP_PRODUCTION, (s))
283#define P4EST_ESSENTIAL(s) P4EST_LOG (SC_LP_ESSENTIAL, (s))
284#define P4EST_LERROR(s) P4EST_LOG (SC_LP_ERROR, (s))
285void P4EST_TRACEF (
const char *fmt, ...)
286 __attribute__ ((format (printf, 1, 2)));
287void P4EST_LDEBUGF (const
char *fmt, ...)
288 __attribute__ ((format (printf, 1, 2)));
289void P4EST_VERBOSEF (const
char *fmt, ...)
290 __attribute__ ((format (printf, 1, 2)));
291void P4EST_INFOF (const
char *fmt, ...)
292 __attribute__ ((format (printf, 1, 2)));
293void P4EST_STATISTICSF (const
char *fmt, ...)
294 __attribute__ ((format (printf, 1, 2)));
295void P4EST_PRODUCTIONF (const
char *fmt, ...)
296 __attribute__ ((format (printf, 1, 2)));
297void P4EST_ESSENTIALF (const
char *fmt, ...)
298 __attribute__ ((format (printf, 1, 2)));
299void P4EST_LERRORF (const
char *fmt, ...)
300 __attribute__ ((format (printf, 1, 2)));
302#define P4EST_TRACEF(f,...) \
303 P4EST_LOGF (SC_LP_TRACE, (f), __VA_ARGS__)
304#define P4EST_LDEBUGF(f,...) \
305 P4EST_LOGF (SC_LP_DEBUG, (f), __VA_ARGS__)
306#define P4EST_VERBOSEF(f,...) \
307 P4EST_LOGF (SC_LP_VERBOSE, (f), __VA_ARGS__)
308#define P4EST_INFOF(f,...) \
309 P4EST_LOGF (SC_LP_INFO, (f), __VA_ARGS__)
310#define P4EST_STATISTICSF(f,...) \
311 P4EST_LOGF (SC_LP_STATISTICS, (f), __VA_ARGS__)
312#define P4EST_PRODUCTIONF(f,...) \
313 P4EST_LOGF (SC_LP_PRODUCTION, (f), __VA_ARGS__)
314#define P4EST_ESSENTIALF(f,...) \
315 P4EST_LOGF (SC_LP_ESSENTIAL, (f), __VA_ARGS__)
316#define P4EST_LERRORF(f,...) \
317 P4EST_LOGF (SC_LP_ERROR, (f), __VA_ARGS__)
319#define P4EST_NOTICE P4EST_STATISTICS
320#define P4EST_NOTICEF P4EST_STATISTICSF
389#if (P4EST_TOPIDX_FITS_32)
390 a = (uint32_t) tt[0];
391 b = (uint32_t) tt[1];
394 a = (uint32_t) (tt[0] && 0xFFFFFFFF);
395 b = (uint32_t) (tt[0] >> 32);
396 c = (uint32_t) (tt[1] && 0xFFFFFFFF);
397 sc_hash_mix (a, b, c);
398 a += (uint32_t) (tt[1] >> 32);
400 sc_hash_final (a, b, c);
414#if (P4EST_TOPIDX_FITS_32)
415 a = (uint32_t) tt[0];
416 b = (uint32_t) tt[1];
417 c = (uint32_t) tt[2];
419 a = (uint32_t) (tt[0] && 0xFFFFFFFF);
420 b = (uint32_t) (tt[0] >> 32);
421 c = (uint32_t) (tt[1] && 0xFFFFFFFF);
422 sc_hash_mix (a, b, c);
423 a += (uint32_t) (tt[1] >> 32);
424 b += (uint32_t) (tt[2] && 0xFFFFFFFF);
425 c += (uint32_t) (tt[2] >> 32);
427 sc_hash_final (a, b, c);
441#if (P4EST_TOPIDX_FITS_32)
442 a = (uint32_t) tt[0];
443 b = (uint32_t) tt[1];
444 c = (uint32_t) tt[2];
445 sc_hash_mix (a, b, c);
446 a += (uint32_t) tt[3];
448 a = (uint32_t) (tt[0] && 0xFFFFFFFF);
449 b = (uint32_t) (tt[0] >> 32);
450 c = (uint32_t) (tt[1] && 0xFFFFFFFF);
451 sc_hash_mix (a, b, c);
452 a += (uint32_t) (tt[1] >> 32);
453 b += (uint32_t) (tt[2] && 0xFFFFFFFF);
454 c += (uint32_t) (tt[2] >> 32);
455 sc_hash_mix (a, b, c);
456 a += (uint32_t) (tt[3] && 0xFFFFFFFF);
457 b += (uint32_t) (tt[3] >> 32);
459 sc_hash_final (a, b, c);
473 for (i = 1; i < length; ++i) {
474 if (t[i - 1] > t[i]) {
491 for (i = length - 1; i > 0; --i) {
493 for (j = 0; j < i; ++j) {
494 if (t[j] > t[j + 1]) {
511 (
int global_num,
int p,
int num_procs);
533 P4EST_ASSERT (0 <= p && p <= num_procs);
535 if (p == num_procs) {
541 (((
long double) global_num * (
double) p) / (double) num_procs);
543 P4EST_ASSERT (result <= global_num);
569 P4EST_ASSERT (global_num >= 0);
570 P4EST_ASSERT (0 <= p && p <= num_procs);
572 if (p == num_procs) {
578 (((
long double) global_num * (
double) p) / (double) num_procs);
580 P4EST_ASSERT (0 <= result && result <= global_num);
int32_t p4est_qcoord_t
Typedef for quadrant coordinates.
Definition p4est_base.h:81
unsigned p4est_topidx_hash3(const p4est_topidx_t *tt)
Compute hash value for three p4est_topidx_t integers.
Definition p4est_base.h:410
enum p4est_comm_tag p4est_comm_tag_t
Tags for MPI messages.
int p4est_topidx_is_sorted(p4est_topidx_t *t, int length)
Check if an array of p4est_topidx_t is sorted from lowest to highest.
Definition p4est_base.h:469
SC_DLL_PUBLIC int p4est_package_id
The package id for p4est within libsc.
void p4est_topidx_bsort(p4est_topidx_t *t, int length)
Sort an array of p4est_topidx_t from lowest to highest using bubble sort.
Definition p4est_base.h:485
int p4est_partition_cut_int(int global_num, int p, int num_procs)
Compute an offset partitioning a range of integers.
unsigned p4est_topidx_hash2(const p4est_topidx_t *tt)
Compute hash value for two p4est_topidx_t integers.
Definition p4est_base.h:385
int p4est_version_major(void)
Return the major version of p4est.
int p4est_have_zlib(void)
Check for a sufficiently recent zlib installation.
void p4est_log_indent_push(void)
Add one space to the start of p4est's default log format.
Definition p4est_base.h:332
int32_t p4est_topidx_t
Typedef for counting topological entities (trees, tree vertices).
Definition p4est_base.h:93
int p4est_get_package_id(void)
Query the package identity as registered in libsc.
const char * p4est_version(void)
Return the full version of p4est.
uint64_t p4est_partition_cut_uint64(uint64_t global_num, int p, int num_procs)
For a uint64_t global number of elements return the offset of rank p in their uniform partition.
Definition p4est_base.h:523
p4est_comm_tag
Tags for MPI messages.
Definition p4est_base.h:131
int32_t p4est_locidx_t
Typedef for processor-local indexing of quadrants and nodes.
Definition p4est_base.h:106
void p4est_init(sc_log_handler_t log_handler, int log_threshold)
Registers p4est with the SC Library and sets the logging behavior.
int p4est_version_minor(void)
Return the minor version of p4est.
unsigned p4est_topidx_hash4(const p4est_topidx_t *tt)
Compute hash value for four p4est_topidx_t integers.
Definition p4est_base.h:437
void p4est_log_indent_pop(void)
Remove one space from the start of p4est's default log format.
Definition p4est_base.h:339
p4est_gloidx_t p4est_partition_cut_gloidx(p4est_gloidx_t global_num, int p, int num_procs)
For a p4est_gloidxs_t global number of elements return the offset of rank p in their uniform partitio...
Definition p4est_base.h:559
int64_t p4est_gloidx_t
Typedef for globally unique indexing of quadrants.
Definition p4est_base.h:118
int p4est_is_initialized(void)
Return whether p4est has been initialized or not.