OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
main.cu
1 #define VCLUSTER_PERF_REPORT
2 #define SYNC_BEFORE_TAKE_TIME
3 #define ENABLE_GRID_DIST_ID_PERF_STATS
4 #include "Decomposition/Distribution/BoxDistribution.hpp"
5 #include "util/cuda_launch.hpp"
6 #include "Grid/grid_dist_id.hpp"
7 #include "data_type/aggregate.hpp"
8 #include "timer.hpp"
9 
68 #ifdef __NVCC__
69 
70 constexpr int U = 0;
71 constexpr int V = 1;
72 
73 constexpr int U_next = 2;
74 constexpr int V_next = 3;
75 
76 constexpr int x = 0;
77 constexpr int y = 1;
78 constexpr int z = 2;
79 
81 
82 typedef sgrid_dist_id_gpu<3,float,aggregate<float>,CudaMemory, Dec> SparseGridType;
83 
84 void init(SparseGridType & grid, Box<3,float> & domain)
85 {
87 
88  typedef typename GetAddBlockType<SparseGridType>::type InsertBlockT;
89 
90  for (int i = 0 ; i < 10 ; i++)
91  {
92  timer t;
93  t.start();
94 
95  grid.addPoints([] __device__ (int i, int j, int k)
96  {
97  return true;
98  },
99  [] __device__ (InsertBlockT & data, int i, int j, int k)
100  {
101  data.template get<U>() = 1.0;
102  }
103  );
104 
105 
106  grid.template flush<smax_<U>>(flush_type::FLUSH_ON_DEVICE);
107 
108  t.stop();
109 
110  std::cout << "Time populate: " << t.getwct() << std::endl;
111 
112  timer t2;
113  cudaDeviceSynchronize();
114  t2.start();
115 
116  grid.addPoints([] __device__ (int i, int j, int k)
117  {
118  return true;
119  },
120  [] __device__ (InsertBlockT & data, int i, int j, int k)
121  {
122  data.template get<U>() = 5.0;
123  }
124  );
125 
126 
127  grid.template flush<sRight_<U>>(flush_type::FLUSH_ON_DEVICE);
128 
129  t2.stop();
130 
131  std::cout << "Time populate: " << t2.getwct() << std::endl;
132  }
133 }
134 
135 
136 int main(int argc, char* argv[])
137 {
138  openfpm_init(&argc,&argv);
139 
140  // domain
141  Box<3,float> domain({0.0,0.0,0.0},{2.5,2.5,2.5});
142 
143  // grid size
144  size_t sz[3] = {512,512,512};
145 
146  // Define periodicity of the grid
147  periodicity<3> bc = {PERIODIC,PERIODIC,PERIODIC};
148 
149  // Ghost in grid unit
150  Ghost<3,long int> g(1);
151 
152  // deltaT
153  float deltaT = 0.25;
154 
155  // Diffusion constant for specie U
156  float du = 2*1e-5;
157 
158  // Diffusion constant for specie V
159  float dv = 1*1e-5;
160 
161  // Number of timesteps
162 #ifdef TEST_RUN
163  size_t timeSteps = 300;
164 #else
165  size_t timeSteps = 15000;
166 #endif
167 
168  // K and F (Physical constant in the equation)
169  float K = 0.053;
170  float F = 0.014;
171 
172  SparseGridType grid(sz,domain,g,bc);
173 
174  // spacing of the grid on x and y
175  float spacing[3] = {grid.spacing(0),grid.spacing(1),grid.spacing(2)};
176 
177  init(grid,domain);
178 
179  // sync the ghost
180  grid.deviceToHost<U>();
181  grid.write("final");
182  grid.print_stats();
183 
185 
197 
199  openfpm_finalize();
200 
202 
211 }
212 
213 #else
214 
215 int main(int argc, char* argv[])
216 {
217  return 0;
218 }
219 
220 #endif
221 
double getwct()
Return the elapsed real time.
Definition: timer.hpp:130
Definition: Ghost.hpp:39
It model an expression expr1 * expr2.
Definition: mul.hpp:119
This class decompose a space into sub-sub-domains and distribute them across processors.
void start()
Start the timer.
Definition: timer.hpp:90
OutputIteratorT OffsetT ReductionOpT OuputT init
< [in] The initial value of the reduction
Boundary conditions.
Definition: common.hpp:21
Class for cpu time benchmarking.
Definition: timer.hpp:27
void stop()
Stop the timer.
Definition: timer.hpp:119
[v_transform metafunction]