GraviDy  1.0
Gravitational Dynamics N-body integrator
common.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016
3  *
4  * Cristián Maureira-Fredes <cmaureirafredes@gmail.com>
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * 3. The name of the author may not be used to endorse or promote
20  * products derived from this software without specific prior written
21  * permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  */
36 
37 #ifndef COMMON_HPP
38 #define COMMON_HPP
39 
40 #if defined(_MPI)
41 #include <mpi.h>
42 #endif
43 
44 #include <iomanip>
45 #include <iostream>
46 #include <ctime>
47 #include <cstdio>
48 #include <omp.h>
49 #include <cmath>
50 #include <fstream>
51 #include <sstream>
52 #include <vector>
53 #include <string>
54 
55 
56 #if defined(_MPI)
57 #define MPI_NUM_SLAVES 600
58 #endif
59 
60 #if defined(GPU)
61 
63 #include <cuda_runtime.h>
64 #else
65 
67 typedef struct double4
68 {
69  double x, y, z, w;
70 } double4;
71 
74 typedef struct double3
75 {
76  double x, y, z;
77 } double3;
78 #endif
79 
81 const int G = 1;
82 
85 const int J = 6;
86 
88 const float CORE_MASS = 0.1;
89 
90 const float LAGRANGE_RADII[] = {0.01, 0.05, 0.1, 0.2, 0.5, 0.75};
91 
93 const double E = 1e-4;
94 
96 const double E2 = 1e-8;
97 
100 const float ETA_S = 0.01;
101 
104 const float ETA_N = 0.01;
105 
107 const double D_TIME_MIN = 1.1920928955078125e-07;
108 
110 //const double D_MTIME_MIN = 9.313225746154785e-10;
111 const double D_MTIME_MIN = 7.450580596923828e-09; // 2^-27
112 
114 const double D_TIME_MAX = 0.125;
115 
126 struct Distance
127 {
128  int index;
129  double value;
130  bool operator<(const Distance& a) const
131  {
132  return value < a.value;
133  }
134 };
135 
151 typedef struct Energy
152 {
153  double ini;
154  double end;
155  double tmp;
156  double kinetic;
157  double potential;
158 } Energy;
159 
175 typedef struct options
176 {
178  bool print_all;
180 } options;
181 
192 typedef struct Predictor {
193  double r[3];
194  double v[3];
195  float m;
196 } Predictor;
197 
207 typedef struct Forces {
208  double a[3];
209  double a1[3];
210 } Forces;
211 
253 typedef struct Gtime {
256 
259 
260  double update_ini;
261  double update_end;
262 
265 
266  double grav_ini;
267  double grav_end;
268 
269  double reduce_ini;
270  double reduce_end;
271 
274 
275  float gflops;
277  {
278  integration_ini = 0.0;
279  integration_end = 0.0;
280  prediction_ini = 0.0;
281  prediction_end = 0.0;
282  update_ini = 0.0;
283  update_end = 0.0;
284  correction_ini = 0.0;
285  correction_end = 0.0;
286  grav_ini = 0.0;
287  grav_end = 0.0;
288  reduce_ini = 0.0;
289  reduce_end = 0.0;
290  reduce_forces_ini = 0.0;
291  reduce_forces_end = 0.0;
292  gflops = 0.0;
293  }
294 } Gtime;
295 
307 typedef struct file_data
308 {
309  int id;
310  float m;
311  double r[3];
312  double v[3];
313 } file_data;
314 
315 const double KERNEL_GFLOP = 48e-9; // 60e-9
316 #if defined(GPU)
317 const int BSIZE = 32;
318 const int NJBLOCK = 16;
319 //#define KERNEL_ERROR_DEBUG 1
320 #endif
321 
322 #endif
double grav_end
Member &#39;grav_end&#39; contains the final time of the gravitational interaction.
Definition: common.hpp:267
This structure contains all the energy variables of the system.
Definition: common.hpp:151
const double D_TIME_MAX
Upper boundary for the particles timesteps, .
Definition: common.hpp:114
double w
Definition: common.hpp:69
double z
Definition: common.hpp:69
const double E
Softening parameter.
Definition: common.hpp:93
General structure to read the INPUT file.
Definition: common.hpp:307
double end
Member &#39;end&#39; contains the newest total energy of the system in a certain time.
Definition: common.hpp:154
bool print_all
Member &#39;print_all&#39; contains the boolean value of printing the information of all the particles of the...
Definition: common.hpp:178
double value
Member &#39;value&#39; distance of the particle respect to a reference.
Definition: common.hpp:129
double integration_ini
Member &#39;integration_ini&#39; contains the starting time of the integration.
Definition: common.hpp:254
struct double4 double4
Defining the «double4» structure based on the CUDA definition for the CPU version, which not include the CUDA headers.
Structure to handle the distance of the particles, to be able to identify them while sorted...
Definition: common.hpp:126
double tmp
Member &#39;tmp&#39; contains the previous total total energy of the system.
Definition: common.hpp:155
This structure contains the predicted information of a particle in some moment of the integration...
Definition: common.hpp:192
Options to handling printing options, like printing the snapshot on the screen instead of a file; pri...
Definition: common.hpp:175
double z
Definition: common.hpp:76
const int J
Amount of neighbours to calculate the center of density of the system (Casertano & Hut 1985) ...
Definition: common.hpp:85
const double KERNEL_GFLOP
Definition: common.hpp:315
double reduce_forces_ini
Member &#39;reduce_ini&#39; contains the starting time of the forces reduction on CPU.
Definition: common.hpp:272
double prediction_ini
Member &#39;prediction_ini&#39; contains the starting time of the prediction.
Definition: common.hpp:257
int index
Member &#39;index&#39; identification of the particle.
Definition: common.hpp:128
double grav_ini
Member &#39;grav_ini&#39; contains the starting time of the gravitational interaction.
Definition: common.hpp:266
double ini
Member &#39;ini&#39; contains the initial total energy of the system.
Definition: common.hpp:153
bool print_screen
Member &#39;print_screen&#39; contains the boolean value of printing the snapshot on the screen (true) or a f...
Definition: common.hpp:177
Gtime()
Definition: common.hpp:276
const double D_MTIME_MIN
Lower boundary for the binary timesteps, .
Definition: common.hpp:111
double reduce_end
Member &#39;reduce_end&#39; contains the final time of the forces reduction.
Definition: common.hpp:270
bool print_lagrange
Member &#39;print_lagrange&#39; contains the boolean value for calculating and printing the lagrange radii of...
Definition: common.hpp:179
struct Predictor Predictor
This structure contains different times of the internal integration process.
Definition: common.hpp:253
double y
Definition: common.hpp:69
double reduce_forces_end
Member &#39;reduce_end&#39; contains the final time of the forces reduction on CPU.
Definition: common.hpp:273
int id
Member &#39;id&#39; particle identification.
Definition: common.hpp:309
double prediction_end
Member &#39;prediction_end&#39; contains the final time of the prediction.
Definition: common.hpp:258
const float ETA_S
Initial ETA parameter to calculate the first timestep of all the particles of the system...
Definition: common.hpp:100
struct Forces Forces
struct Gtime Gtime
struct Energy Energy
const int G
Gravitational constant.
Definition: common.hpp:81
Defining the «double3» structure based on the CUDA definition for the CPU version, which not include the CUDA headers.
Definition: common.hpp:74
struct options options
struct file_data file_data
struct double3 double3
Defining the «double3» structure based on the CUDA definition for the CPU version, which not include the CUDA headers.
const double E2
Softening parameter squared.
Definition: common.hpp:96
This structure contains the information of the Forces of a particle in some moment of the integration...
Definition: common.hpp:207
float m
Member &#39;m&#39; particle mass.
Definition: common.hpp:310
float m
Member &#39;m&#39; contains the mass of the particle.
Definition: common.hpp:195
const double D_TIME_MIN
Lower boundary for the particles timesteps, .
Definition: common.hpp:107
double correction_end
Member &#39;correction_end&#39; contains the final time of the correction.
Definition: common.hpp:264
double update_end
Member &#39;update_end&#39; contains the final time of the forces update.
Definition: common.hpp:261
double correction_ini
Member &#39;correction_ini&#39; contains the starting time of the correction.
Definition: common.hpp:263
const float LAGRANGE_RADII[]
Definition: common.hpp:90
Defining the «double4» structure based on the CUDA definition for the CPU version, which not include the CUDA headers.
Definition: common.hpp:67
float gflops
Member &#39;gflops&#39; contains the amount of Giga FLOPs of the force update method.
Definition: common.hpp:275
bool operator<(const Distance &a) const
Definition: common.hpp:130
double reduce_ini
Member &#39;reduce_ini&#39; contains the starting time of the forces reduction.
Definition: common.hpp:269
double update_ini
Member &#39;update_ini&#39; contains the starting time of the forces update.
Definition: common.hpp:260
double kinetic
Member &#39;kinetic&#39; contains the newest kinetic energy of the system in a certain time.
Definition: common.hpp:156
const float ETA_N
Iteration ETA parameter to calculate new timestep of all the active particles of the system...
Definition: common.hpp:104
double integration_end
Member &#39;integration_end&#39; contains the final time of the integration.
Definition: common.hpp:255
double x
Definition: common.hpp:69
const float CORE_MASS
Common mass percentage in the core of a globular cluster.
Definition: common.hpp:88
double potential
Member &#39;potential&#39; contains the newest kinetic energy of the system in a certain time.
Definition: common.hpp:157