1 /*============================================================================
2  * Base macro and typedef definitions for system portability
3  *============================================================================*/
4 
5 /*
6   This file is part of Code_Saturne, a general-purpose CFD tool.
7 
8   Copyright (C) 1998-2021 EDF S.A.
9 
10   This program is free software; you can redistribute it and/or modify it under
11   the terms of the GNU General Public License as published by the Free Software
12   Foundation; either version 2 of the License, or (at your option) any later
13   version.
14 
15   This program is distributed in the hope that it will be useful, but WITHOUT
16   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18   details.
19 
20   You should have received a copy of the GNU General Public License along with
21   this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22   Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24 
25 /*----------------------------------------------------------------------------*/
26 
27 #include "cs_defs.h"
28 
29 /*----------------------------------------------------------------------------
30  * Standard C library headers
31  *----------------------------------------------------------------------------*/
32 
33 #include <math.h>
34 #include <float.h>
35 
36 /*----------------------------------------------------------------------------*/
37 
38 BEGIN_C_DECLS
39 
40 /*=============================================================================
41  * Additional doxygen documentation
42  *============================================================================*/
43 
44 /* The following block applies to cs_defs.h directly, as it mainly
45    concerns itself with type definitions */
46 
47 /*!
48   \file cs_defs.h
49         Base macro and typedef definitions for system portability.
50 
51   \typedef cs_gnum_t
52            \brief global mesh entity number
53            \details Global mesh-entity numbers are strictly positive
54            (<em>1 to n</em> based) integers, so they are declared as a form of
55            unsigned integer. Such a number is unique across MPI ranks;
56            2 mesh elements on different ranks share the same number
57            <em>if and only if</em> they are local instances of the same global
58            element (such as shared faces or vertices on rank boundaries).
59            A value of 0 is commonly used to mark undefined (or not yet
60            defined) element ids in various pre or post-processing stages.
61 
62   \typedef cs_lnum_t
63            \brief local mesh entity id
64            \details Local mesh-entity ids are signed integers, and be either
65            <em>0 to n-1</em> or <em>1 to n</em> based. When 0-based,
66            the \e id prefix or postfix is preferred
67            for associated variable names, while \e num is preferred when
68            1-based.
69            In C code, using this type is recommended over using simple
70            \c int integers, as 64-bit variants could be used in the future
71            for shared-memory machines with large memory. This type should
72            \b not be used to declare identifiers which are not mesh entities,
73            such as groups, fields, or any other entity whose count does
74            not depend on mesh size, so as not to pollute the readability
75            and comprehensibility of the code.
76 
77   \typedef cs_lnum_2_t
78            \brief vector of 2 local mesh-entity ids
79 
80   \typedef cs_real_t
81            \brief Floating-point value
82 
83   \typedef cs_real_2_t
84            \brief vector of 2 floating-point values
85 
86   \typedef cs_real_3_t
87            \brief vector of 3 floating-point values
88 
89   \typedef cs_real_4_t
90            \brief vector of 4 floating-point values
91 
92   \typedef cs_real_6_t
93            \brief vector of 6 floating-point values
94 
95   \typedef cs_real_33_t
96            \brief 3x3 matrix of floating-point values
97 
98   \typedef cs_real_66_t
99            \brief 6x6 matrix of floating-point values
100 
101   \typedef cs_real_332_t
102            \brief vector of 2 3x3 matrices of floating-point values
103 
104 */
105 
106 /*! \fn inline static cs_lnum_t cs_align(cs_lnum_t i, cs_lnum_t m)
107  *
108  * \brief Given a base index i, return the next index aligned with a size m.
109  *
110  * This index is computed as follows:
111  *
112  * if i > 0:
113  *   ((i - 1) / m + 1) * m
114  * if i = 0:
115  *   0
116  *
117  * \param[in]  i  base index
118  * \param[in]  m  block size to align with
119  *
120  * \return  aligned index
121  */
122 
123 /*============================================================================
124  * Global variables
125  *============================================================================*/
126 
127 /* Empty string */
128 
129 const char   cs_empty_string[] = "";
130 
131 /* Sizes associated with datatypes */
132 
133 const size_t  cs_datatype_size[] = {0,
134                                     1,
135                                     sizeof(float),
136                                     sizeof(double),
137                                     sizeof(unsigned short int),
138                                     4,
139                                     8,
140                                     4,
141                                     8};
142 
143 const char   *cs_datatype_name[] = {"",
144                                     "char",
145                                     "float",
146                                     "double",
147                                     "flag",
148                                     "int32",
149                                     "int64",
150                                     "uint32",
151                                     "uint64"};
152 
153 #if defined(HAVE_MPI)
154 
155 /* MPI Datatypes associated with Code_Saturne datatypes */
156 
157 MPI_Datatype  cs_datatype_to_mpi[] = {MPI_DATATYPE_NULL,
158                                       MPI_CHAR,
159                                       MPI_FLOAT,
160                                       MPI_DOUBLE,
161                                       MPI_UNSIGNED_SHORT,
162                                       MPI_INT,            /* CS_INT32 */
163                                       MPI_LONG_INT,       /* CS_INT64 */
164                                       MPI_UNSIGNED,       /* CS_UINT32 */
165                                       MPI_UNSIGNED_LONG}; /* CS_UINT64 */
166 
167 
168 #endif
169 
170 /* Global variables indicating task state */
171 
172 int  cs_glob_n_threads = 1;     /*<! Number of threads */
173 
174 int  cs_glob_rank_id = -1;      /*!< Rank of process in communicator */
175 int  cs_glob_n_ranks =  1;      /*!< Number of processes in communicator */
176 
177 int  cs_glob_node_rank_id = 0;   /*!< Rank on node in main MPI communicator */
178 int  cs_glob_node_n_ranks = 1;   /*!< Number of ranks on node of main
179                                       MPI communicator */
180 
181 #if defined(HAVE_MPI)
182 
183 MPI_Comm  cs_glob_mpi_comm = MPI_COMM_NULL;   /* Main MPI intra-communicator */
184 
185 #endif
186 
187 /*=============================================================================
188  * Local static variables
189  *============================================================================*/
190 
191 /*=============================================================================
192  * Public functions
193  *============================================================================*/
194 
195 /*----------------------------------------------------------------------------*/
196 
197 END_C_DECLS
198