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-2015 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_INT32, /* 4-byte signed integer values */
262  CS_INT64, /* 8-byte signed integer values */
263  CS_UINT32, /* 4-byte unsigned integer values */
264  CS_UINT64 /* 8-byte unsigned integer values */
265 
266 } cs_datatype_t;
267 
268 /*----------------------------------------------------------------------------
269  * Basic types used by Code_Saturne
270  * They may be modified here to better map to a given library, with the
271  * following constraints:
272  * - cs_lnum_t must be signed
273  * - cs_gnum_t may be signed or unsigned
274  *----------------------------------------------------------------------------*/
275 
276 /* Global integer index or number */
277 
278 #if defined(HAVE_LONG_GNUM)
279  #if (SIZEOF_LONG == 8)
280  typedef unsigned long cs_gnum_t;
281  #elif (SIZEOF_LONG_LONG == 8)
282  typedef unsigned long long cs_gnum_t;
283  #else
284  #error
285  #endif
286 #else
287  typedef unsigned cs_gnum_t;
288 #endif
289 
290 /* Other types */
291 
292 typedef int cs_lnum_t; /* Local integer index or number */
293 typedef double cs_coord_t; /* Real number (coordinate value) */
294 
295 typedef int cs_int_t; /* Fortran integer */
296 typedef double cs_real_t; /* Fortran double precision */
297 typedef char cs_byte_t; /* Byte (untyped memory unit) */
298 
299 /* Vector or array block types */
300 
301 typedef int cs_lnum_2_t[2]; /* Vector of 2 local numbers */
302 
303 typedef double cs_coord_3_t[3]; /* Vector of 3 real (coordinate)
304  values */
305 
306 typedef cs_real_t cs_real_2_t[2]; /* Vector of 2 real values */
307 typedef cs_real_t cs_real_3_t[3]; /* Vector of 3 real values */
308 typedef cs_real_t cs_real_4_t[4]; /* Vector of 4 real values */
309 typedef cs_real_t cs_real_6_t[6]; /* Vector of 6 real values
310  (for symmetric tensor) */
311 typedef cs_real_t cs_real_33_t[3][3]; /* Matrix of 3x3 real values */
312 typedef cs_real_t cs_real_66_t[6][6]; /* Matrix of 6x6 real values */
313 
314 typedef cs_real_t cs_real_34_t[3][4]; /* Matrix of 3x4 real values */
315 
316 typedef cs_real_t cs_real_63_t[6][3]; /* Matrix of 6x3 real values */
317 
318 typedef cs_real_33_t cs_real_332_t[2]; /* vector of 2 3x3 matrices
319  of real values */
320 typedef cs_real_66_t cs_real_662_t[2]; /* vector of 2 6x6 matrices
321  of real values */
322 
323 
324 /* Mappings to MPI datatypes */
325 /*---------------------------*/
326 
327 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
328 
329 # define CS_MPI_INT MPI_INT /* If cs_int_t is an int */
330 # define CS_MPI_REAL MPI_DOUBLE /* If cs_real_t is a double */
331 
332 /* MPI type for cs_gnum_t integer type (depends on configuration) */
333 
334 # if defined(HAVE_LONG_GNUM)
335 # if (SIZEOF_LONG == 8)
336 # define CS_MPI_GNUM MPI_UNSIGNED_LONG
337 # elif (SIZEOF_LONG_LONG == 8)
338 # if defined(MPI_UNSIGNED_LONG_LONG)
339 # define CS_MPI_GNUM MPI_UNSIGNED_LONG_LONG
340 # elif defined(MPI_LONG_LONG)
341 # define CS_MPI_GNUM MPI_LONG_LONG
342 # endif
343 # endif
344 # if !defined(CS_MPI_GNUM)
345 # error
346 # endif
347 # else
348 # define CS_MPI_GNUM MPI_UNSIGNED
349 # endif
350 
351 # define CS_MPI_LNUM MPI_INT /* MPI type for cs_lnum_t type */
352 # define CS_MPI_COORD MPI_DOUBLE /* MPI type for cs_coord_t type */
353 
354 #endif /* defined(HAVE_MPI) && !defined(CS_IGNORE_MPI) */
355 
356 /* Mappings to Code_Saturne datatypes */
357 /*------------------------------------*/
358 
359 #if defined(HAVE_LONG_GNUM)
360 # define CS_GNUM_TYPE CS_UINT64
361 #elif (SIZEOF_INT == 8)
362 # define CS_GNUM_TYPE CS_UINT64
363 #else
364 # define CS_GNUM_TYPE CS_UINT32
365 #endif
366 
367 #if (SIZEOF_INT == 8)
368 # define CS_LNUM_TYPE CS_INT64
369 #else
370 # define CS_LNUM_TYPE CS_INT32
371 #endif
372 
373 #if (SIZEOF_INT == 8)
374 # define CS_INT_TYPE CS_INT64
375 #else
376 # define CS_INT_TYPE CS_INT32
377 #endif
378 
379 #define CS_REAL_TYPE CS_DOUBLE
380 #define CS_COORD_TYPE CS_DOUBLE
381 
382 /* Minimum size for OpenMP loops
383  * (based on initial benchmarking, which will need updates)
384  *-----------------------------------------------------------*/
385 
386 #if defined(__bgq__) && defined(__xlc__)
387 # define CS_THR_MIN 1014
388 #else
389 # define CS_THR_MIN 128
390 #endif
391 
392 /* Cache line size, or multiple thereof */
393 /*--------------------------------------*/
394 
395 #define CS_CL_SIZE 64
396 
397 /*----------------------------------------------------------------------------
398  * Type independent min an max (caution: the argument is evaluated)
399  *----------------------------------------------------------------------------*/
400 
401 #define CS_ABS(a) ((a) < 0 ? -(a) : (a)) /* Absolute value of a */
402 #define CS_MIN(a,b) ((a) < (b) ? (a) : (b)) /* Minimum of a et b */
403 #define CS_MAX(a,b) ((a) > (b) ? (a) : (b)) /* Maximum of a et b */
404 
405 /*----------------------------------------------------------------------------
406  * Variable interlace type:
407  * {x1, y1, z1, x2, y2, z2, ...,xn, yn, zn} if interlaced
408  * {x1, x2, ..., xn, y1, y2, ..., yn, z1, z2, ..., zn} if non interlaced
409  *----------------------------------------------------------------------------*/
410 
411 typedef enum {
412 
413  CS_INTERLACE, /* Variable is interlaced */
414  CS_NO_INTERLACE /* Variable is not interlaced */
415 
417 
418 /*----------------------------------------------------------------------------
419  * Macros for compilation with a C++ compiler
420  *----------------------------------------------------------------------------*/
421 
422 #undef BEGIN_C_DECLS
423 #undef END_C_DECLS
424 
425 #if defined(__cplusplus)
426 # define BEGIN_C_DECLS extern "C" {
427 # define END_C_DECLS }
428 #else
429 # define BEGIN_C_DECLS
430 # define END_C_DECLS
431 #endif
432 
433 /*----------------------------------------------------------------------------
434  * Macros for scoping of examples
435  *----------------------------------------------------------------------------*/
436 
437 #undef BEGIN_EXAMPLE_SCOPE
438 #undef END_EXAMPLE_SCOPE
439 
440 #define BEGIN_EXAMPLE_SCOPE {
441 #define END_EXAMPLE_SCOPE }
442 
443 /*----------------------------------------------------------------------------
444  * Macros for Fortran interoperability
445  *----------------------------------------------------------------------------*/
446 
447 /*
448  * Macro for handling of different symbol names (underscored or not,
449  * lowercase or uppercase) between C and Fortran, for link resolution.
450  */
451 
452 #if !defined (__hpux)
453 #define CS_PROCF(x, y) x##_
454 #else
455 #define CS_PROCF(x, y) x
456 #endif
457 
458 /*
459  * Macro used to handle automatic "Fortran string length" arguments
460  * (not used by Code_Saturne calls, but set by many compilers).
461  * Some compilers, like the Fujitsu VPP 5000 compiler in its time, may not
462  * support the variable length lists in mixed C/Fortran calls.
463  */
464 
465 #if defined (__uxpv__) /* Fujitsu VPP 5000 case */
466 #define CS_ARGF_SUPP_CHAINE
467 #else
468 #define CS_ARGF_SUPP_CHAINE , ...
469 #endif
470 
471 /*=============================================================================
472  * Global variables
473  *============================================================================*/
474 
475 /* Numerical constants */
476 
477 extern const cs_real_t cs_defs_epzero;
478 extern const cs_real_t cs_defs_infinite_r;
479 extern const cs_real_t cs_defs_big_r;
480 extern const cs_real_t cs_defs_pi;
481 
482 /* Sizes and names associated with datatypes */
483 
484 extern const size_t cs_datatype_size[];
485 extern const char *cs_datatype_name[];
486 
487 /* MPI Datatypes associated with Code_Saturne datatypes */
488 
489 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
490 
491 extern MPI_Datatype cs_datatype_to_mpi[];
492 
493 #endif
494 
495 /* Global variables indicationg task state */
496 
497 extern int cs_glob_n_threads; /* Number of threads */
498 
499 extern int cs_glob_rank_id; /* Rank in main MPI communicator */
500 extern int cs_glob_n_ranks; /* Size of main MPI communicator */
501 
502 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
503 
504 extern MPI_Comm cs_glob_mpi_comm; /* Main MPI intra-communicator */
505 
506 #endif
507 
508 /*----------------------------------------------------------------------------*/
509 
510 #ifdef __cplusplus
511 }
512 #endif /* __cplusplus */
513 
514 #endif /* __CS_DEFS_H__ */
MPI_Comm cs_glob_mpi_comm
Definition: cs_defs.c:169
cs_datatype_t
Definition: cs_defs.h:255
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:280
Definition: cs_defs.h:262
const cs_real_t cs_defs_big_r
Definition: cs_defs.c:119
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition: cs_defs.h:306
Definition: cs_defs.h:261
const cs_real_t cs_defs_infinite_r
Definition: cs_defs.c:116
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:309
Definition: cs_defs.h:413
cs_real_t cs_real_34_t[3][4]
Definition: cs_defs.h:314
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:312
char cs_byte_t
Definition: cs_defs.h:297
cs_interlace_t
Definition: cs_defs.h:411
int cs_int_t
Fortran-compatible integer.
Definition: cs_defs.h:295
Definition: cs_defs.h:257
int cs_glob_n_ranks
Definition: cs_defs.c:165
cs_real_66_t cs_real_662_t[2]
Definition: cs_defs.h:320
Definition: cs_defs.h:264
double cs_coord_t
Definition: cs_defs.h:293
cs_real_t cs_real_4_t[4]
vector of 4 floating-point values
Definition: cs_defs.h:308
Definition: cs_defs.h:414
Definition: cs_defs.h:259
int cs_glob_n_threads
Definition: cs_defs.c:162
MPI_Datatype cs_datatype_to_mpi[]
Definition: cs_defs.c:148
cs_real_33_t cs_real_332_t[2]
vector of 2 3x3 matrices of floating-point values
Definition: cs_defs.h:318
int cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:301
Definition: cs_defs.h:263
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:307
const cs_real_t cs_defs_pi
Definition: cs_defs.c:122
const size_t cs_datatype_size[]
Definition: cs_defs.c:126
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:292
double cs_coord_3_t[3]
Definition: cs_defs.h:303
Definition: cs_defs.h:258
double cs_real_t
Definition: cs_defs.h:296
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:311
const char * cs_datatype_name[]
Definition: cs_defs.c:135
cs_real_t cs_real_63_t[6][3]
Definition: cs_defs.h:316
Definition: cs_defs.h:260
int cs_glob_rank_id
Definition: cs_defs.c:164
const cs_real_t cs_defs_epzero
Definition: cs_defs.c:113