YetAnotherCoupler 3.2.0_a
Loading...
Searching...
No Matches
utils_common.h
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef UTILS_COMMON_H
6#define UTILS_COMMON_H
7
8#include "yac_config.h"
9
10#ifdef YAC_OPENMP_ENABLED
11#include <omp.h>
12#endif
13
14#include <stdlib.h>
15#include "ppm/ppm_xfuncs.h"
16#include "ppm/core.h"
17#include "yac_types.h"
18#include "yac_assert.h"
19
25static inline void yac_remove_duplicates_int(int * array, size_t * n) {
26
27 size_t const N = *n;
28 size_t pos = 0;
29
30 if (N == 0) return;
31
32 int prev = array[0];
33
34 for (size_t i = 1; i < N; ++i) {
35
36 if (array[i] == prev) continue;
37
38 prev = array[i];
39 ++pos;
40
41 if (pos != i) array[pos] = array[i];
42 }
43
44 *n = pos + 1;
45}
46
48 const char * name;
49 int type;
50};
51
53 struct yac_name_type_pair const * pairs, size_t count, int type);
55 struct yac_name_type_pair const * pairs, size_t count, char const * name);
56
58 void * a, size_t count, size_t size,
59 int (*compare)(void const *, void const *), size_t * idx);
60
61/* =======================================================================
62 Macros
63 ======================================================================= */
64
65#ifndef MAX
66#define MAX(a,b) ((a) > (b) ? (a) : (b))
67#endif
68
69#ifndef MIN
70#define MIN(a,b) ((a) < (b) ? (a) : (b))
71#endif
72
73#ifdef YAC_OPENMP_ENABLED
74#define YAC_OMP_PARALLEL _Pragma("omp parallel")
75#define YAC_OMP_FOR _Pragma("omp for")
76#else
77#define YAC_OMP_PARALLEL
78#define YAC_OMP_FOR
79#endif
80
81#endif // UTILS_H
82
enum callback_type type
add versions of standard API functions not returning on error
const char * name
int yac_name_type_pair_get_type(struct yac_name_type_pair const *pairs, size_t count, char const *name)
Definition utils_core.c:26
static void yac_remove_duplicates_int(int *array, size_t *n)
void yac_qsort_index(void *a, size_t count, size_t size, int(*compare)(void const *, void const *), size_t *idx)
Definition quicksort.c:185
char const * yac_name_type_pair_get_name(struct yac_name_type_pair const *pairs, size_t count, int type)
Definition utils_core.c:17