/usr/include/p4est_base.h is in libp4est-dev 1.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | /*
This file is part of p4est.
p4est is a C library to manage a collection (a forest) of multiple
connected adaptive quadtrees or octrees in parallel.
Copyright (C) 2010 The University of Texas System
Written by Carsten Burstedde, Lucas C. Wilcox, and Tobin Isaac
p4est is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
p4est is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with p4est; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file p4est_base.h
*
* General support types and functions
*/
#ifndef P4EST_BASE_H
#define P4EST_BASE_H
/* include config headers */
#include <p4est_config.h>
#include <sc_config.h>
#if \
(defined (P4EST_ENABLE_MPI) && !defined (SC_ENABLE_MPI)) || \
(!defined (P4EST_ENABLE_MPI) && defined (SC_ENABLE_MPI))
#error "MPI configured differently in p4est and libsc"
#endif
#if \
(defined (P4EST_ENABLE_MPIIO) && !defined (SC_ENABLE_MPIIO)) || \
(!defined (P4EST_ENABLE_MPIIO) && defined (SC_ENABLE_MPIIO))
#error "MPI I/O configured differently in p4est and libsc"
#endif
/* indirectly also include sc.h */
#include <sc_containers.h>
#define _p4est_const _sc_const
SC_EXTERN_C_BEGIN;
/** Typedef for quadrant coordinates. */
typedef int32_t p4est_qcoord_t;
#define p4est_qcoord_compare sc_int32_compare
#define P4EST_MPI_QCOORD sc_MPI_INT
#define P4EST_VTK_QCOORD "Int32"
#define P4EST_F90_QCOORD INTEGER(KIND=C_INT32_T)
#define P4EST_QCOORD_MIN INT32_MIN
#define P4EST_QCOORD_MAX INT32_MAX
#define P4EST_QCOORD_1 ((p4est_qcoord_t) 1)
/** Typedef for counting topological entities (trees, tree vertices). */
typedef int32_t p4est_topidx_t;
#define p4est_topidx_compare sc_int32_compare
#define P4EST_MPI_TOPIDX sc_MPI_INT
#define P4EST_VTK_TOPIDX "Int32"
#define P4EST_F90_TOPIDX INTEGER(KIND=C_INT32_T)
#define P4EST_TOPIDX_MIN INT32_MIN
#define P4EST_TOPIDX_MAX INT32_MAX
#define P4EST_TOPIDX_FITS_32 1
#define P4EST_TOPIDX_1 ((p4est_topidx_t) 1)
/** Typedef for processor-local indexing of quadrants and nodes. */
typedef int32_t p4est_locidx_t;
#define p4est_locidx_compare sc_int32_compare
#define P4EST_MPI_LOCIDX sc_MPI_INT
#define P4EST_VTK_LOCIDX "Int32"
#define P4EST_F90_LOCIDX INTEGER(KIND=C_INT32_T)
#define P4EST_LOCIDX_MIN INT32_MIN
#define P4EST_LOCIDX_MAX INT32_MAX
#define P4EST_LOCIDX_1 ((p4est_locidx_t) 1)
/** Typedef for globally unique indexing of quadrants. */
typedef int64_t p4est_gloidx_t;
#define p4est_gloidx_compare sc_int64_compare
#define P4EST_MPI_GLOIDX sc_MPI_LONG_LONG_INT
#define P4EST_VTK_GLOIDX "Int64"
#define P4EST_F90_GLOIDX INTEGER(KIND=C_INT64_T)
#define P4EST_GLOIDX_MIN INT64_MIN
#define P4EST_GLOIDX_MAX INT64_MAX
#define P4EST_GLOIDX_1 ((p4est_gloidx_t) 1)
/* some error checking possibly specific to p4est */
#ifdef P4EST_ENABLE_DEBUG
#define P4EST_ASSERT(c) SC_CHECK_ABORT ((c), "Assertion '" #c "'")
#define P4EST_EXECUTE_ASSERT_FALSE(expression) \
do { int _p4est_i = (int) (expression); \
SC_CHECK_ABORT (!_p4est_i, "Expected false: '" #expression "'"); \
} while (0)
#define P4EST_EXECUTE_ASSERT_TRUE(expression) \
do { int _p4est_i = (int) (expression); \
SC_CHECK_ABORT (_p4est_i, "Expected true: '" #expression "'"); \
} while (0)
#else
#define P4EST_ASSERT(c) SC_NOOP ()
#define P4EST_EXECUTE_ASSERT_FALSE(expression) \
do { (void) (expression); } while (0)
#define P4EST_EXECUTE_ASSERT_TRUE(expression) \
do { (void) (expression); } while (0)
#endif
/* macros for memory allocation, will abort if out of memory */
/** allocate a \a t-array with \a n elements */
#define P4EST_ALLOC(t,n) (t *) sc_malloc (p4est_package_id, \
(n) * sizeof(t))
/** allocate a \a t-array with \a n elements and zero */
#define P4EST_ALLOC_ZERO(t,n) (t *) sc_calloc (p4est_package_id, \
(size_t) (n), sizeof(t))
/** reallocate the \a t-array \a p with \a n elements */
#define P4EST_REALLOC(p,t,n) (t *) sc_realloc (p4est_package_id, \
(p), (n) * sizeof(t))
/** duplicate a string */
#define P4EST_STRDUP(s) sc_strdup (p4est_package_id, (s))
/** free an allocated array */
#define P4EST_FREE(p) sc_free (p4est_package_id, (p))
/* log helper macros */
#define P4EST_GLOBAL_LOG(p,s) \
SC_GEN_LOG (p4est_package_id, SC_LC_GLOBAL, (p), (s))
#define P4EST_LOG(p,s) \
SC_GEN_LOG (p4est_package_id, SC_LC_NORMAL, (p), (s))
void P4EST_GLOBAL_LOGF (int priority, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
void P4EST_LOGF (int priority, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
#ifndef __cplusplus
#define P4EST_GLOBAL_LOGF(p,f,...) \
SC_GEN_LOGF (p4est_package_id, SC_LC_GLOBAL, (p), (f), __VA_ARGS__)
#define P4EST_LOGF(p,f,...) \
SC_GEN_LOGF (p4est_package_id, SC_LC_NORMAL, (p), (f), __VA_ARGS__)
#endif
/* convenience global log macros will only print if identifier <= 0 */
#define P4EST_GLOBAL_TRACE(s) P4EST_GLOBAL_LOG (SC_LP_TRACE, (s))
#define P4EST_GLOBAL_LDEBUG(s) P4EST_GLOBAL_LOG (SC_LP_DEBUG, (s))
#define P4EST_GLOBAL_VERBOSE(s) P4EST_GLOBAL_LOG (SC_LP_VERBOSE, (s))
#define P4EST_GLOBAL_INFO(s) P4EST_GLOBAL_LOG (SC_LP_INFO, (s))
#define P4EST_GLOBAL_STATISTICS(s) P4EST_GLOBAL_LOG (SC_LP_STATISTICS, (s))
#define P4EST_GLOBAL_PRODUCTION(s) P4EST_GLOBAL_LOG (SC_LP_PRODUCTION, (s))
#define P4EST_GLOBAL_ESSENTIAL(s) P4EST_GLOBAL_LOG (SC_LP_ESSENTIAL, (s))
#define P4EST_GLOBAL_LERROR(s) P4EST_GLOBAL_LOG (SC_LP_ERROR, (s))
void P4EST_GLOBAL_TRACEF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_GLOBAL_LDEBUGF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_GLOBAL_VERBOSEF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_GLOBAL_INFOF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_GLOBAL_STATISTICSF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_GLOBAL_PRODUCTIONF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_GLOBAL_ESSENTIALF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_GLOBAL_LERRORF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
#ifndef __cplusplus
#define P4EST_GLOBAL_TRACEF(f,...) \
P4EST_GLOBAL_LOGF (SC_LP_TRACE, (f), __VA_ARGS__)
#define P4EST_GLOBAL_LDEBUGF(f,...) \
P4EST_GLOBAL_LOGF (SC_LP_DEBUG, (f), __VA_ARGS__)
#define P4EST_GLOBAL_VERBOSEF(f,...) \
P4EST_GLOBAL_LOGF (SC_LP_VERBOSE, (f), __VA_ARGS__)
#define P4EST_GLOBAL_INFOF(f,...) \
P4EST_GLOBAL_LOGF (SC_LP_INFO, (f), __VA_ARGS__)
#define P4EST_GLOBAL_STATISTICSF(f,...) \
P4EST_GLOBAL_LOGF (SC_LP_STATISTICS, (f), __VA_ARGS__)
#define P4EST_GLOBAL_PRODUCTIONF(f,...) \
P4EST_GLOBAL_LOGF (SC_LP_PRODUCTION, (f), __VA_ARGS__)
#define P4EST_GLOBAL_ESSENTIALF(f,...) \
P4EST_GLOBAL_LOGF (SC_LP_ESSENTIAL, (f), __VA_ARGS__)
#define P4EST_GLOBAL_LERRORF(f,...) \
P4EST_GLOBAL_LOGF (SC_LP_ERROR, (f), __VA_ARGS__)
#endif
#define P4EST_GLOBAL_NOTICE P4EST_GLOBAL_STATISTICS
#define P4EST_GLOBAL_NOTICEF P4EST_GLOBAL_STATISTICSF
/* convenience log macros that are active on every processor */
#define P4EST_TRACE(s) P4EST_LOG (SC_LP_TRACE, (s))
#define P4EST_LDEBUG(s) P4EST_LOG (SC_LP_DEBUG, (s))
#define P4EST_VERBOSE(s) P4EST_LOG (SC_LP_VERBOSE, (s))
#define P4EST_INFO(s) P4EST_LOG (SC_LP_INFO, (s))
#define P4EST_STATISTICS(s) P4EST_LOG (SC_LP_STATISTICS, (s))
#define P4EST_PRODUCTION(s) P4EST_LOG (SC_LP_PRODUCTION, (s))
#define P4EST_ESSENTIAL(s) P4EST_LOG (SC_LP_ESSENTIAL, (s))
#define P4EST_LERROR(s) P4EST_LOG (SC_LP_ERROR, (s))
void P4EST_TRACEF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_LDEBUGF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_VERBOSEF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_INFOF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_STATISTICSF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_PRODUCTIONF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_ESSENTIALF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void P4EST_LERRORF (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
#ifndef __cplusplus
#define P4EST_TRACEF(f,...) \
P4EST_LOGF (SC_LP_TRACE, (f), __VA_ARGS__)
#define P4EST_LDEBUGF(f,...) \
P4EST_LOGF (SC_LP_DEBUG, (f), __VA_ARGS__)
#define P4EST_VERBOSEF(f,...) \
P4EST_LOGF (SC_LP_VERBOSE, (f), __VA_ARGS__)
#define P4EST_INFOF(f,...) \
P4EST_LOGF (SC_LP_INFO, (f), __VA_ARGS__)
#define P4EST_STATISTICSF(f,...) \
P4EST_LOGF (SC_LP_STATISTICS, (f), __VA_ARGS__)
#define P4EST_PRODUCTIONF(f,...) \
P4EST_LOGF (SC_LP_PRODUCTION, (f), __VA_ARGS__)
#define P4EST_ESSENTIALF(f,...) \
P4EST_LOGF (SC_LP_ESSENTIAL, (f), __VA_ARGS__)
#define P4EST_LERRORF(f,...) \
P4EST_LOGF (SC_LP_ERROR, (f), __VA_ARGS__)
#endif
#define P4EST_NOTICE P4EST_STATISTICS
#define P4EST_NOTICEF P4EST_STATISTICSF
/* extern declarations */
/** the libsc package id for p4est (set in p4est_init()) */
extern int p4est_package_id;
static inline void
p4est_log_indent_push ()
{
sc_log_indent_push_count (p4est_package_id, 1);
}
static inline void
p4est_log_indent_pop ()
{
sc_log_indent_pop_count (p4est_package_id, 1);
}
/** Registers p4est with the SC Library and sets the logging behavior.
* This function is optional.
* This function must only be called before additional threads are created.
* If this function is not called or called with log_handler == NULL,
* the default SC log handler will be used.
* If this function is not called or called with log_threshold == SC_LP_DEFAULT,
* the default SC log threshold will be used.
* The default SC log settings can be changed with sc_set_log_defaults ().
*/
void p4est_init (sc_log_handler_t log_handler,
int log_threshold);
/** Compute hash value for two p4est_topidx_t integers.
* \param [in] tt Array of (at least) two values.
* \return An unsigned hash value.
*/
/*@unused@*/
static inline unsigned
p4est_topidx_hash2 (const p4est_topidx_t * tt)
{
uint32_t a, b, c;
#if (P4EST_TOPIDX_FITS_32)
a = (uint32_t) tt[0];
b = (uint32_t) tt[1];
c = 0;
#else
a = (uint32_t) (tt[0] && 0xFFFFFFFF);
b = (uint32_t) (tt[0] >> 32);
c = (uint32_t) (tt[1] && 0xFFFFFFFF);
sc_hash_mix (a, b, c);
a += (uint32_t) (tt[1] >> 32);
#endif
sc_hash_final (a, b, c);
return (unsigned) c;
}
/** Compute hash value for three p4est_topidx_t integers.
* \param [in] tt Array of (at least) three values.
* \return An unsigned hash value.
*/
/*@unused@*/
static inline unsigned
p4est_topidx_hash3 (const p4est_topidx_t * tt)
{
uint32_t a, b, c;
#if (P4EST_TOPIDX_FITS_32)
a = (uint32_t) tt[0];
b = (uint32_t) tt[1];
c = (uint32_t) tt[2];
#else
a = (uint32_t) (tt[0] && 0xFFFFFFFF);
b = (uint32_t) (tt[0] >> 32);
c = (uint32_t) (tt[1] && 0xFFFFFFFF);
sc_hash_mix (a, b, c);
a += (uint32_t) (tt[1] >> 32);
b += (uint32_t) (tt[2] && 0xFFFFFFFF);
c += (uint32_t) (tt[2] >> 32);
#endif
sc_hash_final (a, b, c);
return (unsigned) c;
}
/** Compute hash value for four p4est_topidx_t integers.
* \param [in] tt Array of (at least) four values.
* \return An unsigned hash value.
*/
/*@unused@*/
static inline unsigned
p4est_topidx_hash4 (const p4est_topidx_t * tt)
{
uint32_t a, b, c;
#if (P4EST_TOPIDX_FITS_32)
a = (uint32_t) tt[0];
b = (uint32_t) tt[1];
c = (uint32_t) tt[2];
sc_hash_mix (a, b, c);
a += (uint32_t) tt[3];
#else
a = (uint32_t) (tt[0] && 0xFFFFFFFF);
b = (uint32_t) (tt[0] >> 32);
c = (uint32_t) (tt[1] && 0xFFFFFFFF);
sc_hash_mix (a, b, c);
a += (uint32_t) (tt[1] >> 32);
b += (uint32_t) (tt[2] && 0xFFFFFFFF);
c += (uint32_t) (tt[2] >> 32);
sc_hash_mix (a, b, c);
a += (uint32_t) (tt[3] && 0xFFFFFFFF);
b += (uint32_t) (tt[3] >> 32);
#endif
sc_hash_final (a, b, c);
return (unsigned) c;
}
/*@unused@*/
static inline int
p4est_topidx_is_sorted (p4est_topidx_t * t, int length)
{
int i;
for (i = 1; i < length; ++i) {
if (t[i - 1] > t[i]) {
return 0;
}
}
return 1;
}
/*@unused@*/
static inline void
p4est_topidx_bsort (p4est_topidx_t * t, int length)
{
int i, j;
p4est_topidx_t tswap;
/* go through all elements except the last */
for (i = length - 1; i > 0; --i) {
/* bubble up the first element until before position i */
for (j = 0; j < i; ++j) {
if (t[j] > t[j + 1]) {
tswap = t[j + 1];
t[j + 1] = t[j];
t[j] = tswap;
}
}
}
P4EST_ASSERT (p4est_topidx_is_sorted (t, length));
}
/*@unused@*/
static inline uint64_t
p4est_partition_cut_uint64 (uint64_t global_num, int p, int num_procs)
{
uint64_t result;
/* In theory, a double * double product should never overflow
due to the 15-bit exponent used internally on x87 and above.
Also in theory, 80-bit floats should be used internally,
and multiply/divide associativity goes left-to-right.
Still checking for funny stuff just to be sure. */
P4EST_ASSERT (0 <= p && p <= num_procs);
if (p == num_procs) {
/* prevent roundoff error and division by zero */
return global_num;
}
result = (uint64_t)
(((long double) global_num * (double) p) / (double) num_procs);
P4EST_ASSERT (result <= global_num);
return result;
}
/*@unused@*/
static inline p4est_gloidx_t
p4est_partition_cut_gloidx (p4est_gloidx_t global_num, int p, int num_procs)
{
p4est_gloidx_t result;
/* In theory, a double * double product should never overflow
due to the 15-bit exponent used internally on x87 and above.
Also in theory, 80-bit floats should be used internally,
and multiply/divide associativity goes left-to-right.
Still checking for funny stuff just to be sure. */
P4EST_ASSERT (global_num >= 0);
P4EST_ASSERT (0 <= p && p <= num_procs);
if (p == num_procs) {
/* prevent roundoff error and division by zero */
return global_num;
}
result = (p4est_gloidx_t)
(((long double) global_num * (double) p) / (double) num_procs);
P4EST_ASSERT (0 <= result && result <= global_num);
return result;
}
SC_EXTERN_C_END;
#endif /* !P4EST_BASE_H */
|