src/base/cs_defs.h Source File

| programmer's documentation

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups 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-2013 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 cs_lnum_t 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
313 /* Mappings to MPI datatypes */
314 /*---------------------------*/
315
316 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
317
318 # define CS_MPI_INT MPI_INT /* If cs_int_t is an int */
319 # define CS_MPI_REAL MPI_DOUBLE /* If cs_real_t is a double */
320
321 /* MPI type for cs_gnum_t integer type (depends on configuration) */
322
323 # if defined(HAVE_LONG_GNUM)
324 # if (SIZEOF_LONG == 8)
325 # define CS_MPI_GNUM MPI_UNSIGNED_LONG
326 # elif (SIZEOF_LONG_LONG == 8)
327 # if defined(MPI_UNSIGNED_LONG_LONG)
328 # define CS_MPI_GNUM MPI_UNSIGNED_LONG_LONG
329 # elif defined(MPI_LONG_LONG)
330 # define CS_MPI_GNUM MPI_LONG_LONG
331 # endif
332 # endif
333 # if !defined(CS_MPI_GNUM)
334 # error
335 # endif
336 # else
337 # define CS_MPI_GNUM MPI_UNSIGNED
338 # endif
339
340 # define CS_MPI_LNUM MPI_INT /* MPI type for cs_lnum_t type */
341 # define CS_MPI_COORD MPI_DOUBLE /* MPI type for cs_coord_t type */
342
343 #endif /* defined(HAVE_MPI) && !defined(CS_IGNORE_MPI) */
344
345 /* Mappings to Code_Saturne datatypes */
346 /*------------------------------------*/
347
348 #if defined(HAVE_LONG_GNUM)
349 # define CS_GNUM_TYPE CS_UINT64
350 #elif (SIZEOF_INT == 8)
351 # define CS_GNUM_TYPE CS_UINT64
352 #else
353 # define CS_GNUM_TYPE CS_UINT32
354 #endif
355
356 #if (SIZEOF_INT == 8)
357 # define CS_LNUM_TYPE CS_INT64
358 #else
359 # define CS_LNUM_TYPE CS_INT32
360 #endif
361
362 #if (SIZEOF_INT == 8)
363 # define CS_INT_TYPE CS_INT64
364 #else
365 # define CS_INT_TYPE CS_INT32
366 #endif
367
368 #define CS_REAL_TYPE CS_DOUBLE
369 #define CS_COORD_TYPE CS_DOUBLE
370
371 /*----------------------------------------------------------------------------
372 * Type independent min an max (caution: the argument is evaluated)
373 *----------------------------------------------------------------------------*/
374
375 #define CS_ABS(a) ((a) < 0 ? -(a) : (a)) /* Absolute value of a */
376 #define CS_MIN(a,b) ((a) < (b) ? (a) : (b)) /* Minimum of a et b */
377 #define CS_MAX(a,b) ((a) > (b) ? (a) : (b)) /* Maximum of a et b */
378
379 /*----------------------------------------------------------------------------
380 * Variable interlace type:
381 * {x1, y1, z1, x2, y2, z2, ...,xn, yn, zn} if interlaced
382 * {x1, x2, ..., xn, y1, y2, ..., yn, z1, z2, ..., zn} if non interlaced
383 *----------------------------------------------------------------------------*/
384
385 typedef enum {
386
387 CS_INTERLACE, /* Variable is interlaced */
388 CS_NO_INTERLACE /* Variable is not interlaced */
389
390 } cs_interlace_t;
391
392 /*----------------------------------------------------------------------------
393 * Macros for compilation with a C++ compiler
394 *----------------------------------------------------------------------------*/
395
396 #undef BEGIN_C_DECLS
397 #undef END_C_DECLS
398
399 #if defined(__cplusplus)
400 # define BEGIN_C_DECLS extern "C" {
401 # define END_C_DECLS }
402 #else
403 # define BEGIN_C_DECLS
404 # define END_C_DECLS
405 #endif
406
407 /*----------------------------------------------------------------------------
408 * Macros for Fortran interoperability
409 *----------------------------------------------------------------------------*/
410
411 /*
412 * Macro for handling of different symbol names (underscored or not,
413 * lowercase or uppercase) between C and Fortran, for link resolution.
414 */
415
416 #if !defined (__hpux)
417 #define CS_PROCF(x, y) x##_
418 #else
419 #define CS_PROCF(x, y) x
420 #endif
421
422 /*
423 * Macro used to handle automatic "Fortran string length" arguments
424 * (not used by Code_Saturne calls, but set by many compilers).
425 * Some compilers, like the Fujitsu VPP 5000 compiler in its time, may not
426 * support the variable length lists in mixed C/Fortran calls.
427 */
428
429 #if defined (__uxpv__) /* Fujitsu VPP 5000 case */
430 #define CS_ARGF_SUPP_CHAINE
431 #else
432 #define CS_ARGF_SUPP_CHAINE , ...
433 #endif
434
435 /*=============================================================================
436 * Global variables
437 *============================================================================*/
438
439 /* Sizes and names associated with datatypes */
440
441 extern const size_t cs_datatype_size[];
442 extern const char *cs_datatype_name[];
443
444 /* MPI Datatypes associated with Code_Saturne datatypes */
445
446 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
447
448 extern MPI_Datatype cs_datatype_to_mpi[];
449
450 #endif
451
452 /* Global variables indicationg task state */
453
454 extern int cs_glob_n_threads; /* Number of threads */
455
456 extern int cs_glob_rank_id; /* Rank in main MPI communicator */
457 extern int cs_glob_n_ranks; /* Size of main MPI communicator */
458
459 #if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
460
461 extern MPI_Comm cs_glob_mpi_comm; /* Main MPI intra-communicator */
462
463 #endif
464
465 /*----------------------------------------------------------------------------*/
466
467 #ifdef __cplusplus
468 }
469 #endif /* __cplusplus */
470
471 #endif /* __CS_DEFS_H__ */