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