GADGET-4
dtypes.h
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#ifndef DTYPES_H
13#define DTYPES_H
14
15#include <stdint.h>
16#include <cstddef>
17#ifdef EXPLICIT_VECTORIZATION
18#include "../vectorclass/vectorclass.h"
19#endif
20
21#if !defined(POSITIONS_IN_32BIT) && !defined(POSITIONS_IN_64BIT) && !defined(POSITIONS_IN_128BIT)
22/* ok, nothing has been chosen as part of the configuration, then use a default value */
23#ifndef DOUBLEPRECISION
24#define POSITIONS_IN_32BIT
25#else
26#define POSITIONS_IN_64BIT
27#endif
28#endif
29
30/* Exactly one of the symbols POSITIONS_IN_32BIT, POSITIONS_IN_64BIT or POSITIONS_IN_128BIT need to be fined, otherwise
31 * it is desirable to get a compile time error
32 */
33
34#ifdef POSITIONS_IN_32BIT
35typedef uint32_t MyIntPosType;
36typedef int32_t MySignedIntPosType;
37#define BITS_FOR_POSITIONS 32
38#ifdef EXPLICIT_VECTORIZATION
39typedef Vec4ui Vec4MyIntPosType;
40typedef Vec4i Vec4MySignedIntPosType;
41#endif
42#endif
43
44#ifdef POSITIONS_IN_64BIT
45typedef uint64_t MyIntPosType;
46typedef int64_t MySignedIntPosType;
47#define BITS_FOR_POSITIONS 64
48#ifdef EXPLICIT_VECTORIZATION
49typedef Vec4uq Vec4MyIntPosType;
50typedef Vec4q Vec4MySignedIntPosType;
51#endif
52#endif
53
54#ifdef POSITIONS_IN_128BIT
55typedef uint128_t MyIntPosType;
56typedef int128_t MySignedIntPosType;
57#define BITS_FOR_POSITIONS 128
58#ifdef EXPLICIT_VECTORIZATION
59#error "EXPLICIT_VECTORIZATION and POSITIONS_IN_128BIT do not work together"
60#endif
61#endif
62
63#if !defined(IDS_32BIT) && !defined(IDS_48BIT) && !defined(IDS_64BIT)
64#define IDS_32BIT
65#endif
66
67#ifdef IDS_32BIT
68typedef unsigned int MyIDType;
69#else
70typedef unsigned long long MyIDType;
71#endif
72
73#ifdef FOF_ALLOW_HUGE_GROUPLENGTH
74typedef long long MyLenType;
75#else
76typedef int MyLenType;
77#endif
78
79#ifdef USE_SINGLEPRECISION_INTERNALLY
80typedef float MyReal;
81#else
82typedef double MyReal;
83#endif
84
85#ifndef DOUBLEPRECISION /* default is single-precision */
86typedef float MyFloat;
87typedef float MyDouble;
88typedef float MyNgbTreeFloat;
89#define MPI_MYFLOAT MPI_FLOAT
90#define MPI_MYDOUBLE MPI_FLOAT
91#define H5T_NATIVE_MYFLOAT H5T_NATIVE_FLOAT
92#define H5T_NATIVE_MYDOUBLE H5T_NATIVE_FLOAT
93#else
94#if(DOUBLEPRECISION == 2) /* mixed precision */
95typedef float MyFloat;
96typedef double MyDouble;
97typedef float MyNgbTreeFloat;
98#define MPI_MYFLOAT MPI_FLOAT
99#define MPI_MYDOUBLE MPI_DOUBLE
100#define H5T_NATIVE_MYFLOAT H5T_NATIVE_FLOAT
101#define H5T_NATIVE_MYDOUBLE H5T_NATIVE_DOUBLE
102#else /* everything double-precision */
103typedef double MyFloat;
104typedef double MyDouble;
105typedef double MyNgbTreeFloat;
106#define MPI_MYFLOAT MPI_DOUBLE
107#define MPI_MYDOUBLE MPI_DOUBLE
108#define H5T_NATIVE_MYFLOAT H5T_NATIVE_DOUBLE
109#define H5T_NATIVE_MYDOUBLE H5T_NATIVE_DOUBLE
110#endif
111#endif
112
113#ifdef ENLARGE_DYNAMIC_RANGE_IN_TIME
114typedef long long integertime;
115#define TIMEBINS 60
116#define TIMEBASE \
117 (((long long)1) << TIMEBINS) /* The simulated timespan is mapped onto the integer interval [0,TIMESPAN], \
118 * where TIMESPAN needs to be a power of 2. */
119#else
120typedef int integertime;
121#define TIMEBINS 29
122#define TIMEBASE (1 << TIMEBINS)
123#endif
124
125#ifndef NUMBER_OF_MPI_LISTENERS_PER_NODE
126#define NUMBER_OF_MPI_LISTENERS_PER_NODE 1
127#endif
128
129#ifndef MAX_NUMBER_OF_RANKS_WITH_SHARED_MEMORY
130#define MAX_NUMBER_OF_RANKS_WITH_SHARED_MEMORY 64
131#endif
132
133#if MAX_NUMBER_OF_RANKS_WITH_SHARED_MEMORY <= 32
134typedef uint32_t node_bit_field;
135#elif MAX_NUMBER_OF_RANKS_WITH_SHARED_MEMORY <= 64
136typedef uint64_t node_bit_field;
137#else
138#error "unsupported MAX_NUMBER_OF_RANKS_WITH_SHARED_MEMORY setting"
139#endif
140
142{
143 char n[3];
144
145 offset_tuple() {} /* constructor */
146
147 offset_tuple(const char x) /* constructor */
148 {
149 n[0] = x;
150 n[1] = x;
151 n[2] = x;
152 }
153
154 offset_tuple(const char x, const char y, const char z) /* constructor */
155 {
156 n[0] = x;
157 n[1] = y;
158 n[2] = z;
159 }
160};
161
163{
164 int task;
165 int index;
166};
167
168inline bool operator==(const location &left, const location &right) { return left.task == right.task && left.index == right.index; }
169
170inline bool operator!=(const location &left, const location &right) { return left.task != right.task || left.index != right.index; }
171
172inline bool operator<(const location &left, const location &right)
173{
174 if(left.task < right.task)
175 return true;
176 else if(left.task == right.task)
177 {
178 if(left.index < right.index)
179 return true;
180 else
181 return false;
182 }
183 else
184 return false;
185}
186
188{
190 long long FirstHalo;
191 long long TreeID;
192};
193
195{
197 long long ParticleFirst;
198 long long TreeID;
199};
200
202{
203 double Time;
204 double Redshift;
205};
206
208{
209 public:
210 MyIntPosType hs, is, ls; /* 'hs'-high significance, 'is'-intermediate, 'ls'-low significance bits */
211};
212
213inline bool operator>=(const peanokey &a, const peanokey &b)
214{
215 if(a.hs < b.hs)
216 return false;
217 else if(a.hs > b.hs)
218 return true;
219 else if(a.is < b.is)
220 return false;
221 else if(a.is > b.is)
222 return true;
223 else if(a.ls < b.ls)
224 return false;
225 else
226 return true;
227}
228
229inline bool operator<(const peanokey &a, const peanokey &b)
230{
231 if(a.hs < b.hs)
232 return true;
233 else if(a.hs > b.hs)
234 return false;
235 else if(a.is < b.is)
236 return true;
237 else if(a.is > b.is)
238 return false;
239 else if(a.ls < b.ls)
240 return true;
241 else
242 return false;
243}
244
245inline peanokey operator+(const peanokey &a, const peanokey &b)
246{
247 peanokey c;
248
249 c.ls = a.ls + b.ls;
250 c.is = a.is + b.is;
251 c.hs = a.hs + b.hs;
252
253 if(c.is < a.is || c.is < b.is) /* overflow has occurred */
254 {
255 c.hs += 1;
256 }
257
258 if(c.ls < a.ls || c.ls < b.ls) /* overflow has occurred */
259 {
260 c.is += 1;
261 if(c.is == 0) /* overflown again */
262 c.hs += 1;
263 }
264
265 /* note: for hs we don't check for overflow explicitly as this would not be represented in the type anyhow */
266
267 return c;
268}
269
270inline peanokey get_peanokey_offset(unsigned int j, int bits) /* this returns the peanokey for which j << bits */
271{
272 peanokey key = {j, j, j};
273
274 if(bits < BITS_FOR_POSITIONS)
275 key.ls <<= bits;
276 else
277 key.ls = 0;
278
279 int is_bits = bits - BITS_FOR_POSITIONS;
280
281 if(is_bits <= -BITS_FOR_POSITIONS)
282 key.is = 0;
283 else if(is_bits <= 0)
284 key.is >>= -is_bits;
285 else if(is_bits < BITS_FOR_POSITIONS)
286 key.is <<= is_bits;
287 else
288 key.is = 0;
289
290 int hs_bits = bits - 2 * BITS_FOR_POSITIONS;
291
292 if(hs_bits <= -BITS_FOR_POSITIONS)
293 key.hs = 0;
294 else if(hs_bits <= 0)
295 key.hs >>= -hs_bits;
296 else if(hs_bits < BITS_FOR_POSITIONS)
297 key.hs <<= hs_bits;
298 else
299 key.hs = 0;
300
301 return key;
302}
303
305{
310
312{
326
328{
329 int Task;
330 int Index;
331};
332
334{
337
340 double Ewaldcount;
345 size_t ItemSize;
346
350
355};
356
357#ifdef LONG_X_BITS
358#define LONG_X (1 << (LONG_X_BITS))
359#define MAX_LONG_X_BITS LONG_X_BITS
360#else
361#define LONG_X 1
362#define MAX_LONG_X_BITS 0
363#endif
364
365#ifdef LONG_Y_BITS
366#define LONG_Y (1 << (LONG_Y_BITS))
367#define MAX_LONG_Y_BITS LONG_Y_BITS
368#else
369#define LONG_Y 1
370#define MAX_LONG_Y_BITS 0
371#endif
372
373#ifdef LONG_Z_BITS
374#define LONG_Z (1 << (LONG_Z_BITS))
375#define MAX_LONG_Z_BITS LONG_Z_BITS
376#else
377#define LONG_Z 1
378#define MAX_LONG_Z_BITS 0
379#endif
380
381#define LONG_BITS_MAX(A, B) (((A) > (B)) ? (A) : (B))
382
383#define LEVEL_ALWAYS_OPEN LONG_BITS_MAX(MAX_LONG_X_BITS, LONG_BITS_MAX(MAX_LONG_Y_BITS, MAX_LONG_Z_BITS))
384
385#ifdef GRAVITY_TALLBOX
386
387#if(GRAVITY_TALLBOX == 0)
388#define DBX 2
389#define DBX_EXTRA 6
390#define BOXX (1.0 / LONG_Y)
391#define BOXY (1.0 / LONG_Z)
392#else
393#define DBX 1
394#define DBX_EXTRA 0
395#endif
396
397#if(GRAVITY_TALLBOX == 1)
398#define DBY 2
399#define DBY_EXTRA 6
400#define BOXX (1.0 / LONG_X)
401#define BOXY (1.0 / LONG_Z)
402#else
403#define DBY 1
404#define DBY_EXTRA 0
405#endif
406
407#if(GRAVITY_TALLBOX == 2)
408#define DBZ 2
409#define DBZ_EXTRA 6
410#define BOXX (1.0 / LONG_X)
411#define BOXY (1.0 / LONG_Y)
412#else
413#define DBZ 1
414#define DBZ_EXTRA 0
415#endif
416
417#else
418
419#define DBX 1
420#define DBY 1
421#define DBZ 1
422#define DBX_EXTRA 0
423#define DBY_EXTRA 0
424#define DBZ_EXTRA 0
425#endif
426
427#endif
MyIntPosType hs
Definition: dtypes.h:210
MyIntPosType is
Definition: dtypes.h:210
MyIntPosType ls
Definition: dtypes.h:210
float MyDouble
Definition: dtypes.h:87
peanokey get_peanokey_offset(unsigned int j, int bits)
Definition: dtypes.h:270
bool operator<(const location &left, const location &right)
Definition: dtypes.h:172
float MyFloat
Definition: dtypes.h:86
uint64_t node_bit_field
Definition: dtypes.h:136
mysnaptype
Definition: dtypes.h:305
@ MOST_BOUND_PARTICLE_SNAPHOT
Definition: dtypes.h:307
@ NORMAL_SNAPSHOT
Definition: dtypes.h:306
@ MOST_BOUND_PARTICLE_SNAPHOT_REORDERED
Definition: dtypes.h:308
uint32_t MyIntPosType
Definition: dtypes.h:35
int MyLenType
Definition: dtypes.h:76
float MyNgbTreeFloat
Definition: dtypes.h:88
int32_t MySignedIntPosType
Definition: dtypes.h:36
bool operator>=(const peanokey &a, const peanokey &b)
Definition: dtypes.h:213
peanokey operator+(const peanokey &a, const peanokey &b)
Definition: dtypes.h:245
double MyReal
Definition: dtypes.h:82
int integertime
Definition: dtypes.h:120
bool operator!=(const location &left, const location &right)
Definition: dtypes.h:170
restart_options
Definition: dtypes.h:312
@ RST_CONVERTSNAP
Definition: dtypes.h:318
@ RST_LCREARRANGE
Definition: dtypes.h:323
@ RST_STARTFROMSNAP
Definition: dtypes.h:315
@ RST_POWERSPEC
Definition: dtypes.h:317
@ RST_CREATEICS
Definition: dtypes.h:319
@ RST_MAKETREES
Definition: dtypes.h:321
@ RST_IOBANDWIDTH
Definition: dtypes.h:322
@ RST_FOF
Definition: dtypes.h:316
@ RST_SNPREARRANGE
Definition: dtypes.h:324
@ RST_BEGIN
Definition: dtypes.h:313
@ RST_RESUME
Definition: dtypes.h:314
@ RST_CALCDESC
Definition: dtypes.h:320
#define BITS_FOR_POSITIONS
Definition: dtypes.h:37
bool operator==(const location &left, const location &right)
Definition: dtypes.h:168
unsigned int MyIDType
Definition: dtypes.h:68
long long TreeID
Definition: dtypes.h:191
long long FirstHalo
Definition: dtypes.h:190
int task
Definition: dtypes.h:164
int index
Definition: dtypes.h:165
char n[3]
Definition: dtypes.h:143
offset_tuple(const char x)
Definition: dtypes.h:147
offset_tuple()
Definition: dtypes.h:145
offset_tuple(const char x, const char y, const char z)
Definition: dtypes.h:154
long long ParticleFirst
Definition: dtypes.h:197
long long TreeID
Definition: dtypes.h:198
int ParticleCount
Definition: dtypes.h:196
int * Shmranklist
Definition: dtypes.h:353
size_t ItemSize
Definition: dtypes.h:345
int NexportNodes
Definition: dtypes.h:336
int * Exportflag
Definition: dtypes.h:354
size_t InitialSpace
Definition: dtypes.h:344
size_t ExportSpace
Definition: dtypes.h:343
int * Node_CostCount
Definition: dtypes.h:349
data_partlist * PartList
Definition: dtypes.h:351
int FirstExec
Definition: dtypes.h:341
double Interactions
Definition: dtypes.h:338
int * TreePoints_CostCount
Definition: dtypes.h:348
int * P_CostCount
Definition: dtypes.h:347
double Ewaldcount
Definition: dtypes.h:340
int Nexport
Definition: dtypes.h:335
int * Ngblist
Definition: dtypes.h:352
double Redshift
Definition: dtypes.h:204
double Time
Definition: dtypes.h:203