Properly finalize MPI on mdrun -version. Fixes #1313
[gromacs.git] / include / types / simple.h
blobc6df9c601600893dd77c6a7f340443fa22ee54a8
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
39 #ifndef _simple_h
40 #define _simple_h
42 /* Dont remove this instance of HAVE_CONFIG_H!!!
44 * We dont _require_ config.h here, but IF one is
45 * available it might contain valuable information about simple types
46 * that helps us automate things better and avoid bailing out.
48 * Note that this does not have to be the gromacs config.h - several
49 * package setups define these simple types.
51 #ifdef HAVE_CONFIG_H
52 # include <config.h>
53 #endif
55 /* Information about integer data type sizes */
56 #include <limits.h>
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 #if 0
63 #endif
66 #define XX 0 /* Defines for indexing in */
67 #define YY 1 /* vectors */
68 #define ZZ 2
69 #define DIM 3 /* Dimension of vectors */
70 #define XXXX 0 /* defines to index matrices */
71 #define XXYY 1
72 #define XXZZ 2
73 #define YYXX 3
74 #define YYYY 4
75 #define YYZZ 5
76 #define ZZXX 6
77 #define ZZYY 7
78 #define ZZZZ 8
80 /* There is no standard size for 'bool' in C++, so when
81 * we previously defined it to int for C code the data types
82 * (and structs) would have different size depending on your compiler,
83 * both at gromacs build time and when you use the library.
84 * The only way around this is to NOT assume anything about the C++ type,
85 * so we cannot use the name 'bool' in our C code anymore.
88 typedef int gmx_bool;
90 #ifndef FALSE
91 # define FALSE 0
92 #endif
93 #ifndef TRUE
94 # define TRUE 1
95 #endif
96 #define BOOL_NR 2
99 typedef int atom_id; /* To indicate an atoms id */
100 #define NO_ATID (atom_id)(~0) /* Use this to indicate invalid atid */
102 /*! \brief Double precision accuracy */
103 #define GMX_DOUBLE_EPS 1.11022302E-16
105 /*! \brief Maximum double precision value - reduced 1 unit in last digit for MSVC */
106 #define GMX_DOUBLE_MAX 1.79769312E+308
108 /*! \brief Minimum double precision value */
109 #define GMX_DOUBLE_MIN 2.22507386E-308
111 /*! \brief Single precision accuracy */
112 #define GMX_FLOAT_EPS 5.96046448E-08
114 /*! \brief Maximum single precision value - reduced 1 unit in last digit for MSVC */
115 #define GMX_FLOAT_MAX 3.40282346E+38
117 /*! \brief Minimum single precision value */
118 #define GMX_FLOAT_MIN 1.17549435E-38
121 /* Check whether we already have a real type! */
122 #ifdef GMX_DOUBLE
124 #ifndef HAVE_REAL
125 typedef double real;
126 #define HAVE_REAL
127 #endif
129 #define GMX_MPI_REAL MPI_DOUBLE
130 #define GMX_REAL_EPS GMX_DOUBLE_EPS
131 #define GMX_REAL_MIN GMX_DOUBLE_MIN
132 #define GMX_REAL_MAX GMX_DOUBLE_MAX
133 #define gmx_real_fullprecision_pfmt "%21.14e"
134 #else
136 #ifndef HAVE_REAL
137 typedef float real;
138 #define HAVE_REAL
139 #endif
141 #define GMX_MPI_REAL MPI_FLOAT
142 #define GMX_REAL_EPS GMX_FLOAT_EPS
143 #define GMX_REAL_MIN GMX_FLOAT_MIN
144 #define GMX_REAL_MAX GMX_FLOAT_MAX
145 #define gmx_real_fullprecision_pfmt "%14.7e"
146 #endif
148 typedef real rvec[DIM];
150 typedef double dvec[DIM];
152 typedef real matrix[DIM][DIM];
154 typedef real tensor[DIM][DIM];
156 typedef int ivec[DIM];
158 typedef int imatrix[DIM][DIM];
161 /* For the step count type gmx_large_int_t we aim for 8 bytes (64bit),
162 * but we might only be able to get 4 bytes (32bit).
164 * We first try to find a type without reyling on any SIZEOF_XXX defines.
166 * Avoid using "long int" if we can. This type is really dangerous,
167 * since the width frequently depends on compiler options, and they
168 * might not be set correctly when (buggy) Cmake is detecting things.
169 * Instead, start by looking for "long long", and just go down if we
170 * have to (rarely on new systems). /EL 20100810
172 #if ( (defined SIZEOF_LONG_LONG_INT && SIZEOF_LONG_LONG_INT == 8) || (defined LLONG_MAX && LLONG_MAX == 9223372036854775807LL) )
174 /* Long long int is 64 bit */
175 typedef long long int gmx_large_int_t;
176 #define gmx_large_int_fmt "lld"
177 #define gmx_large_int_pfmt "%lld"
178 #define SIZEOF_GMX_LARGE_INT 8
179 #define GMX_LARGE_INT_MAX 9223372036854775807LL
180 #define GMX_LARGE_INT_MIN (-GMX_LARGE_INT_MAX - 1LL)
181 #define GMX_MPI_LARGE_INT MPI_LONG_LONG_INT
183 #elif ( (defined SIZEOF_LONG_INT && SIZEOF_LONG_INT == 8) || (defined LONG_MAX && LONG_MAX == 9223372036854775807L) )
185 /* Long int is 64 bit */
186 typedef long int gmx_large_int_t;
187 #define gmx_large_int_fmt "ld"
188 #define gmx_large_int_pfmt "%ld"
189 #define SIZEOF_GMX_LARGE_INT 8
190 #define GMX_LARGE_INT_MAX 9223372036854775807LL
191 #define GMX_LARGE_INT_MIN (-GMX_LARGE_INT_MAX - 1LL)
192 #define GMX_MPI_LARGE_INT MPI_LONG_INT
194 #elif ( (defined SIZEOF_INT && SIZEOF_INT == 8) || (defined INT_MAX && INT_MAX == 9223372036854775807L) )
196 /* int is 64 bit */
197 typedef int gmx_large_int_t;
198 #define gmx_large_int_fmt "d"
199 #define gmx_large_int_pfmt "%d"
200 #define SIZEOF_GMX_LARGE_INT 8
201 #define GMX_LARGE_INT_MAX 9223372036854775807LL
202 #define GMX_LARGE_INT_MIN (-GMX_LARGE_INT_MAX - 1LL)
203 #define GMX_MPI_LARGE_INT MPI_INT
205 #elif ( (defined INT_MAX && INT_MAX == 2147483647) || (defined SIZEOF_INT && SIZEOF_INT == 4) )
207 /* None of the above worked, try a 32 bit integer */
208 typedef int gmx_large_int_t;
209 #define gmx_large_int_fmt "d"
210 #define gmx_large_int_pfmt "%d"
211 #define SIZEOF_GMX_LARGE_INT 4
212 #define GMX_LARGE_INT_MAX 2147483647
213 #define GMX_LARGE_INT_MIN (-GMX_LARGE_INT_MAX - 1)
214 #define GMX_MPI_LARGE_INT MPI_INT
216 #else
218 #error "Cannot find any 32 or 64 bit integer data type. Please extend the gromacs simple.h file!"
220 #endif
223 #ifndef gmx_inline
224 /* config.h tests for inline definitions and should work on a much wider range
225 * of compilers, but does not work with installed headers. These compiler checks
226 * still enable a real inline keyword for the most common compilers.
229 /* Try to define suitable inline keyword for gmx_inline.
230 * Set it to empty if we cannot find one (and dont complain to the user)
232 #ifndef __cplusplus
234 #ifdef __GNUC__
235 /* GCC */
236 # define gmx_inline __inline__
237 #elif (defined(__INTEL_COMPILER) || defined(__ECC)) && defined(__ia64__)
238 /* ICC */
239 # define gmx_inline __inline__
240 #elif defined(__PATHSCALE__)
241 /* Pathscale */
242 # define gmx_inline __inline__
243 #elif defined(__PGIC__)
244 /* Portland */
245 # define gmx_inline __inline
246 #elif defined _MSC_VER
247 /* MSVC */
248 # define gmx_inline __inline
249 #elif defined(__xlC__)
250 /* IBM */
251 # define gmx_inline __inline
252 #else
253 # define gmx_inline
254 #endif
256 #else
257 /* C++ */
258 # define gmx_inline inline
259 #endif
261 #endif /* ifndef gmx_inline */
264 /* Restrict keywords. Note that this has to be done for C++ too, unless
265 * it was set from the more general checks if we had config.h (gmx internal)
267 #ifndef gmx_restrict
269 #ifdef __GNUC__
270 /* GCC */
271 # define gmx_restrict __restrict__
272 #elif (defined(__INTEL_COMPILER) || defined(__ECC)) && defined(__ia64__)
273 /* ICC */
274 # define gmx_restrict __restrict__
275 #elif defined(__PATHSCALE__)
276 /* Pathscale */
277 # define gmx_restrict __restrict
278 #elif defined(__PGIC__)
279 /* Portland */
280 # define gmx_restrict __restrict
281 #elif defined _MSC_VER
282 /* MSVC */
283 # define gmx_restrict __restrict
284 #elif defined(__xlC__)
285 /* IBM */
286 # define gmx_restrict __restrict
287 #else
288 # define gmx_restrict
289 #endif
291 #endif
293 /* Standard sizes for char* string buffers */
294 #define STRLEN 4096
295 #define BIG_STRLEN 1048576
298 #ifdef __cplusplus
300 #endif
302 #endif