5#ifndef OPENFPM_PDATA_SUPPORTBUILDER_CUH
6#define OPENFPM_PDATA_SUPPORTBUILDER_CUH
8#include <Space/Shape/Point.hpp>
9#include <Vector/vector_dist.hpp>
12#include "SupportBuilder.hpp"
15template <
unsigned int dim>
16__device__ __host__
bool nextCell(
size_t (&offset)[dim],
size_t maxOffset) {
20 if ((++offset[i++])/maxOffset)
21 for (
size_t j = 0; j < i; ++j)
29template<
unsigned int dim,
typename T,
typename particles_type,
typename CellList_type,
typename supportSize_type>
30__global__
void gatherSupportSize_gpu(
34 auto cell = cl.getCellGrid(pos);
36 size_t grSize[dim]; cl.getGrid().getSize(grSize);
37 size_t offset[dim];
for (
int i = 0; i < dim; ++i) offset[i] = 0;
44 for (
size_t i = 0; i < dim; ++i)
45 if (key.value(i) < 0 || key.value(i) >= grSize[i])
48 mem_id
id = cl.getGrid().LinId(key);
49 const size_t cellLinId =
static_cast<size_t>(id);
50 const size_t elemsInCell = cl.getNelements(cellLinId);
52 for (
size_t k = 0; k < elemsInCell; ++k) {
53 size_t el = cl.
get(cellLinId, k);
55 if (p_key == el)
continue;
59 }
while (nextCell<dim>(offset, 2+1));
61 supportSize.get(p_key) = N;
64template<
unsigned int dim,
typename T,
typename particles_type,
typename CellList_type,
typename supportKey_type>
65__global__
void assembleSupport_gpu(
particles_type particles, CellList_type cl, supportKey_type supportSize, supportKey_type supportKeys1D, T rCut) {
68 auto cell = cl.getCellGrid(pos);
70 size_t supportKeysSize = supportSize.get(p_key+1)-supportSize.get(p_key);
71 size_t* supportKeys = &((
size_t*)supportKeys1D.getPointer())[supportSize.get(p_key)];
73 size_t grSize[dim]; cl.getGrid().getSize(grSize);
74 size_t offset[dim];
for (
int i = 0; i < dim; ++i) offset[i] = 0;
81 for (
size_t i = 0; i < dim; ++i)
82 if (key.value(i) < 0 || key.value(i) >= grSize[i])
85 mem_id
id = cl.getGrid().LinId(key);
86 const size_t cellLinId =
static_cast<size_t>(id);
87 const size_t elemsInCell = cl.getNelements(cellLinId);
89 for (
size_t k = 0; k < elemsInCell; ++k) {
90 size_t el = cl.
get(cellLinId, k);
92 if (p_key == el)
continue;
96 }
while (nextCell<dim>(offset, 2+1));
101template<
typename vector_type>
106 typename vector_type::stype rCut;
110 : domain(domain), rCut(rCut) {}
113 size_t& maxSupport,
size_t& supportKeysTotalN)
115 domain.hostToDevicePos();
116 auto it = domain.getDomainIteratorGPU(512);
119 auto NN = domain.template getCellList<params>(rCut);
124 kerOffsets.resize(N+1);
125 gatherSupportSize_gpu<vector_type::dims><<<it.wthr,it.thr>>>(domain.toKernel(), NN.toKernel(), kerOffsets.toKernel(), rCut);
126 kerOffsets.template deviceToHost();
128 supportKeysTotalN = 0; maxSupport = 0;
130 for (
size_t i = 0; i < N; ++i) {
131 size_t sz = kerOffsets.get(i);
132 kerOffsets.get(i) = supportKeysTotalN;
133 supportKeysTotalN += sz;
134 if (maxSupport < sz) maxSupport = sz;
136 kerOffsets.get(N) = supportKeysTotalN;
138 supportKeys1D.resize(supportKeysTotalN);
139 kerOffsets.template hostToDevice();
140 assembleSupport_gpu<vector_type::dims><<<it.wthr,it.thr>>>(domain.toKernel(), NN.toKernel(), kerOffsets.toKernel(), supportKeys1D.toKernel(), rCut);
141 supportKeys1D.template deviceToHost();
This class implement the point shape in an N-dimensional space.
__device__ __host__ T distance(const Point< dim, T > &q) const
It calculate the distance between 2 points.
grid_key_dx is the key to access any element in the grid
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
__device__ __host__ index_type get(index_type i) const
Get the i index.
Implementation of 1-D std::vector like structure.
auto getPos(vect_dist_key_dx vec_key) -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
auto getPosOrig(vect_dist_key_dx vec_key) const -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.