OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_dist_id_iterator_sub.hpp
1/*
2 * grid_dist_id_iterator_sub.hpp
3 *
4 * Created on: Oct 14, 2015
5 * Author: i-bird
6 */
7
8#ifndef SRC_GRID_GRID_DIST_ID_ITERATOR_SUB_HPP_
9#define SRC_GRID_GRID_DIST_ID_ITERATOR_SUB_HPP_
10
11
21template<unsigned int dim, typename device_grid>
23{
24 // sub_set of the grid where to iterate
25 struct sub_set
26 {
31 };
32
34 size_t g_c;
35
38
41
43 decltype(device_grid::type_of_subiterator()) a_it;
44
47
50
60 bool compute_subset(size_t gc, grid_key_dx<dim> & start_c, grid_key_dx<dim> & stop_c)
61 {
62 // Intersect the grid keys
63
64 for (size_t i = 0 ; i < dim ; i++)
65 {
66 long int start_p = gdb_ext.get(g_c).Dbox.getP1().get(i) + gdb_ext.get(g_c).origin.get(i);
67 long int stop_p = gdb_ext.get(g_c).Dbox.getP2().get(i) + gdb_ext.get(g_c).origin.get(i);
68 if (start.get(i) <= start_p)
69 start_c.set_d(i,gdb_ext.get(g_c).Dbox.getP1().get(i));
70 else if (start.get(i) <= stop_p)
71 start_c.set_d(i,start.get(i) - gdb_ext.get(g_c).origin.get(i));
72 else
73 return false;
74
75 if (stop.get(i) >= stop_p)
76 stop_c.set_d(i,gdb_ext.get(g_c).Dbox.getP2().get(i));
77 else if (stop.get(i) >= start_p)
78 stop_c.set_d(i,stop.get(i) - gdb_ext.get(g_c).origin.get(i));
79 else
80 return false;
81 }
82
83 return true;
84 }
85
90 {
91 // start and stop for the subset grid
92 grid_key_dx<dim> start_c;
93 grid_key_dx<dim> stop_c;
94
95 do
96 {
97 // When the grid has size 0 potentially all the other informations are garbage
98 while (g_c < gList.size() &&
99 (gList.get(g_c).size() == 0 || gdb_ext.get(g_c).Dbox.isValid() == false || compute_subset(g_c,start_c,stop_c) == false ))
100 {g_c++;}
101
102 // get the next grid iterator
103 if (g_c < gList.size())
104 {
105 a_it.reinitialize(gList.get(g_c).getIterator(start_c,stop_c));
106 if (a_it.isNext() == false) {g_c++;}
107 }
108 } while (g_c < gList.size() && a_it.isNext() == false);
109 }
110
111 public:
112
120 {
121 g_c = tmp.g_c;
122 gList = tmp.gList;
123 gdb_ext = tmp.gdb_ext;
124 start = tmp.start;
125 stop = tmp.stop;
126 a_it.reinitialize(tmp.a_it);
127
128 return *this;
129 }
130
137 :g_c(tmp.g_c),gList(tmp.gList),gdb_ext(tmp.gdb_ext),start(tmp.start),stop(tmp.stop)
138 {
139 // get the next grid iterator
140 if (g_c < gList.size())
141 {
142 if (reinitialize == true)
143 {a_it.reinitialize(tmp.a_it);}
144 else
145 {a_it = tmp.a_it;}
146 }
147 }
148
159 {
160 // Initialize the current iterator
161 // with the first grid
163 }
164
165 // Destructor
167 {
168 }
169
177 {
178 ++a_it;
179
180 // check if a_it is at the end
181
182 if (a_it.isNext() == true)
183 return *this;
184 else
185 {
186 // switch to the new grid
187 g_c++;
188
190 }
191
192 return *this;
193 }
194
200 inline bool isNext()
201 {
202 // If there are no other grid stop
203
204 if (g_c >= gList.size())
205 return false;
206
207 return true;
208 }
209
216 {
218 }
219
229 {
230 // Get the sub-domain id
231 size_t sub_id = k.getSub();
232
233 grid_key_dx<dim> k_glob = k.getKey();
234
235 // shift
236 k_glob = k_glob + gdb_ext.get(sub_id).origin;
237
238 return k_glob;
239 }
240
241 /* \brief Get the starting point of the grid iterator
242 *
243 * \return the starting point
244 *
245 */
246 inline grid_key_dx<dim> getStart() const
247 {
248 return start;
249 }
250
251 /* \brief Get the stop point of the grid iterator
252 *
253 * \return the stop point
254 *
255 */
256 inline grid_key_dx<dim> getStop() const
257 {
258 return stop;
259 }
260
265 inline size_t N_loc_grid()
266 {
267 return gList.size();
268 }
269
278 inline size_t loc_grid_info_start(size_t i,size_t j)
279 {
280 return gdb_ext.get(i).DBox.getLow(i);
281 }
282
291 inline size_t loc_grid_info_size(size_t i,size_t j)
292 {
293 return gdb_ext.get(i).GDBox.getHigh(i);
294 }
295};
296
297
299
300#define WHILE_M(grid,stencil) auto & ginfo = grid.getLocalGridsInfo();\
301 for (size_t s = 0 ; s < grid.getN_loc_grid() ; s++)\
302 {\
303 auto it = grid.get_loc_grid_iterator_stencil(s,stencil);\
304\
305 int lo[3] = {(int)ginfo.get(s).Dbox.getLow(0),(int)ginfo.get(s).Dbox.getLow(1),(int)ginfo.get(s).Dbox.getLow(2)};\
306 int hi[3] = {(int)ginfo.get(s).Dbox.getHigh(0),(int)ginfo.get(s).Dbox.getHigh(1),(int)ginfo.get(s).Dbox.getHigh(2)};\
307\
308 int uhi[3] = {(int)ginfo.get(s).GDbox.getHigh(0),(int)ginfo.get(s).GDbox.getHigh(1),(int)ginfo.get(s).GDbox.getHigh(2)};\
309\
310 int sx = uhi[0]+1;\
311 int sxsy = (uhi[0]+1)*(uhi[1]+1);
312
313#define ITERATE_3D_M(n_pt) int i = lo[2];\
314 for ( ; i <= hi[2] ; i+=1)\
315 {\
316 int j = lo[1];\
317 for ( ; j <= hi[1] ; j+=1)\
318 {\
319 int k = lo[0];\
320 for ( ; k <= hi[0] ; k+=n_pt)\
321 {
322
323
324#define GET_GRID_M(grid) grid.get_loc_grid(s);
325
326
327#define END_LOOP_M(n_pt) it.private_sum<n_pt>();\
328 }\
329 it.private_adjust( - k + sx + lo[0]);\
330 }\
331 it.private_adjust(- j*sx + sxsy + lo[1]*sx);\
332 }\
333 }
334
335#endif /* SRC_GRID_GRID_DIST_ID_ITERATOR_SUB_HPP_ */
Distributed grid iterator.
grid_key_dx< dim > getGKey(const grid_dist_key_dx< dim > &k)
Convert a g_dist_key_dx into a global key.
decltype(device_grid::type_of_subiterator()) a_it
Actual iterator.
grid_key_dx< dim > start
start key
size_t loc_grid_info_start(size_t i, size_t j)
Return the component j of the starting point (P1) of the domain part for the local grid i.
grid_dist_iterator_sub< dim, device_grid > & operator++()
Get the next element.
grid_key_dx< dim > stop
stop key
grid_dist_iterator_sub(const grid_dist_iterator_sub< dim, device_grid > &tmp, bool reinitialize=true)
Copy constructor.
void selectValidGrid()
from g_c increment g_c until you find a valid grid
size_t loc_grid_info_size(size_t i, size_t j)
Return the component j of the stop point (P2) of the domain part for the local grid i.
const openfpm::vector< device_grid > & gList
List of the grids we are going to iterate.
grid_dist_key_dx< dim, typename device_grid::base_key > get()
Get the actual key.
grid_dist_iterator_sub< dim, device_grid > & operator=(const grid_dist_iterator_sub< dim, device_grid > &tmp)
Copy operator=.
bool isNext()
Check if there is the next element.
size_t N_loc_grid()
Return the number of local grids.
bool compute_subset(size_t gc, grid_key_dx< dim > &start_c, grid_key_dx< dim > &stop_c)
compute the subset where it has to iterate
grid_dist_iterator_sub(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop, const openfpm::vector< device_grid > &gk, const openfpm::vector< GBoxes< device_grid::dims > > &gdb_ext)
Constructor of the distributed grid iterator.
const openfpm::vector< GBoxes< device_grid::dims > > & gdb_ext
Extension of each grid: domain and ghost + domain.
Grid key for a distributed grid.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition grid_key.hpp:516
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition grid_key.hpp:503
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
This structure store the Box that define the domain inside the Ghost + domain box.
Definition GBoxes.hpp:40
grid_key_dx< dim > start
start point where iterate
grid_key_dx< dim > stop
stop point where iterate