7.0
general documentation
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-2021 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
43 extern "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)
197 typedef int int32_t;
198 # elif (SIZEOF_SHORT == 4)
199 typedef 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)
209 typedef int int64_t;
210 # elif (SIZEOF_LONG == 8)
211 typedef long int64_t;
212 # elif (HAVE_LONG_LONG == 8) /* SIZEOF_LONG_LONG not generally available */
213 typedef 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)
223 typedef unsigned uint32_t;
224 # elif (SIZEOF_SHORT == 4)
225 typedef 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)
235 typedef unsigned uint64_t;
236 # elif (SIZEOF_LONG == 8)
237 typedef unsigned long uint64_t;
238 # elif (HAVE_LONG_LONG) /* SIZEOF_LONG_LONG not generally available */
239 typedef 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
250 extern "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 
260 typedef 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 
272 } cs_datatype_t;
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 /* Local integer index or number */
297 
298 #if defined(HAVE_LONG_LNUM)
299  typedef long cs_lnum_t;
300 #else
301  typedef int cs_lnum_t;
302 #endif
303 
304 /* Other types */
305 typedef double cs_coord_t; /* Real number (coordinate value) */
306 
307 typedef double cs_real_t; /* Fortran double precision */
308 typedef char cs_byte_t; /* Byte (untyped memory unit) */
309 typedef unsigned short int cs_flag_t; /* Flag storing metadata */
310 
311 /* Vector or array block types */
312 
313 typedef cs_lnum_t cs_lnum_2_t[2]; /* Vector of 2 local numbers */
314 typedef cs_lnum_t cs_lnum_3_t[3]; /* Vector of 3 local numbers */
315 
316 typedef cs_coord_t cs_coord_3_t[3]; /* Vector of 3 real (coordinate)
317  values */
318 
319 typedef cs_real_t cs_real_2_t[2]; /* Vector of 2 real values */
320 typedef cs_real_t cs_real_3_t[3]; /* Vector of 3 real values */
321 typedef cs_real_t cs_real_4_t[4]; /* Vector of 4 real values */
322 typedef cs_real_t cs_real_6_t[6]; /* Vector of 6 real values
323  (for symmetric tensor) */
324 typedef cs_real_t cs_real_9_t[9]; /* Vector of 9 real values */
325 typedef cs_real_t cs_real_10_t[10]; /* Vector of 10 real values */
326 
327 typedef cs_real_t cs_real_33_t[3][3]; /* Matrix of 3x3 real values */
328 typedef cs_real_t cs_real_66_t[6][6]; /* Matrix of 6x6 real values */
329 typedef cs_real_t cs_real_99_t[9][9]; /* Matrix of 9x9 real values */
330 
331 typedef cs_real_t cs_real_333_t[3][3][3]; /* tensor of 3x3x3 real values */
332 
333 typedef cs_real_t cs_real_34_t[3][4]; /* Matrix of 3x4 real values */
334 
335 typedef cs_real_t cs_real_63_t[6][3]; /* Matrix of 6x3 real values */
336 
337 typedef cs_real_t cs_real_69_t[6][9]; /* Matrix of 6x9 real values */
338 
339 typedef cs_real_33_t cs_real_332_t[2]; /* vector of 2 3x3 matrices
340  of real values */
341 typedef cs_real_66_t cs_real_662_t[2]; /* vector of 2 6x6 matrices
342  of real values */
343 
344 typedef struct {
345 
346  double val; /* Value */
347  int id; /* Id related to value */
348 
350 
351 /* Vector-valued quantity stored using its measure (i.e. length) and
352  its direction given by a unitary vector */
353 typedef struct {
354 
355  double meas;
356  double unitv[3];
357 
358 } cs_nvec3_t;
359 
360 /* Mappings to MPI datatypes */
361 /*---------------------------*/
362 
363 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
364 
365 # define CS_MPI_REAL MPI_DOUBLE /* If cs_real_t is a double */
366 
367 /* MPI type for cs_gnum_t integer type (depends on configuration) */
368 
369 # if defined(HAVE_LONG_GNUM)
370 # if (SIZEOF_LONG == 8)
371 # define CS_MPI_GNUM MPI_UNSIGNED_LONG
372 # elif (SIZEOF_LONG_LONG == 8)
373 # if defined(MPI_UNSIGNED_LONG_LONG)
374 # define CS_MPI_GNUM MPI_UNSIGNED_LONG_LONG
375 # elif defined(MPI_LONG_LONG)
376 # define CS_MPI_GNUM MPI_LONG_LONG
377 # endif
378 # endif
379 # if !defined(CS_MPI_GNUM)
380 # error
381 # endif
382 # else
383 # define CS_MPI_GNUM MPI_UNSIGNED
384 # endif
385 
386 /* MPI type for cs_lnum_t type */
387 
388 # if defined(HAVE_LONG_LNUM)
389 # define CS_MPI_LNUM MPI_LONG
390 # else
391 # define CS_MPI_LNUM MPI_INT
392 # endif
393 
394 # define CS_MPI_EFLAG MPI_UNSIGNED /* MPI type for cs_mflag_t type */
395 # define CS_MPI_FLAG MPI_UNSIGNED_SHORT /* MPI type for cs_flag_t type */
396 # define CS_MPI_COORD MPI_DOUBLE /* MPI type for cs_coord_t type */
397 
398 #endif /* defined(HAVE_MPI) && !defined(CS_IGNORE_MPI) */
399 
400 /* Mappings to Code_Saturne datatypes */
401 /*------------------------------------*/
402 
403 #if defined(HAVE_LONG_GNUM)
404 # define CS_GNUM_TYPE CS_UINT64
405 #elif (SIZEOF_INT == 8)
406 # define CS_GNUM_TYPE CS_UINT64
407 #else
408 # define CS_GNUM_TYPE CS_UINT32
409 #endif
410 
411 #if defined(HAVE_LONG_LNUM)
412 # if (SIZEOF_LONG == 8)
413 # define CS_LNUM_TYPE CS_INT64
414 # else
415 # define CS_LNUM_TYPE CS_INT32
416 # endif
417 #else
418 # if (SIZEOF_INT == 8)
419 # define CS_LNUM_TYPE CS_INT64
420 # else
421 # define CS_LNUM_TYPE CS_INT32
422 # endif
423 #endif
424 
425 #if (SIZEOF_INT == 8)
426 # define CS_INT_TYPE CS_INT64
427 #else
428 # define CS_INT_TYPE CS_INT32
429 #endif
430 
431 #if (SIZEOF_INT == 8)
432 # define CS_UINT_TYPE CS_UINT64
433 #else
434 # define CS_UINT_TYPE CS_UINT32
435 #endif
436 
437 #define CS_FLAG_TYPE CS_UINT16
438 #define CS_EFLAG_TYPE CS_UINT_TYPE
439 #define CS_REAL_TYPE CS_DOUBLE
440 #define CS_COORD_TYPE CS_DOUBLE
441 
442 /* Minimum size for OpenMP loops
443  * (will need benchmarking and tuning for various systems)
444  *---------------------------------------------------------*/
445 
446 #define CS_THR_MIN 128
447 
448 /* Cache line size, or multiple thereof */
449 /*--------------------------------------*/
450 
451 #define CS_CL_SIZE 64
452 
453 /*----------------------------------------------------------------------------
454  * Type independent min an max (caution: the argument is evaluated)
455  *----------------------------------------------------------------------------*/
456 
457 #define CS_ABS(a) ((a) < 0 ? -(a) : (a))
458 #define CS_MIN(a,b) ((a) < (b) ? (a) : (b))
459 #define CS_MAX(a,b) ((a) > (b) ? (a) : (b))
461 /*----------------------------------------------------------------------------
462  * Variable interlace type:
463  * {x1, y1, z1, x2, y2, z2, ...,xn, yn, zn} if interlaced
464  * {x1, x2, ..., xn, y1, y2, ..., yn, z1, z2, ..., zn} if non interlaced
465  *----------------------------------------------------------------------------*/
466 
467 typedef enum {
468 
469  CS_INTERLACE, /* Variable is interlaced */
470  CS_NO_INTERLACE /* Variable is not interlaced */
471 
473 
474 /*----------------------------------------------------------------------------
475  * Macro used to silence "unused argument" warnings.
476  *
477  * This is useful when a function must match a given function pointer
478  * type, but does not use all possible arguments.
479  *----------------------------------------------------------------------------*/
480 
481 #define CS_UNUSED(x) (void)(x)
482 #define CS_NO_WARN_IF_UNUSED(x) (void)(x)
483 
484 /*----------------------------------------------------------------------------
485  * Macros for compilation with a C++ compiler
486  *----------------------------------------------------------------------------*/
487 
488 #undef BEGIN_C_DECLS
489 #undef END_C_DECLS
490 
491 #if defined(__cplusplus)
492 # define BEGIN_C_DECLS extern "C" {
493 # define END_C_DECLS }
494 #else
495 # define BEGIN_C_DECLS
496 # define END_C_DECLS
497 #endif
498 
499 /*----------------------------------------------------------------------------
500  * Macros for Fortran interoperability
501  *----------------------------------------------------------------------------*/
502 
503 /*
504  * Macro for handling of different symbol names (underscored or not,
505  * lowercase or uppercase) between C and Fortran, for link resolution.
506  */
507 
508 #if !defined (__hpux)
509 #define CS_PROCF(x, y) x##_
510 #else
511 #define CS_PROCF(x, y) x
512 #endif
513 
514 /*
515  * Macro used to handle automatic "Fortran string length" arguments
516  * (not used by Code_Saturne calls, but set by many compilers).
517  * Some compilers, like the Fujitsu VPP 5000 compiler in its time, may not
518  * support the variable length lists in mixed C/Fortran calls.
519  */
520 
521 #if defined (__uxpv__) /* Fujitsu VPP 5000 case */
522 #define CS_ARGF_SUPP_CHAINE
523 #else
524 #define CS_ARGF_SUPP_CHAINE , ...
525 #endif
526 
527 /*=============================================================================
528  * Global variables
529  *============================================================================*/
530 
531 /* Empty but non-NULL string */
532 
533 extern const char cs_empty_string[];
534 
535 /* Sizes and names associated with datatypes */
536 
537 extern const size_t cs_datatype_size[];
538 extern const char *cs_datatype_name[];
539 
540 /* MPI Datatypes associated with Code_Saturne datatypes */
541 
542 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
543 
544 extern MPI_Datatype cs_datatype_to_mpi[];
545 
546 #endif
547 
548 /* Global variables indicationg task state */
549 
550 extern int cs_glob_n_threads; /* Number of threads */
551 
552 extern int cs_glob_rank_id; /* Rank in main MPI communicator */
553 extern int cs_glob_n_ranks; /* Size of main MPI communicator */
554 
555 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
556 
557 extern MPI_Comm cs_glob_mpi_comm; /* Main MPI intra-communicator */
558 
559 #endif
560 
561 /*=============================================================================
562  * Public functions
563  *============================================================================*/
564 
565 /*----------------------------------------------------------------------------*/
574 /*----------------------------------------------------------------------------*/
575 
576 inline static cs_lnum_t
577 cs_align(cs_lnum_t i,
578  cs_lnum_t m)
579 {
580  return ((i > 0) ? ((i-1)/m+1)*m : 0);
581 }
582 
583 /*----------------------------------------------------------------------------*/
584 
585 #ifdef __cplusplus
586 }
587 #endif /* __cplusplus */
588 
589 #endif /* __CS_DEFS_H__ */
MPI_Comm cs_glob_mpi_comm
Definition: cs_defs.c:179
cs_datatype_t
Definition: cs_defs.h:260
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_lnum_t cs_lnum_3_t[3]
Definition: cs_defs.h:314
cs_real_t cs_real_333_t[3][3][3]
Definition: cs_defs.h:331
Definition: cs_defs.h:268
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition: cs_defs.h:319
Definition: cs_defs.h:267
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:322
Definition: cs_defs.h:469
cs_real_t cs_real_34_t[3][4]
Definition: cs_defs.h:333
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:328
char cs_byte_t
Definition: cs_defs.h:308
cs_interlace_t
Definition: cs_defs.h:467
Definition: cs_defs.h:262
cs_coord_t cs_coord_3_t[3]
Definition: cs_defs.h:316
cs_real_t cs_real_99_t[9][9]
Definition: cs_defs.h:329
int cs_glob_n_ranks
Definition: cs_defs.c:175
cs_real_66_t cs_real_662_t[2]
Definition: cs_defs.h:341
Definition: cs_defs.h:270
double cs_coord_t
Definition: cs_defs.h:305
cs_real_t cs_real_4_t[4]
vector of 4 floating-point values
Definition: cs_defs.h:321
double cs_real_t
Floating-point value.
Definition: cs_defs.h:307
Definition: cs_defs.h:353
Definition: cs_defs.h:470
Definition: cs_defs.h:344
cs_real_t cs_real_9_t[9]
Definition: cs_defs.h:324
Definition: cs_defs.h:264
cs_real_t cs_real_10_t[10]
Definition: cs_defs.h:325
double meas
Definition: cs_defs.h:355
int cs_glob_n_threads
Definition: cs_defs.c:172
MPI_Datatype cs_datatype_to_mpi[]
Definition: cs_defs.c:157
const char cs_empty_string[]
Definition: cs_defs.c:129
cs_real_33_t cs_real_332_t[2]
vector of 2 3x3 matrices of floating-point values
Definition: cs_defs.h:339
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:313
Definition: cs_defs.h:269
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:320
const size_t cs_datatype_size[]
Definition: cs_defs.c:133
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:301
cs_real_t cs_real_69_t[6][9]
Definition: cs_defs.h:337
Definition: cs_defs.h:263
unsigned short int cs_flag_t
Definition: cs_defs.h:309
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:327
const char * cs_datatype_name[]
Definition: cs_defs.c:143
cs_real_t cs_real_63_t[6][3]
Definition: cs_defs.h:335
int id
Definition: cs_defs.h:347
Definition: cs_defs.h:266
Definition: cs_defs.h:265
int cs_glob_rank_id
Definition: cs_defs.c:174
double val
Definition: cs_defs.h:346