34 #include <p4est_config.h>
35 #include <sc_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,
162 #ifdef P4EST_ENABLE_DEBUG
163 #define P4EST_ASSERT(c) SC_CHECK_ABORT ((c), "Assertion '" #c "'")
164 #define P4EST_EXECUTE_ASSERT_FALSE(expression) \
165 do { int _p4est_i = (int) (expression); \
166 SC_CHECK_ABORT (!_p4est_i, "Expected false: '" #expression "'"); \
168 #define P4EST_EXECUTE_ASSERT_TRUE(expression) \
169 do { int _p4est_i = (int) (expression); \
170 SC_CHECK_ABORT (_p4est_i, "Expected true: '" #expression "'"); \
172 #define P4EST_EXECUTE_ASSERT_INT(expression,ival) \
173 do { int _p4est_i = (int) (expression); \
174 SC_CHECK_ABORT ((ival) == _p4est_i, \
175 "Expected '" #ival "': '" #expression "'"); \
177 #define P4EST_EXECUTE_ASSERT_TOPIDX(expression,tval) \
178 do { p4est_topidx_t _p4est_t = (p4est_topidx_t) (expression); \
179 SC_CHECK_ABORT ((tval) == _p4est_t, \
180 "Expected '" #tval "': '" #expression "'"); \
182 #define P4EST_DEBUG_EXECUTE(expression) \
183 do { (void) (expression); } while (0)
185 #define P4EST_ASSERT(c) SC_NOOP ()
186 #define P4EST_EXECUTE_ASSERT_FALSE(expression) \
187 do { (void) (expression); } while (0)
188 #define P4EST_EXECUTE_ASSERT_TRUE(expression) \
189 do { (void) (expression); } while (0)
190 #define P4EST_EXECUTE_ASSERT_INT(expression,ival) \
191 do { (void) (expression); } while (0)
192 #define P4EST_EXECUTE_ASSERT_TOPIDX(expression,tval) \
193 do { (void) (expression); } while (0)
194 #define P4EST_DEBUG_EXECUTE(expression) SC_NOOP ()
199 #define P4EST_ALLOC(t,n) (t *) sc_malloc (p4est_package_id, \
202 #define P4EST_ALLOC_ZERO(t,n) (t *) sc_calloc (p4est_package_id, \
203 (size_t) (n), sizeof(t))
205 #define P4EST_REALLOC(p,t,n) (t *) sc_realloc (p4est_package_id, \
206 (p), (n) * sizeof(t))
208 #define P4EST_STRDUP(s) sc_strdup (p4est_package_id, (s))
210 #define P4EST_FREE(p) sc_free (p4est_package_id, (p))
213 #define P4EST_GLOBAL_LOG(p,s) \
214 SC_GEN_LOG (p4est_package_id, SC_LC_GLOBAL, (p), (s))
215 #define P4EST_LOG(p,s) \
216 SC_GEN_LOG (p4est_package_id, SC_LC_NORMAL, (p), (s))
217 void P4EST_GLOBAL_LOGF (
int priority,
const char *fmt, ...)
218 __attribute__ ((format (printf, 2, 3)));
219 void P4EST_LOGF (
int priority, const
char *fmt, ...)
220 __attribute__ ((format (printf, 2, 3)));
222 #define P4EST_GLOBAL_LOGF(p,f,...) \
223 SC_GEN_LOGF (p4est_package_id, SC_LC_GLOBAL, (p), (f), __VA_ARGS__)
224 #define P4EST_LOGF(p,f,...) \
225 SC_GEN_LOGF (p4est_package_id, SC_LC_NORMAL, (p), (f), __VA_ARGS__)
229 #define P4EST_GLOBAL_TRACE(s) P4EST_GLOBAL_LOG (SC_LP_TRACE, (s))
230 #define P4EST_GLOBAL_LDEBUG(s) P4EST_GLOBAL_LOG (SC_LP_DEBUG, (s))
231 #define P4EST_GLOBAL_VERBOSE(s) P4EST_GLOBAL_LOG (SC_LP_VERBOSE, (s))
232 #define P4EST_GLOBAL_INFO(s) P4EST_GLOBAL_LOG (SC_LP_INFO, (s))
233 #define P4EST_GLOBAL_STATISTICS(s) P4EST_GLOBAL_LOG (SC_LP_STATISTICS, (s))
234 #define P4EST_GLOBAL_PRODUCTION(s) P4EST_GLOBAL_LOG (SC_LP_PRODUCTION, (s))
235 #define P4EST_GLOBAL_ESSENTIAL(s) P4EST_GLOBAL_LOG (SC_LP_ESSENTIAL, (s))
236 #define P4EST_GLOBAL_LERROR(s) P4EST_GLOBAL_LOG (SC_LP_ERROR, (s))
237 void P4EST_GLOBAL_TRACEF (
const char *fmt, ...)
238 __attribute__ ((format (printf, 1, 2)));
239 void P4EST_GLOBAL_LDEBUGF (const
char *fmt, ...)
240 __attribute__ ((format (printf, 1, 2)));
241 void P4EST_GLOBAL_VERBOSEF (const
char *fmt, ...)
242 __attribute__ ((format (printf, 1, 2)));
243 void P4EST_GLOBAL_INFOF (const
char *fmt, ...)
244 __attribute__ ((format (printf, 1, 2)));
245 void P4EST_GLOBAL_STATISTICSF (const
char *fmt, ...)
246 __attribute__ ((format (printf, 1, 2)));
247 void P4EST_GLOBAL_PRODUCTIONF (const
char *fmt, ...)
248 __attribute__ ((format (printf, 1, 2)));
249 void P4EST_GLOBAL_ESSENTIALF (const
char *fmt, ...)
250 __attribute__ ((format (printf, 1, 2)));
251 void P4EST_GLOBAL_LERRORF (const
char *fmt, ...)
252 __attribute__ ((format (printf, 1, 2)));
254 #define P4EST_GLOBAL_TRACEF(f,...) \
255 P4EST_GLOBAL_LOGF (SC_LP_TRACE, (f), __VA_ARGS__)
256 #define P4EST_GLOBAL_LDEBUGF(f,...) \
257 P4EST_GLOBAL_LOGF (SC_LP_DEBUG, (f), __VA_ARGS__)
258 #define P4EST_GLOBAL_VERBOSEF(f,...) \
259 P4EST_GLOBAL_LOGF (SC_LP_VERBOSE, (f), __VA_ARGS__)
260 #define P4EST_GLOBAL_INFOF(f,...) \
261 P4EST_GLOBAL_LOGF (SC_LP_INFO, (f), __VA_ARGS__)
262 #define P4EST_GLOBAL_STATISTICSF(f,...) \
263 P4EST_GLOBAL_LOGF (SC_LP_STATISTICS, (f), __VA_ARGS__)
264 #define P4EST_GLOBAL_PRODUCTIONF(f,...) \
265 P4EST_GLOBAL_LOGF (SC_LP_PRODUCTION, (f), __VA_ARGS__)
266 #define P4EST_GLOBAL_ESSENTIALF(f,...) \
267 P4EST_GLOBAL_LOGF (SC_LP_ESSENTIAL, (f), __VA_ARGS__)
268 #define P4EST_GLOBAL_LERRORF(f,...) \
269 P4EST_GLOBAL_LOGF (SC_LP_ERROR, (f), __VA_ARGS__)
271 #define P4EST_GLOBAL_NOTICE P4EST_GLOBAL_STATISTICS
272 #define P4EST_GLOBAL_NOTICEF P4EST_GLOBAL_STATISTICSF
275 #define P4EST_TRACE(s) P4EST_LOG (SC_LP_TRACE, (s))
276 #define P4EST_LDEBUG(s) P4EST_LOG (SC_LP_DEBUG, (s))
277 #define P4EST_VERBOSE(s) P4EST_LOG (SC_LP_VERBOSE, (s))
278 #define P4EST_INFO(s) P4EST_LOG (SC_LP_INFO, (s))
279 #define P4EST_STATISTICS(s) P4EST_LOG (SC_LP_STATISTICS, (s))
280 #define P4EST_PRODUCTION(s) P4EST_LOG (SC_LP_PRODUCTION, (s))
281 #define P4EST_ESSENTIAL(s) P4EST_LOG (SC_LP_ESSENTIAL, (s))
282 #define P4EST_LERROR(s) P4EST_LOG (SC_LP_ERROR, (s))
283 void P4EST_TRACEF (
const char *fmt, ...)
284 __attribute__ ((format (printf, 1, 2)));
285 void P4EST_LDEBUGF (const
char *fmt, ...)
286 __attribute__ ((format (printf, 1, 2)));
287 void P4EST_VERBOSEF (const
char *fmt, ...)
288 __attribute__ ((format (printf, 1, 2)));
289 void P4EST_INFOF (const
char *fmt, ...)
290 __attribute__ ((format (printf, 1, 2)));
291 void P4EST_STATISTICSF (const
char *fmt, ...)
292 __attribute__ ((format (printf, 1, 2)));
293 void P4EST_PRODUCTIONF (const
char *fmt, ...)
294 __attribute__ ((format (printf, 1, 2)));
295 void P4EST_ESSENTIALF (const
char *fmt, ...)
296 __attribute__ ((format (printf, 1, 2)));
297 void P4EST_LERRORF (const
char *fmt, ...)
298 __attribute__ ((format (printf, 1, 2)));
300 #define P4EST_TRACEF(f,...) \
301 P4EST_LOGF (SC_LP_TRACE, (f), __VA_ARGS__)
302 #define P4EST_LDEBUGF(f,...) \
303 P4EST_LOGF (SC_LP_DEBUG, (f), __VA_ARGS__)
304 #define P4EST_VERBOSEF(f,...) \
305 P4EST_LOGF (SC_LP_VERBOSE, (f), __VA_ARGS__)
306 #define P4EST_INFOF(f,...) \
307 P4EST_LOGF (SC_LP_INFO, (f), __VA_ARGS__)
308 #define P4EST_STATISTICSF(f,...) \
309 P4EST_LOGF (SC_LP_STATISTICS, (f), __VA_ARGS__)
310 #define P4EST_PRODUCTIONF(f,...) \
311 P4EST_LOGF (SC_LP_PRODUCTION, (f), __VA_ARGS__)
312 #define P4EST_ESSENTIALF(f,...) \
313 P4EST_LOGF (SC_LP_ESSENTIAL, (f), __VA_ARGS__)
314 #define P4EST_LERRORF(f,...) \
315 P4EST_LOGF (SC_LP_ERROR, (f), __VA_ARGS__)
317 #define P4EST_NOTICE P4EST_STATISTICS
318 #define P4EST_NOTICEF P4EST_STATISTICSF
329 p4est_log_indent_push (
void)
335 p4est_log_indent_pop (
void)
381 static inline unsigned
386 #if (P4EST_TOPIDX_FITS_32)
387 a = (uint32_t) tt[0];
388 b = (uint32_t) tt[1];
391 a = (uint32_t) (tt[0] && 0xFFFFFFFF);
392 b = (uint32_t) (tt[0] >> 32);
393 c = (uint32_t) (tt[1] && 0xFFFFFFFF);
394 sc_hash_mix (a, b, c);
395 a += (uint32_t) (tt[1] >> 32);
397 sc_hash_final (a, b, c);
407 static inline unsigned
412 #if (P4EST_TOPIDX_FITS_32)
413 a = (uint32_t) tt[0];
414 b = (uint32_t) tt[1];
415 c = (uint32_t) tt[2];
417 a = (uint32_t) (tt[0] && 0xFFFFFFFF);
418 b = (uint32_t) (tt[0] >> 32);
419 c = (uint32_t) (tt[1] && 0xFFFFFFFF);
420 sc_hash_mix (a, b, c);
421 a += (uint32_t) (tt[1] >> 32);
422 b += (uint32_t) (tt[2] && 0xFFFFFFFF);
423 c += (uint32_t) (tt[2] >> 32);
425 sc_hash_final (a, b, c);
435 static inline unsigned
440 #if (P4EST_TOPIDX_FITS_32)
441 a = (uint32_t) tt[0];
442 b = (uint32_t) tt[1];
443 c = (uint32_t) tt[2];
444 sc_hash_mix (a, b, c);
445 a += (uint32_t) tt[3];
447 a = (uint32_t) (tt[0] && 0xFFFFFFFF);
448 b = (uint32_t) (tt[0] >> 32);
449 c = (uint32_t) (tt[1] && 0xFFFFFFFF);
450 sc_hash_mix (a, b, c);
451 a += (uint32_t) (tt[1] >> 32);
452 b += (uint32_t) (tt[2] && 0xFFFFFFFF);
453 c += (uint32_t) (tt[2] >> 32);
454 sc_hash_mix (a, b, c);
455 a += (uint32_t) (tt[3] && 0xFFFFFFFF);
456 b += (uint32_t) (tt[3] >> 32);
458 sc_hash_final (a, b, c);
469 for (i = 1; i < length; ++i) {
470 if (t[i - 1] > t[i]) {
485 for (i = length - 1; i > 0; --i) {
487 for (j = 0; j < i; ++j) {
488 if (t[j] > t[j + 1]) {
495 P4EST_ASSERT (p4est_topidx_is_sorted (t, length));
499 static inline uint64_t
500 p4est_partition_cut_uint64 (uint64_t global_num,
int p,
int num_procs)
510 P4EST_ASSERT (0 <= p && p <= num_procs);
512 if (p == num_procs) {
518 (((
long double) global_num * (
double) p) / (double) num_procs);
520 P4EST_ASSERT (result <= global_num);
527 p4est_partition_cut_gloidx (
p4est_gloidx_t global_num,
int p,
int num_procs)
537 P4EST_ASSERT (global_num >= 0);
538 P4EST_ASSERT (0 <= p && p <= num_procs);
540 if (p == num_procs) {
546 (((
long double) global_num * (
double) p) / (double) num_procs);
548 P4EST_ASSERT (0 <= result && result <= global_num);
int32_t p4est_qcoord_t
Typedef for quadrant coordinates.
Definition: p4est_base.h:81
enum p4est_comm_tag p4est_comm_tag_t
Tags for MPI messages.
SC_DLL_PUBLIC int p4est_package_id
The package id for p4est within libsc.
int p4est_version_major(void)
Return the major version of p4est.
int p4est_have_zlib(void)
Check for a sufficiently recent zlib installation.
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.
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.
int64_t p4est_gloidx_t
Typedef for globally unique indexing of quadrants.
Definition: p4est_base.h:118
const char * p4est_version(void)
Return the full version of p4est.
int p4est_is_initialized(void)
Return whether p4est has been initialized or not.