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 | |
23 | /*! \brief populate the Cell-list with particles non symmetric case on GPU |
24 | * |
25 | * \tparam dim dimensionality of the space |
26 | * \tparam T type of the space |
27 | * \tparam CellList type of cell-list |
28 | * |
29 | * \param pos vector of positions |
30 | * \param cli Cell-list |
31 | * \param g_m marker (particle below this marker must be inside the domain, particles outside this marker must be outside the domain) |
32 | * |
33 | */ |
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> |
43 | struct populate_cell_list_no_sym_impl |
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, |
48 | openfpm::vector<prop,Memory,layout_base > & v_prp, |
49 | openfpm::vector<prop,Memory,layout_base > & v_prp_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<> |
65 | struct populate_cell_list_no_sym_impl<true> |
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, |
70 | openfpm::vector<prop,Memory,layout_base > & v_prp, |
71 | openfpm::vector<prop,Memory,layout_base > & v_prp_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> |
85 | struct populate_cell_list_sym_impl |
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<> |
107 | struct populate_cell_list_sym_impl<true> |
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 | |
118 | /*! \brief populate the Cell-list with particles non symmetric case |
119 | * |
120 | * \tparam dim dimensionality of the space |
121 | * \tparam T type of the space |
122 | * \tparam CellList type of cell-list |
123 | * |
124 | * \param pos vector of positions |
125 | * \param cli Cell-list |
126 | * \param g_m marker (particle below this marker must be inside the domain, particles outside this marker must be outside the domain) |
127 | * |
128 | */ |
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, |
138 | openfpm::vector<prop,Memory,layout_base > & v_prp, |
139 | openfpm::vector<prop,Memory,layout_base > & v_prp_out, |
140 | CellList & cli, |
141 | mgpu::ofp_context_t & mgpu, |
142 | size_t g_m, |
143 | cl_construct_opt optc) |
144 | { |
145 | populate_cell_list_no_sym_impl<is_gpu_celllist<CellList>::value> |
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 | |
149 | /*! \brief populate the Cell-list with particles symmetric case |
150 | * |
151 | * \tparam dim dimensionality of the space |
152 | * \tparam T type of the space |
153 | * \tparam CellList type of cell-list |
154 | * |
155 | * \param pos vector of positions |
156 | * \param cli Cell-list |
157 | * \param g_m marker (particle below this marker must be inside the domain, particles outside this marker must be outside the domain) |
158 | * |
159 | */ |
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 | { |
165 | populate_cell_list_sym_impl<is_gpu_celllist<CellList>::value>::populate(pos,cli,g_m); |
166 | } |
167 | |
168 | /*! \brief populate the Cell-list with particles generic case |
169 | * |
170 | * \tparam dim dimensionality of the space |
171 | * \tparam T type of the space |
172 | * \tparam CellList type of cell-list |
173 | * |
174 | * \param pos vector of positions |
175 | * \param cli Cell-list |
176 | * \param opt option like CL_SYMMETRIC or CL_NON_SYMMETRIC |
177 | * \param g_m marker (particle below this marker must be inside the domain, particles outside this marker must be outside the domain) |
178 | * |
179 | */ |
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, |
189 | openfpm::vector<prop,Memory,layout_base > & v_prp, |
190 | openfpm::vector<prop,Memory,layout_base > & v_prp_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 | |
203 | /*! \brief populate the Cell-list with particles generic case |
204 | * |
205 | * \note this function remain for backward compatibility it supposed to be remove once the verlet-list use the new populate-cell list form |
206 | * |
207 | * \tparam dim dimensionality of the space |
208 | * \tparam T type of the space |
209 | * \tparam CellList type of cell-list |
210 | * |
211 | * \param pos vector of positions |
212 | * \param cli Cell-list |
213 | * \param opt option like CL_SYMMETRIC or CL_NON_SYMMETRIC |
214 | * \param g_m marker (particle below this marker must be inside the domain, particles outside this marker must be outside the domain) |
215 | * |
216 | */ |
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 | |
240 | /*! \brief Structure that contain a reference to a vector of particles |
241 | * |
242 | * |
243 | */ |
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_ */ |
255 | |