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