OpenFPM  5.2.0
Project that contain the implementation of distributed structures
main.cu
1 
124 #ifdef __NVCC__
125 
126 #include "Vector/vector_dist.hpp"
127 #include "util/cuda_util.hpp"
128 
130 
131 __global__ void print_data_particle_50(float * scalar, float * vector, float * tensor, size_t capacity)
132 {
133  int p = threadIdx.x + blockIdx.x * blockDim.x;
134 
135  if (p == 50)
136  {
137  printf("Scalar particle %d = %f\n",p,scalar[p]);
138 
139  printf("Vector particle %d = %f\n",p,vector[p]);
140  printf("Vector particle %d = %f\n",p,vector[p + capacity]);
141 
142  printf("Tensor particle %d = %f\n",p,tensor[p + (0*2 + 0)*capacity]);
143  printf("Tensor particle %d = %f\n",p,tensor[p + (0*2 + 1)*capacity]);
144  printf("Tensor particle %d = %f\n",p,tensor[p + (1*2 + 0)*capacity]);
145  printf("Tensor particle %d = %f\n",p,tensor[p + (1*2 + 1)*capacity]);
146  }
147 }
148 
150 
151 int main(int argc, char* argv[])
152 {
153  // initialize the library
154  openfpm_init(&argc,&argv);
155 
156  // Here we define our domain a 2D box with internals from 0 to 1.0 for x and y
157  Box<2,float> domain({0.0,0.0},{1.0,1.0});
158 
159  // Here we define the boundary conditions of our problem
160  size_t bc[2]={PERIODIC,PERIODIC};
161 
162  // extended boundary around the domain, and the processor domain
163  Ghost<2,float> g(0.05);
164 
166 
167  auto it = vd.getDomainIterator();
168 
169  while (it.isNext())
170  {
171  auto p = it.get();
172 
173  // we define x, assign a random position between 0.0 and 1.0
174  vd.getPos(p)[0] = (float)rand() / RAND_MAX;
175 
176  // we define y, assign a random position between 0.0 and 1.0
177  vd.getPos(p)[1] = (float)rand() / RAND_MAX;
178 
179  vd.template getProp<0>(p) = vd.getPos(p)[0] + vd.getPos(p)[1];
180 
181  vd.template getProp<1>(p)[0] = vd.getPos(p)[0];
182  vd.template getProp<1>(p)[1] = vd.getPos(p)[1];
183 
184  vd.template getProp<2>(p)[0][0] = vd.getPos(p)[0];
185  vd.template getProp<2>(p)[0][1] = vd.getPos(p)[1];
186  vd.template getProp<2>(p)[1][0] = vd.getPos(p)[0] + vd.getPos(p)[1];
187  vd.template getProp<2>(p)[1][1] = vd.getPos(p)[1] - vd.getPos(p)[0];
188 
189  // next particle
190  ++it;
191  }
192 
193  vd.map();
194 
196 
198 
199  std::cout << "First particle property 0, address: " << &vd.template getProp<0>(0) << std::endl;
200  std::cout << "First particle property 1, address: " << &vd.template getProp<1>(0)[0] << std::endl;
201  std::cout << "First particle property 2, address: " << &vd.template getProp<2>(0)[0][0] << std::endl;
202 
204 
206 
207  std::cout << "Capacity internal vector: " << vd.getPropVector().capacity() << std::endl;
208 
209  std::cout << "First particle property 1 component 0, address: " << &vd.template getProp<1>(0)[0] << std::endl;
210  std::cout << "First particle property 1 component 1, address: " << &vd.template getProp<1>(0)[1] << std::endl;
211 
212  std::cout << "First particle property 2 component 00, address: " << &vd.template getProp<2>(0)[0][0] << std::endl;
213  std::cout << "First particle property 2 component 01, address: " << &vd.template getProp<2>(0)[0][1] << std::endl;
214  std::cout << "First particle property 2 component 10, address: " << &vd.template getProp<2>(0)[1][0] << std::endl;
215  std::cout << "First particle property 2 component 11, address: " << &vd.template getProp<2>(0)[1][1] << std::endl;
216 
217  std::cout << "Second particle property 1 component 0, address: " << &vd.template getProp<1>(1)[0] << std::endl;
218  std::cout << "Second particle property 1 component 1, address: " << &vd.template getProp<1>(1)[1] << std::endl;
219 
220  std::cout << "Second particle property 2 component 00, address: " << &vd.template getProp<2>(1)[0][0] << std::endl;
221  std::cout << "Second particle property 2 component 01, address: " << &vd.template getProp<2>(1)[0][1] << std::endl;
222  std::cout << "Second particle property 2 component 10, address: " << &vd.template getProp<2>(1)[1][0] << std::endl;
223  std::cout << "Second particle property 2 component 11, address: " << &vd.template getProp<2>(1)[1][1] << std::endl;
224 
226 
227  std::cout << std::endl;
228 
230 
231  vd.template hostToDeviceProp<0,1,2>();
232 
233  CUDA_LAUNCH_DIM3(print_data_particle_50,100,1,(float *)vd.getPropVector().template getDeviceBuffer<0>(),
234  (float *)vd.getPropVector().template getDeviceBuffer<1>(),
235  (float *)vd.getPropVector().template getDeviceBuffer<2>(),
236  vd.getPropVector().capacity());
237 
239 
240  openfpm_finalize();
241 }
242 
243 #else
244 
245 int main(int argc, char* argv[])
246 {
247  return 0;
248 }
249 
250 #endif
This class represent an N-dimensional box.
Definition: Box.hpp:60
Definition: Ghost.hpp:40
Distributed vector.