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