OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
CellList_util.hpp
1 /*
2  * CellList_util.hpp
3  *
4  * Created on: Oct 20, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLIST_UTIL_HPP_
9 #define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLIST_UTIL_HPP_
10 
11 #define CL_SYMMETRIC 1
12 #define CL_NON_SYMMETRIC 2
13 
14 enum cl_construct_opt
15 {
16  Full,
17  Only_reorder
18 };
19 
20 #include "util/cuda/ofp_context.hxx"
21 
22 
34 template<unsigned int dim, typename T, typename CellList> void populate_cell_list_no_sym_gpu(openfpm::vector<Point<dim,T>> & pos, CellList & cli, size_t g_m)
35 {
36  // First we have to set the counter to zero
37  cli.PopulateOnGPU(pos);
38 }
39 
40 #include "Vector/map_vector.hpp"
41 
42 template<bool is_gpu>
44 {
45  template<unsigned int dim, typename T, typename prop, typename Memory, template <typename> class layout_base , typename CellList,unsigned int ... prp>
46  static void populate(openfpm::vector<Point<dim,T>,Memory,layout_base > & pos,
47  openfpm::vector<Point<dim,T>,Memory,layout_base > & v_pos_out,
50  CellList & cli,
51  mgpu::ofp_context_t & context,
52  size_t g_m,
53  cl_construct_opt optc)
54  {
55  cli.clear();
56 
57  for (size_t i = 0; i < pos.size() ; i++)
58  {
59  cli.add(pos.get(i), i);
60  }
61  }
62 };
63 
64 template<>
66 {
67  template<unsigned int dim, typename T, typename prop, typename Memory, template <typename> class layout_base , typename CellList, unsigned int ... prp>
68  static void populate(openfpm::vector<Point<dim,T>,Memory,layout_base > & pos,
69  openfpm::vector<Point<dim,T>,Memory,layout_base > & v_pos_out,
72  CellList & cli,
73  mgpu::ofp_context_t & context,
74  size_t g_m,
75  cl_construct_opt optc)
76  {
77  v_prp_out.resize(pos.size());
78  v_pos_out.resize(pos.size());
79 
80  cli.template construct<decltype(pos),decltype(v_prp),prp ...>(pos,v_pos_out,v_prp,v_prp_out,context,g_m,0,pos.size(),optc);
81  }
82 };
83 
84 template<bool is_gpu>
86 {
87  template<unsigned int dim, typename T, typename Memory, template <typename> class layout_base , typename CellList>
88  static void populate(openfpm::vector<Point<dim,T>,Memory,layout_base > & pos,
89  CellList & cli,
90  size_t g_m)
91  {
92  cli.clear();
93 
94  for (size_t i = 0; i < g_m ; i++)
95  {
96  cli.addDom(pos.get(i), i);
97  }
98 
99  for (size_t i = g_m; i < pos.size() ; i++)
100  {
101  cli.addPad(pos.get(i), i);
102  }
103  }
104 };
105 
106 template<>
108 {
109  template<unsigned int dim, typename T, typename Memory, template <typename> class layout_base , typename CellList>
110  static void populate(openfpm::vector<Point<dim,T>,Memory,layout_base > & pos,
111  CellList & cli,
112  size_t g_m)
113  {
114  std::cout << __FILE__ << ":" << __LINE__ << " symmetric cell list on GPU is not implemented. (And will never be, race conditions make them non suitable for GPU)" << std::endl;
115  }
116 };
117 
129 template<unsigned int dim,
130  typename T,
131  typename prop,
132  typename Memory,
133  template <typename> class layout_base ,
134  typename CellList,
135  unsigned int ... prp>
136 void populate_cell_list_no_sym(openfpm::vector<Point<dim,T>,Memory,layout_base > & pos,
137  openfpm::vector<Point<dim,T>,Memory,layout_base > & v_pos_out,
140  CellList & cli,
141  mgpu::ofp_context_t & mgpu,
142  size_t g_m,
143  cl_construct_opt optc)
144 {
146  ::template populate<dim,T,prop,Memory,layout_base,CellList, prp ...>(pos,v_pos_out,v_prp,v_prp_out,cli,mgpu,g_m,optc);
147 }
148 
160 template<unsigned int dim, typename T, typename Memory, template <typename> class layout_base ,typename CellList>
161 void populate_cell_list_sym(openfpm::vector<Point<dim,T>,Memory,layout_base > & pos,
162  CellList & cli,
163  size_t g_m)
164 {
166 }
167 
180 template<unsigned int dim,
181  typename T,
182  typename prop,
183  typename Memory,
184  template <typename> class layout_base,
185  typename CellList,
186  unsigned int ... prp>
187 void populate_cell_list(openfpm::vector<Point<dim,T>,Memory,layout_base> & pos,
188  openfpm::vector<Point<dim,T>,Memory,layout_base > & v_pos_out,
191  CellList & cli,
192  mgpu::ofp_context_t & context,
193  size_t g_m,
194  size_t opt,
195  cl_construct_opt optc)
196 {
197  if (opt == CL_NON_SYMMETRIC)
198  {populate_cell_list_no_sym<dim,T,prop,Memory,layout_base,CellList,prp ...>(pos,v_pos_out,v_prp,v_prp_out,cli,context,g_m,optc);}
199  else
200  {populate_cell_list_sym(pos,cli,g_m);}
201 }
202 
217 template<unsigned int dim,
218  typename T,
219  typename Memory,
220  template <typename> class layout_base,
221  typename CellList,
222  unsigned int ... prp>
223 void populate_cell_list(openfpm::vector<Point<dim,T>,Memory,layout_base> & pos,
224  CellList & cli,
225  mgpu::ofp_context_t & context,
226  size_t g_m,
227  size_t opt,
228  cl_construct_opt optc)
229 {
230  typedef openfpm::vector<aggregate<int>,Memory,layout_base> stub_prop_type;
231 
232  stub_prop_type stub1;
233  stub_prop_type stub2;
234 
235  openfpm::vector<Point<dim,T>,Memory,layout_base> stub3;
236 
237  populate_cell_list<dim,T,aggregate<int>,Memory,layout_base,CellList,prp...>(pos,stub3,stub1,stub2,cli,context,g_m,opt,optc);
238 }
239 
244 template<typename vector_pos_type>
245 struct pos_v
246 {
247  vector_pos_type & pos;
248 
249  pos_v(vector_pos_type & pos)
250  :pos(pos)
251  {}
252 };
253 
254 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLIST_UTIL_HPP_ */
void addDom(const T(&pos)[dim], typename Mem_type::local_index_type ele)
Add an element in the cell list forcing to be in the domain cells.
Definition: CellList.hpp:757
void clear()
Clear the cell list.
Definition: CellList.hpp:1100
void add(const T(&pos)[dim], typename Mem_type::local_index_type ele)
Add an element in the cell list.
Definition: CellList.hpp:726
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
size_t size()
Stub size.
Definition: map_vector.hpp:211
Structure that contain a reference to a vector of particles.
void addPad(const T(&pos)[dim], typename Mem_type::local_index_type ele)
Add an element in the cell list forcing to be in the padding cells.
Definition: CellList.hpp:795
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:202
Class for FAST cell list implementation.
Definition: CellList.hpp:356