programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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-2017 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 
336 /* Mappings to MPI datatypes */
337 /*---------------------------*/
338 
339 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
340 
341 # define CS_MPI_INT MPI_INT /* If cs_int_t is an int */
342 # define CS_MPI_REAL MPI_DOUBLE /* If cs_real_t is a double */
343 
344 /* MPI type for cs_gnum_t integer type (depends on configuration) */
345 
346 # if defined(HAVE_LONG_GNUM)
347 # if (SIZEOF_LONG == 8)
348 # define CS_MPI_GNUM MPI_UNSIGNED_LONG
349 # elif (SIZEOF_LONG_LONG == 8)
350 # if defined(MPI_UNSIGNED_LONG_LONG)
351 # define CS_MPI_GNUM MPI_UNSIGNED_LONG_LONG
352 # elif defined(MPI_LONG_LONG)
353 # define CS_MPI_GNUM MPI_LONG_LONG
354 # endif
355 # endif
356 # if !defined(CS_MPI_GNUM)
357 # error
358 # endif
359 # else
360 # define CS_MPI_GNUM MPI_UNSIGNED
361 # endif
362 
363 # define CS_MPI_FLAG MPI_UNSIGNED_SHORT /* MPI type for cs_flag_t type */
364 # define CS_MPI_LNUM MPI_INT /* MPI type for cs_lnum_t type */
365 # define CS_MPI_COORD MPI_DOUBLE /* MPI type for cs_coord_t type */
366 
367 #endif /* defined(HAVE_MPI) && !defined(CS_IGNORE_MPI) */
368 
369 /* Mappings to Code_Saturne datatypes */
370 /*------------------------------------*/
371 
372 #if defined(HAVE_LONG_GNUM)
373 # define CS_GNUM_TYPE CS_UINT64
374 #elif (SIZEOF_INT == 8)
375 # define CS_GNUM_TYPE CS_UINT64
376 #else
377 # define CS_GNUM_TYPE CS_UINT32
378 #endif
379 
380 #if (SIZEOF_INT == 8)
381 # define CS_LNUM_TYPE CS_INT64
382 #else
383 # define CS_LNUM_TYPE CS_INT32
384 #endif
385 
386 #if (SIZEOF_INT == 8)
387 # define CS_INT_TYPE CS_INT64
388 #else
389 # define CS_INT_TYPE CS_INT32
390 #endif
391 
392 #define CS_FLAG_TYPE CS_UINT16
393 #define CS_REAL_TYPE CS_DOUBLE
394 #define CS_COORD_TYPE CS_DOUBLE
395 
396 /* Minimum size for OpenMP loops
397  * (based on initial benchmarking, which will need updates)
398  *-----------------------------------------------------------*/
399 
400 #if defined(__bgq__) && defined(__xlc__)
401 # define CS_THR_MIN 1014
402 #else
403 # define CS_THR_MIN 128
404 #endif
405 
406 /* Cache line size, or multiple thereof */
407 /*--------------------------------------*/
408 
409 #define CS_CL_SIZE 64
410 
411 /*----------------------------------------------------------------------------
412  * Type independent min an max (caution: the argument is evaluated)
413  *----------------------------------------------------------------------------*/
414 
415 #define CS_ABS(a) ((a) < 0 ? -(a) : (a)) /* Absolute value of a */
416 #define CS_MIN(a,b) ((a) < (b) ? (a) : (b)) /* Minimum of a et b */
417 #define CS_MAX(a,b) ((a) > (b) ? (a) : (b)) /* Maximum of a et b */
418 
419 /*----------------------------------------------------------------------------
420  * Variable interlace type:
421  * {x1, y1, z1, x2, y2, z2, ...,xn, yn, zn} if interlaced
422  * {x1, x2, ..., xn, y1, y2, ..., yn, z1, z2, ..., zn} if non interlaced
423  *----------------------------------------------------------------------------*/
424 
425 typedef enum {
426 
427  CS_INTERLACE, /* Variable is interlaced */
428  CS_NO_INTERLACE /* Variable is not interlaced */
429 
431 
432 /*----------------------------------------------------------------------------
433  * Macro used to silence "unused argument" warnings.
434  *
435  * This is useful when a function must match a given function pointer
436  * type, but does not use all possible arguments.
437  *----------------------------------------------------------------------------*/
438 
439 #define CS_UNUSED(x) (void)(x)
440 #define CS_NO_WARN_IF_UNUSED(x) (void)(x)
441 
442 /*----------------------------------------------------------------------------
443  * Macros for compilation with a C++ compiler
444  *----------------------------------------------------------------------------*/
445 
446 #undef BEGIN_C_DECLS
447 #undef END_C_DECLS
448 
449 #if defined(__cplusplus)
450 # define BEGIN_C_DECLS extern "C" {
451 # define END_C_DECLS }
452 #else
453 # define BEGIN_C_DECLS
454 # define END_C_DECLS
455 #endif
456 
457 /*----------------------------------------------------------------------------
458  * Macros for Fortran interoperability
459  *----------------------------------------------------------------------------*/
460 
461 /*
462  * Macro for handling of different symbol names (underscored or not,
463  * lowercase or uppercase) between C and Fortran, for link resolution.
464  */
465 
466 #if !defined (__hpux)
467 #define CS_PROCF(x, y) x##_
468 #else
469 #define CS_PROCF(x, y) x
470 #endif
471 
472 /*
473  * Macro used to handle automatic "Fortran string length" arguments
474  * (not used by Code_Saturne calls, but set by many compilers).
475  * Some compilers, like the Fujitsu VPP 5000 compiler in its time, may not
476  * support the variable length lists in mixed C/Fortran calls.
477  */
478 
479 #if defined (__uxpv__) /* Fujitsu VPP 5000 case */
480 #define CS_ARGF_SUPP_CHAINE
481 #else
482 #define CS_ARGF_SUPP_CHAINE , ...
483 #endif
484 
485 /*=============================================================================
486  * Global variables
487  *============================================================================*/
488 
489 /* Sizes and names associated with datatypes */
490 
491 extern const size_t cs_datatype_size[];
492 extern const char *cs_datatype_name[];
493 
494 /* MPI Datatypes associated with Code_Saturne datatypes */
495 
496 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
497 
498 extern MPI_Datatype cs_datatype_to_mpi[];
499 
500 #endif
501 
502 /* Global variables indicationg task state */
503 
504 extern int cs_glob_n_threads; /* Number of threads */
505 
506 extern int cs_glob_rank_id; /* Rank in main MPI communicator */
507 extern int cs_glob_n_ranks; /* Size of main MPI communicator */
508 
509 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
510 
511 extern MPI_Comm cs_glob_mpi_comm; /* Main MPI intra-communicator */
512 
513 #endif
514 
515 /*=============================================================================
516  * Public functions
517  *============================================================================*/
518 
519 /*----------------------------------------------------------------------------*/
528 /*----------------------------------------------------------------------------*/
529 
530 inline static cs_lnum_t
532  cs_lnum_t m)
533 {
534  return ((i > 0) ? ((i-1)/m+1)*m : 0);
535 }
536 
537 /*----------------------------------------------------------------------------*/
538 
539 #ifdef __cplusplus
540 }
541 #endif /* __cplusplus */
542 
543 #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:427
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:425
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:428
Definition: cs_defs.h:328
cs_real_t cs_real_9_t[9]
Definition: cs_defs.h:313
Definition: cs_defs.h:259
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:531
double val
Definition: cs_defs.h:330