Program Listing for File t8.h

Return to documentation for file (src/t8.h)

/*
  This file is part of t8code.
  t8code is a C library to manage a collection (a forest) of multiple
  connected adaptive space-trees of general element classes in parallel.

  Copyright (C) 2015 the developers

  t8code 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.

  t8code 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 t8code; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef T8_H
#define T8_H

#include <t8_misc/t8_with_macro_error.h>
#ifdef __cplusplus
#include <cinttypes>
#else
#include <inttypes.h>
#endif

#include <sc_config.h>
#if (defined(T8_ENABLE_MPI) && !defined(SC_ENABLE_MPI)) || (!defined(T8_ENABLE_MPI) && defined(SC_ENABLE_MPI))
#error "MPI configured differently in t8code and libsc"
#endif
#if (defined(T8_ENABLE_MPIIO) && !defined(SC_ENABLE_MPIIO)) || (!defined(T8_ENABLE_MPIIO) && defined(SC_ENABLE_MPIIO))
#error "MPI I/O configured differently in t8code and libsc"
#endif

/* indirectly also include sc.h */
#include <sc_containers.h>

#define T8_EXTERN_C_BEGIN() SC_EXTERN_C_BEGIN

#define T8_EXTERN_C_END() SC_EXTERN_C_END

T8_EXTERN_C_BEGIN ();

#define t8_const _sc_const

#define t8_restrict _sc_restrict

/* Note that we use the same definition as in sc.h. We are deliberately not using
 * #define T8_ASSERT SC_ASSERT
 * since then the assertion would not trigger if sc is not configured in debugging mode.
 * However, we want it to trigger any time t8code is in debugging mode, independent of sc.
 */
#if T8_ENABLE_DEBUG
#define T8_ASSERT(c) SC_CHECK_ABORT ((c), "Assertion '" #c "'")
#else
#define T8_ASSERT(c) SC_NOOP ()
#endif

#if T8_ENABLE_DEBUG
#define T8_ASSERTF(c, msg) SC_CHECK_ABORT ((c), "Assertion '" #c "': " msg)
#else
#define T8_ASSERTF(c, msg) SC_NOOP ()
#endif

#define T8_ALLOC(t, n) (t *) sc_malloc (t8_get_package_id (), (n) * sizeof (t))

#define T8_ALLOC_ZERO(t, n) (t *) sc_calloc (t8_get_package_id (), (size_t) (n), sizeof (t))

#define T8_FREE(p) sc_free (t8_get_package_id (), (p))

#define T8_REALLOC(p, t, n) (t *) sc_realloc (t8_get_package_id (), (p), (n) * sizeof (t))

typedef int32_t t8_locidx_t;
#define T8_LOCIDX_FORMAT PRId32
#define T8_MPI_LOCIDX sc_MPI_INT
#define T8_LOCIDX_ABS(x) ((t8_locidx_t) labs ((long) (x)))
#define T8_LOCIDX_MAX INT32_MAX
#define t8_compare_locidx(v, w) sc_int32_compare (v, w)
typedef int t8_procidx_t;
typedef int64_t t8_gloidx_t;
#define T8_GLOIDX_FORMAT PRId64
#define T8_MPI_GLOIDX sc_MPI_LONG_LONG_INT
#define T8_GLOIDX_ABS(x) ((t8_gloidx_t) llabs ((long long) (x)))
#define T8_GLOIDX_MAX INT64_MAX
#define t8_compare_gloidx(v, w) sc_int64_compare (v, w)

typedef uint64_t t8_linearidx_t;
#define T8_LINEARIDX_FORMAT PRIu64
#define T8_MPI_LINEARIDX sc_MPI_UNSIGNED_LONG_LONG

#define T8_PADDING_SIZE (sizeof (void *))
#define T8_ADD_PADDING(_x) ((T8_PADDING_SIZE - ((_x) % T8_PADDING_SIZE)) % T8_PADDING_SIZE)

#define T8_PRECISION_EPS SC_EPS
#define T8_PRECISION_SQRT_EPS sqrt (T8_PRECISION_EPS)

#define T8_1D_TO_1D(nx, i) (i)
#define T8_2D_TO_1D(nx, ny, i, j) ((i) * (ny) + (j))
#define T8_3D_TO_1D(nx, ny, nz, i, j, k) (((i) * (ny) + (j)) * (nz) + (k))
#define T8_4D_TO_1D(nx, ny, nz, nl, i, j, k, l) ((((i) * (ny) + (j)) * (nz) + (k)) * (nl) + (l))

typedef enum {
  T8_MPI_TAG_FIRST = SC_TAG_FIRST,
  T8_MPI_PARTITION_CMESH = SC_TAG_LAST,
  T8_MPI_PARTITION_FOREST,
  T8_MPI_GHOST_FOREST,
  T8_MPI_GHOST_EXC_FOREST,
  T8_MPI_CMESH_UNIFORM_BOUNDS_START,
  T8_MPI_CMESH_UNIFORM_BOUNDS_END,
  T8_MPI_TEST_ELEMENT_PACK_TAG,
  T8_MPI_PFC_TAG,
  T8_MPI_TAG_LAST
} t8_MPI_tag_t;

int
t8_get_package_id (void);

void
t8_logv (int category, int priority, const char *fmt, va_list ap);

void
t8_logf (int category, int priority, const char *fmt, ...)
#ifndef T8_DOXYGEN
  __attribute__ ((format (printf, 3, 4)))
#endif
  ;

void
t8_log_indent_push (void);

void
t8_log_indent_pop (void);

void
t8_global_errorf (const char *fmt, ...)
#ifndef T8_DOXYGEN
  __attribute__ ((format (printf, 1, 2)))
#endif
  ;

void
t8_global_essentialf (const char *fmt, ...)
#ifndef T8_DOXYGEN
  __attribute__ ((format (printf, 1, 2)))
#endif
  ;

void
t8_global_productionf (const char *fmt, ...)
#ifndef T8_DOXYGEN
  __attribute__ ((format (printf, 1, 2)))
#endif
  ;

void
t8_global_infof (const char *fmt, ...)
#ifndef T8_DOXYGEN
  __attribute__ ((format (printf, 1, 2)))
#endif
  ;

void
t8_infof (const char *fmt, ...)
#ifndef T8_DOXYGEN
  __attribute__ ((format (printf, 1, 2)))
#endif
  ;

void
t8_productionf (const char *fmt, ...)
#ifndef T8_DOXYGEN
  __attribute__ ((format (printf, 1, 2)))
#endif
  ;

void
t8_debugf (const char *fmt, ...)
#ifndef T8_DOXYGEN
  __attribute__ ((format (printf, 1, 2)))
#endif
  ;

void
t8_errorf (const char *fmt, ...)
#ifndef T8_DOXYGEN
  __attribute__ ((format (printf, 1, 2)))
#endif
  ;

void
t8_set_external_log_fcn (void (*log_fcn) (int category, int priority, const char *msg));

void
t8_init (int log_threshold);

void *
t8_sc_array_index_locidx (const sc_array_t *array, const t8_locidx_t index);

T8_EXTERN_C_END ();

#endif /* !T8_H */