8#ifndef OPENFPM_DATA_SRC_UTIL_COMPUTE_OPTIMAL_DEVICE_GRID_HPP_
9#define OPENFPM_DATA_SRC_UTIL_COMPUTE_OPTIMAL_DEVICE_GRID_HPP_
36template<
unsigned int dim>
39 size_t max_block_size,
40 size_t min_block_size)
43 if (dim == 0) {return ;}
51 std::vector<unsigned long int> x;
52 openfpm::math::getFactorization(sz[0],x);
57 while(jx < x.size() && x[jx] == 2 && tot_block < max_block_size)
59 if (tot_block * 2 > max_block_size)
69 if (tot_block * 2 > max_block_size)
75 for (; jx < x.size() ; jx++)
84 for (
size_t k = 2 ; k < dim ; k++)
93 std::vector<unsigned long int> y;
99 openfpm::math::getFactorization(sz[1],y);
101 while(jy < y.size() && y[jy] == 2 && tot_block < max_block_size)
103 if (tot_block * 2 > max_block_size)
113 if (tot_block * 2 > max_block_size)
118 for (; jx < x.size() ; jx++)
122 for (; jy < y.size() ; jy++)
126 for (
size_t k = 2 ; k < dim ; k++)
134 std::vector<unsigned long int> z;
141 openfpm::math::getFactorization(sz[2],z);
143 while(jz < z.size() && z[jz] == 2 && tot_block < max_block_size)
145 if (tot_block * 2 > max_block_size)
155 if (tot_block * 2 > max_block_size)
158 for (; jx < x.size() ; jx++)
162 for (; jy < y.size() ; jy++)
166 for (; jz < z.size() ; jz++)
169 for (
size_t k = 3 ; k < dim ; k++)
177 if (tot_block >= min_block_size)
183 for (
size_t k = jx ; k < x.size() ; k++)
187 for (
size_t k = jy ; k < y.size() ; k++)
191 for (
size_t k = jz ; k < z.size() ; k++)
194 std::vector<unsigned long int> * ptr_xyz[3];
204 while (tot_block < min_block_size && (jx < x.size() || jy < y.size() || jz < z.size() ) )
206 size_t best_fact = std::numeric_limits<size_t>::max();
209 for (
size_t k = 0 ; k < dim ; k++)
211 if (*jj[k] < ptr_xyz[k]->size() && ptr_xyz[k]->
operator[](*jj[k]) < best_fact )
213 best_fact = ptr_xyz[k]->operator[](*jj[k]);
219 if (tot_block * best_fact > max_block_size)
227 else if (k_best == 1)
233 else if (k_best == 2)
239 tot_block *= best_fact;
dim3_ grids
number of grid for the kernel execution
dim3_ threads
number of treads in each block
unsigned int z
size in z dimension
unsigned int x
size in x dimension
unsigned int y
size in y dimension