My Project
programmer's documentation
Loading...
Searching...
No Matches
cs_defs.h
Go to the documentation of this file.
1#ifndef __CS_DEFS_H__
2#define __CS_DEFS_H__
3
4/*============================================================================
5 * Base macro and typedef definitions for system portability
6 *============================================================================*/
7
8/*
9 This file is part of Code_Saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2019 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*============================================================================
31 * Autoconf-defined macros
32 *============================================================================*/
33
34#if defined(HAVE_CONFIG_H)
35# include "cs_config.h"
36#endif
37
38/*============================================================================
39 * Internationalization
40 *============================================================================*/
41
42#ifdef __cplusplus
43extern "C" {
44#if 0
45} /* Fake brace to force Emacs auto-indentation back to column 0 */
46#endif
47#endif /* __cplusplus */
48
49#if defined(ENABLE_NLS) && defined(HAVE_GETTEXT)
50
51# include <libintl.h>
52# define _(String) dgettext(PACKAGE, String)
53# ifdef gettext_noop
54# define N_(String) gettext_noop(String)
55# else
56# define N_(String) String
57# endif /* gettext_noop */
58
59#else
60
61# define _LIBINTL_H /* Prevent inclusion of <libintl.h> by other files
62 with incorrect or missing checks;
63 TODO locate files causing issues to avoid
64 requiring this workaround */
65
66# define _(String) (String)
67# define N_(String) String
68# define textdomain(String) (String)
69# define gettext(String) (String)
70# define dgettext(Domain,String) (String)
71# define dcgettext(Domain,String,Type) (String)
72# define bindtextdomain(Domain, Directory) (Domain)
73
74#endif /* ENABLE_NLS && HAVE_GETTEXT */
75
76#ifdef __cplusplus
77}
78#endif /* __cplusplus */
79
80/*============================================================================
81 * Parallelism
82 *============================================================================*/
83
84#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
85
86# include <mpi.h>
87
88# if !defined(MPI_VERSION) /* Defined in up-to-date MPI versions */
89# define MPI_VERSION 1
90# endif
91
92# if MPI_VERSION == 1
93# define MPI_Info int
94# define MPI_INFO_NULL 0
95# endif
96
97#endif
98
99#if defined(HAVE_OPENMP)
100# include <omp.h>
101#endif
102
103/*============================================================================
104 * C99 Qualifiers
105 *============================================================================*/
106
107#ifndef __cplusplus /* C */
108
109/* inline provided by cs_config.h if necessary */
110
111#if !defined(__STDC_VERSION__)
112# define __STDC_VERSION__ 1989
113#endif
114
115/*
116 * Redefinition of "inline" et "restrict" qualifiers incompatible with
117 * some C89 compilers (standard in C99)
118 */
119
120#if (__STDC_VERSION__ < 199901L)
121
122# if defined(__GNUC__)
123# define inline __inline__
124# define restrict __restrict__
125# else
126# define inline
127# define restrict
128# endif
129
130#endif
131
132#else /* C++ */
133
134# ifndef HAVE_RESTRICT /* Must be provided by caller */
135# define restrict
136# endif
137
138#endif /* __cplusplus */
139
140/*============================================================================
141 * Definitions that may not always be provided directly by the system
142 *============================================================================*/
143
144/*
145 * Obtain definitions such as that of size_t through stddef.h (C99 standard)
146 * if available (preferred method), or through stdlib.h (which defines
147 * malloc() and family and so must define size_t some way) otherwise.
148 */
149
150#if HAVE_STDDEF_H
151# include <stddef.h>
152#else
153# include <stdlib.h>
154#endif
155
156/*
157 * Usually stdint.h is included by inttypes.h, but only inttypes.h exists
158 * on certain systems, such as Tru64Unix.
159 */
160
161#if HAVE_STDINT_H
162# include <stdint.h>
163#elif HAVE_INTTYPES_H
164# include <inttypes.h>
165#endif
166
167/*
168 * Obtain the definition of off_t.
169 */
170
171#if defined(HAVE_SYS_TYPES_H)
172#include <sys/types.h>
173#endif
174
175/* C99 _Bool type */
176
177#if HAVE_STDBOOL_H
178# include <stdbool.h>
179#else
180# ifndef __cplusplus
181# ifndef HAVE__BOOL
182# define _Bool signed char;
183# endif
184# define bool _Bool
185# define false 0
186# define true 1
187# else
188# define _Bool bool;
189# endif
190# define __bool_true_false_are_defined 1
191#endif
192
193/* int32_t type */
194
195#if !defined(HAVE_INT32_T)
196# if (SIZEOF_INT == 4)
197typedef int int32_t;
198# elif (SIZEOF_SHORT == 4)
199typedef short int32_t;
200# else
201# error
202# endif
203#endif
204
205/* int64_t type */
206
207#if !defined(HAVE_INT64_T)
208# if (SIZEOF_INT == 8)
209typedef int int64_t;
210# elif (SIZEOF_LONG == 8)
211typedef long int64_t;
212# elif (HAVE_LONG_LONG == 8) /* SIZEOF_LONG_LONG not generally available */
213typedef long long int64_t;
214# else
215# error
216# endif
217#endif
218
219/* uint32_t type */
220
221#if !defined(HAVE_UINT32_T)
222# if (SIZEOF_INT == 4)
223typedef unsigned uint32_t;
224# elif (SIZEOF_SHORT == 4)
225typedef unsigned short uint32_t;
226# else
227# error
228# endif
229#endif
230
231/* uint64_t type */
232
233#if !defined(HAVE_UINT64_T)
234# if (SIZEOF_INT == 8)
235typedef unsigned uint64_t;
236# elif (SIZEOF_LONG == 8)
237typedef unsigned long uint64_t;
238# elif (HAVE_LONG_LONG) /* SIZEOF_LONG_LONG not generally available */
239typedef unsigned long long uint64_t;
240# else
241# error
242# endif
243#endif
244
245/*============================================================================
246 * General types and macros used throughout Code_Saturne
247 *============================================================================*/
248
249#ifdef __cplusplus
250extern "C" {
251#if 0
252} /* Fake brace to force Emacs auto-indentation back to column 0 */
253#endif
254#endif /* __cplusplus */
255
256/*----------------------------------------------------------------------------
257 * Variable value type.
258 *----------------------------------------------------------------------------*/
259
260typedef enum {
261
262 CS_DATATYPE_NULL, /* empty datatype */
263 CS_CHAR, /* character values */
264 CS_FLOAT, /* 4-byte floating point values */
265 CS_DOUBLE, /* 8-byte floating point values */
266 CS_UINT16, /* 2-byte unsigned integer values */
267 CS_INT32, /* 4-byte signed integer values */
268 CS_INT64, /* 8-byte signed integer values */
269 CS_UINT32, /* 4-byte unsigned integer values */
270 CS_UINT64 /* 8-byte unsigned integer values */
271
273
274/*----------------------------------------------------------------------------
275 * Basic types used by Code_Saturne
276 * They may be modified here to better map to a given library, with the
277 * following constraints:
278 * - cs_lnum_t must be signed
279 * - cs_gnum_t may be signed or unsigned
280 *----------------------------------------------------------------------------*/
281
282/* Global integer index or number */
283
284#if defined(HAVE_LONG_GNUM)
285 #if (SIZEOF_LONG == 8)
286 typedef unsigned long cs_gnum_t;
287 #elif (SIZEOF_LONG_LONG == 8)
288 typedef unsigned long long cs_gnum_t;
289 #else
290 #error
291 #endif
292#else
293 typedef unsigned cs_gnum_t;
294#endif
295
296/* Other types */
297
298typedef int cs_lnum_t; /* Local integer index or number */
299typedef double cs_coord_t; /* Real number (coordinate value) */
300
301typedef int cs_int_t; /* Fortran integer */
302typedef double cs_real_t; /* Fortran double precision */
303typedef char cs_byte_t; /* Byte (untyped memory unit) */
304typedef unsigned short int cs_flag_t; /* Flag for storing metadata */
305
306/* Vector or array block types */
307
308typedef int cs_lnum_2_t[2]; /* Vector of 2 local numbers */
309typedef int cs_lnum_3_t[3]; /* Vector of 3 local numbers */
310
311typedef double cs_coord_3_t[3]; /* Vector of 3 real (coordinate)
312 values */
313
314typedef cs_real_t cs_real_2_t[2]; /* Vector of 2 real values */
315typedef cs_real_t cs_real_3_t[3]; /* Vector of 3 real values */
316typedef cs_real_t cs_real_4_t[4]; /* Vector of 4 real values */
317typedef cs_real_t cs_real_6_t[6]; /* Vector of 6 real values
318 (for symmetric tensor) */
319typedef cs_real_t cs_real_9_t[9]; /* Vector of 9 real values */
320
321typedef cs_real_t cs_real_33_t[3][3]; /* Matrix of 3x3 real values */
322typedef cs_real_t cs_real_66_t[6][6]; /* Matrix of 6x6 real values */
323typedef cs_real_t cs_real_99_t[9][9]; /* Matrix of 9x9 real values */
324
325typedef cs_real_t cs_real_34_t[3][4]; /* Matrix of 3x4 real values */
326
327typedef cs_real_t cs_real_63_t[6][3]; /* Matrix of 6x3 real values */
328
329typedef cs_real_33_t cs_real_332_t[2]; /* vector of 2 3x3 matrices
330 of real values */
331typedef cs_real_66_t cs_real_662_t[2]; /* vector of 2 6x6 matrices
332 of real values */
333
334typedef struct {
335
336 double val; /* Value */
337 int id; /* Id related to value */
338
340
341/* Vector-valued quantity stored using its measure (i.e. length) and
342 its direction given by a unitary vector */
343typedef struct {
344
345 double meas;
346 double unitv[3];
347
348} cs_nvec3_t;
349
350/* Mappings to MPI datatypes */
351/*---------------------------*/
352
353#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
354
355# define CS_MPI_INT MPI_INT /* If cs_int_t is an int */
356# define CS_MPI_REAL MPI_DOUBLE /* If cs_real_t is a double */
357
358/* MPI type for cs_gnum_t integer type (depends on configuration) */
359
360# if defined(HAVE_LONG_GNUM)
361# if (SIZEOF_LONG == 8)
362# define CS_MPI_GNUM MPI_UNSIGNED_LONG
363# elif (SIZEOF_LONG_LONG == 8)
364# if defined(MPI_UNSIGNED_LONG_LONG)
365# define CS_MPI_GNUM MPI_UNSIGNED_LONG_LONG
366# elif defined(MPI_LONG_LONG)
367# define CS_MPI_GNUM MPI_LONG_LONG
368# endif
369# endif
370# if !defined(CS_MPI_GNUM)
371# error
372# endif
373# else
374# define CS_MPI_GNUM MPI_UNSIGNED
375# endif
376
377# define CS_MPI_FLAG MPI_UNSIGNED_SHORT /* MPI type for cs_flag_t type */
378# define CS_MPI_LNUM MPI_INT /* MPI type for cs_lnum_t type */
379# define CS_MPI_COORD MPI_DOUBLE /* MPI type for cs_coord_t type */
380
381#endif /* defined(HAVE_MPI) && !defined(CS_IGNORE_MPI) */
382
383/* Mappings to Code_Saturne datatypes */
384/*------------------------------------*/
385
386#if defined(HAVE_LONG_GNUM)
387# define CS_GNUM_TYPE CS_UINT64
388#elif (SIZEOF_INT == 8)
389# define CS_GNUM_TYPE CS_UINT64
390#else
391# define CS_GNUM_TYPE CS_UINT32
392#endif
393
394#if (SIZEOF_INT == 8)
395# define CS_LNUM_TYPE CS_INT64
396#else
397# define CS_LNUM_TYPE CS_INT32
398#endif
399
400#if (SIZEOF_INT == 8)
401# define CS_INT_TYPE CS_INT64
402#else
403# define CS_INT_TYPE CS_INT32
404#endif
405
406#define CS_FLAG_TYPE CS_UINT16
407#define CS_REAL_TYPE CS_DOUBLE
408#define CS_COORD_TYPE CS_DOUBLE
409
410/* Minimum size for OpenMP loops
411 * (based on initial benchmarking, which will need updates)
412 *-----------------------------------------------------------*/
413
414#if defined(__bgq__) && defined(__xlc__)
415# define CS_THR_MIN 1014
416#else
417# define CS_THR_MIN 128
418#endif
419
420/* Cache line size, or multiple thereof */
421/*--------------------------------------*/
422
423#define CS_CL_SIZE 64
424
425/*----------------------------------------------------------------------------
426 * Type independent min an max (caution: the argument is evaluated)
427 *----------------------------------------------------------------------------*/
428
429#define CS_ABS(a) ((a) < 0 ? -(a) : (a)) /* Absolute value of a */
430#define CS_MIN(a,b) ((a) < (b) ? (a) : (b)) /* Minimum of a et b */
431#define CS_MAX(a,b) ((a) > (b) ? (a) : (b)) /* Maximum of a et b */
432
433/*----------------------------------------------------------------------------
434 * Variable interlace type:
435 * {x1, y1, z1, x2, y2, z2, ...,xn, yn, zn} if interlaced
436 * {x1, x2, ..., xn, y1, y2, ..., yn, z1, z2, ..., zn} if non interlaced
437 *----------------------------------------------------------------------------*/
438
439typedef enum {
440
441 CS_INTERLACE, /* Variable is interlaced */
442 CS_NO_INTERLACE /* Variable is not interlaced */
443
445
446/*----------------------------------------------------------------------------
447 * Macro used to silence "unused argument" warnings.
448 *
449 * This is useful when a function must match a given function pointer
450 * type, but does not use all possible arguments.
451 *----------------------------------------------------------------------------*/
452
453#define CS_UNUSED(x) (void)(x)
454#define CS_NO_WARN_IF_UNUSED(x) (void)(x)
455
456/*----------------------------------------------------------------------------
457 * Macros for compilation with a C++ compiler
458 *----------------------------------------------------------------------------*/
459
460#undef BEGIN_C_DECLS
461#undef END_C_DECLS
462
463#if defined(__cplusplus)
464# define BEGIN_C_DECLS extern "C" {
465# define END_C_DECLS }
466#else
467# define BEGIN_C_DECLS
468# define END_C_DECLS
469#endif
470
471/*----------------------------------------------------------------------------
472 * Macros for Fortran interoperability
473 *----------------------------------------------------------------------------*/
474
475/*
476 * Macro for handling of different symbol names (underscored or not,
477 * lowercase or uppercase) between C and Fortran, for link resolution.
478 */
479
480#if !defined (__hpux)
481#define CS_PROCF(x, y) x##_
482#else
483#define CS_PROCF(x, y) x
484#endif
485
486/*
487 * Macro used to handle automatic "Fortran string length" arguments
488 * (not used by Code_Saturne calls, but set by many compilers).
489 * Some compilers, like the Fujitsu VPP 5000 compiler in its time, may not
490 * support the variable length lists in mixed C/Fortran calls.
491 */
492
493#if defined (__uxpv__) /* Fujitsu VPP 5000 case */
494#define CS_ARGF_SUPP_CHAINE
495#else
496#define CS_ARGF_SUPP_CHAINE , ...
497#endif
498
499/*=============================================================================
500 * Global variables
501 *============================================================================*/
502
503/* Sizes and names associated with datatypes */
504
505extern const size_t cs_datatype_size[];
506extern const char *cs_datatype_name[];
507
508/* MPI Datatypes associated with Code_Saturne datatypes */
509
510#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
511
512extern MPI_Datatype cs_datatype_to_mpi[];
513
514#endif
515
516/* Global variables indicationg task state */
517
518extern int cs_glob_n_threads; /* Number of threads */
519
520extern int cs_glob_rank_id; /* Rank in main MPI communicator */
521extern int cs_glob_n_ranks; /* Size of main MPI communicator */
522
523#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
524
525extern MPI_Comm cs_glob_mpi_comm; /* Main MPI intra-communicator */
526
527#endif
528
529/*=============================================================================
530 * Public functions
531 *============================================================================*/
532
533/*----------------------------------------------------------------------------*/
542/*----------------------------------------------------------------------------*/
543
544inline static cs_lnum_t
546 cs_lnum_t m)
547{
548 return ((i > 0) ? ((i-1)/m+1)*m : 0);
549}
550
551/*----------------------------------------------------------------------------*/
552
553#ifdef __cplusplus
554}
555#endif /* __cplusplus */
556
557#endif /* __CS_DEFS_H__ */
int cs_glob_n_ranks
Definition cs_defs.c:177
cs_datatype_t
Definition cs_defs.h:260
@ CS_FLOAT
Definition cs_defs.h:264
@ CS_CHAR
Definition cs_defs.h:263
@ CS_UINT16
Definition cs_defs.h:266
@ CS_INT64
Definition cs_defs.h:268
@ CS_UINT64
Definition cs_defs.h:270
@ CS_DOUBLE
Definition cs_defs.h:265
@ CS_UINT32
Definition cs_defs.h:269
@ CS_INT32
Definition cs_defs.h:267
@ CS_DATATYPE_NULL
Definition cs_defs.h:262
const char * cs_datatype_name[]
Definition cs_defs.c:145
char cs_byte_t
Definition cs_defs.h:303
double cs_real_t
Floating-point value.
Definition cs_defs.h:302
const size_t cs_datatype_size[]
Definition cs_defs.c:135
cs_real_33_t cs_real_332_t[2]
vector of 2 3x3 matrices of floating-point values
Definition cs_defs.h:329
double cs_coord_3_t[3]
Definition cs_defs.h:311
int cs_glob_n_threads
Definition cs_defs.c:174
int cs_int_t
Fortran-compatible integer.
Definition cs_defs.h:301
int cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition cs_defs.h:308
cs_real_t cs_real_4_t[4]
vector of 4 floating-point values
Definition cs_defs.h:316
MPI_Datatype cs_datatype_to_mpi[]
Definition cs_defs.c:159
cs_real_t cs_real_99_t[9][9]
Definition cs_defs.h:323
double cs_coord_t
Definition cs_defs.h:299
cs_real_t cs_real_34_t[3][4]
Definition cs_defs.h:325
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition cs_defs.h:322
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition cs_defs.h:315
cs_real_66_t cs_real_662_t[2]
Definition cs_defs.h:331
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition cs_defs.h:314
cs_interlace_t
Definition cs_defs.h:439
@ CS_INTERLACE
Definition cs_defs.h:441
@ CS_NO_INTERLACE
Definition cs_defs.h:442
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition cs_defs.h:317
static cs_lnum_t cs_align(cs_lnum_t i, cs_lnum_t m)
Given a base index i, return the next index aligned with a size m.
Definition cs_defs.h:545
int cs_lnum_3_t[3]
Definition cs_defs.h:309
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition cs_defs.h:321
MPI_Comm cs_glob_mpi_comm
Definition cs_defs.c:181
int cs_lnum_t
local mesh entity id
Definition cs_defs.h:298
cs_real_t cs_real_63_t[6][3]
Definition cs_defs.h:327
cs_real_t cs_real_9_t[9]
Definition cs_defs.h:319
unsigned short int cs_flag_t
Definition cs_defs.h:304
int cs_glob_rank_id
Definition cs_defs.c:176
Definition cs_defs.h:334
double val
Definition cs_defs.h:336
int id
Definition cs_defs.h:337
Definition cs_defs.h:343
double meas
Definition cs_defs.h:345