OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
vector_dist_subset.hpp
1//
2// Created by Abhinav Singh on 24.02.20.
3//
4
5#ifndef OPENFPM_PDATA_VECTOR_DIST_SUBSET_HPP
6#define OPENFPM_PDATA_VECTOR_DIST_SUBSET_HPP
7
8#include "vector_dist.hpp"
9
10template<unsigned int dim,
11 typename St,
12 typename prop,
14 typename Memory = HeapMemory,
15 template<typename> class layout_base = memory_traits_lin>
16class vector_dist_ws : public vector_dist<dim,St,typename AggregateAppend<int,prop>::type,Decomposition,Memory,layout_base>
17{
18 public:
19
20 typedef prop value_type;
21
22 using vector_dist<dim,St,typename AggregateAppend<int,prop>::type,Decomposition,Memory,layout_base>::vector_dist;
23
24 typedef boost::mpl::int_<AggregateAppend<int,prop>::type::max_prop-1> flag_prop;
25
26 void setSubset(vect_dist_key_dx key, int sub_id)
27 {
28 this->template getProp<flag_prop::value>(key) = sub_id;
29 }
30
31 int getSubset(vect_dist_key_dx key)
32 {
33 return this->template getProp<flag_prop::value>(key);
34 }
35
36 void ghost_get_subset()
37 {
38 this->template ghost_get<flag_prop::value>(NO_POSITION | SKIP_LABELLING);
39 }
40
41 void getLastSubset(int sub_id)
42 {
43 this->template getProp<flag_prop::value>(this->size_local()-1) = sub_id;
44 }
45
46 inline bool write_frame(std::string out, size_t iteration, int opt = VTK_WRITER)
47 {
48 auto &prop_names=this->getPropNames();
49 if(prop_names.size()==prop::max_prop){
50 prop_names.add({"SubsetNumber"});
51 }
52
53 return vector_dist<dim,St,typename AggregateAppend<int,prop>::type,Decomposition,Memory,layout_base>::write_frame(out,iteration,opt);
54 }
55 inline bool write_frame(std::string out, size_t iteration,double time, int opt = VTK_WRITER)
56 {
57 auto &prop_names=this->getPropNames();
58 if(prop_names.size()==prop::max_prop){
59 prop_names.add({"SubsetNumber"});
60 }
61
62 return vector_dist<dim,St,typename AggregateAppend<int,prop>::type,Decomposition,Memory,layout_base>::write_frame(out,iteration,time,opt);
63 }
64
65 inline bool write(std::string out,int opt = VTK_WRITER)
66 {
67 auto &prop_names=this->getPropNames();
68 if(prop_names.size()==prop::max_prop){
69 prop_names.add({"SubsetNumber"});
70 }
71
73 }
74
75};
76
77template<unsigned int dim,
78 typename St,
79 typename prop,
81 typename Memory = HeapMemory,
82 template<typename> class layout_base = memory_traits_lin>
84{
86
87 typedef boost::mpl::int_<AggregateAppend<int,prop>::type::max_prop-1> flag_prop;
88
89 ivector_dist & vd;
90
92
93 size_t sub_id;
94
95#ifdef SE_CLASS1
96 int subsetUpdate_ctr=0;
97#endif
98
99 void check_gm()
100 {
101 #ifdef SE_CLASS1
102 for (size_t i = 0 ; i < pid.size() ; i++)
103 {
104 if (pid.template get<0>(i) >= vd.size_local())
105 {
106 std::cout << __FILE__ << ":" << __LINE__ << " Error you have ghost particles in your subset" << std::endl;
107 }
108 }
109 #endif
110 }
111
112public:
113
116
118
120
122 typedef typename ivector_dist::stype stype;
123
125 static const unsigned int dims = ivector_dist::dims;
126
128 typedef int yes_i_am_vector_dist;
129
131 typedef std::integral_constant<bool,true> is_it_a_subset;
132
134 int sub_id)
135 :vd(vd),sub_id(sub_id)
136 {
137#ifdef SE_CLASS1
138 subsetUpdate_ctr=vd.getMapCtr();
139#endif
140 // construct pid vector
141
142 auto it = vd.getDomainIterator();
143
144 while (it.isNext())
145 {
146 auto p = it.get();
147
148 if (vd.template getProp<flag_prop::value>(p) == sub_id)
149 {
150 pid.add();
151 pid.template get<0>(pid.size()-1) = p.getKey();
152 }
153
154 ++it;
155 }
156
157 check_gm();
158 }
159
160 void ghost_get_subset()
161 {
162 vd.template ghost_get<flag_prop::value>(NO_POSITION | SKIP_LABELLING);
163 }
164
171 {
172 return pid;
173 }
174
175#ifdef SE_CLASS1
176 int getUpdateCtr() const{
177 return subsetUpdate_ctr;
178 }
179 int getMapCtr()
180 {
181 return vd.getMapCtr();
182 }
183#endif
184
188 inline void update()
189 {
190#ifdef SE_CLASS1
191 subsetUpdate_ctr=vd.getMapCtr();
192#endif
193
194 ghost_get_subset();
195
196 pid.clear();
197
198 auto it = vd.getDomainIterator();
199
200 while (it.isNext())
201 {
202 auto p = it.get();
203
204 if (vd.template getProp<flag_prop::value>(p) == sub_id)
205 {
206 pid.add();
207 pid.template get<0>(pid.size()-1) = p.getKey();
208 }
209
210 ++it;
211 }
212
213 check_gm();
214 }
215
222 {
223 return vd.getDecomposition();
224 }
225
231 inline const Decomposition & getDecomposition() const
232 {
233 return vd.getDecomposition();
234 }
235
241 size_t size_local() const
242 {
243 return pid.size();
244 }
245
251 size_t size_local_orig() const
252 {
253 return vd.size_local();
254 }
255
256#ifndef ONLY_READWRITE_GETTER
257
267 inline auto getPos(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
268 {
269 return vd.getPos(vect_dist_key_dx(pid.template get<0>(vec_key.getKey())));
270 }
271
281 inline auto getPos(vect_dist_key_dx vec_key) const -> decltype(vd.getPos(vec_key))
282 {
283 return vd.getPos(vect_dist_key_dx(pid.template get<0>(vec_key.getKey())));
284 }
285
291 template<unsigned int ... prp>
292 inline void hostToDeviceProp()
293 {
294 vd.template hostToDeviceProp<prp ...>();
295 }
296
302 inline void hostToDevicePos()
303 {
304 vd.template hostToDevicePos<0>();
305 }
306
316 inline auto getPosOrig(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
317 {
318 return vd.getPos(vec_key.getKey());
319 }
320
330 inline auto getPosOrig(vect_dist_key_dx vec_key) const -> decltype(vd.getPos(vec_key))
331 {
332 return vd.getPos(vec_key.getKey());
333 }
334
345 template<unsigned int id> inline auto getProp(vect_dist_key_dx vec_key) -> decltype(vd.template getProp<id>(vec_key))
346 {
347 return vd.template getProp<id>(vect_dist_key_dx(pid.template get<0>(vec_key.getKey())));
348 }
349
360 template<unsigned int id> inline auto getProp(vect_dist_key_dx vec_key) const -> decltype(vd.template getProp<id>(vec_key))
361 {
362 return vd.template getProp<id>(vect_dist_key_dx(pid.template get<0>(vec_key.getKey())));
363 }
364
365
366 vect_dist_key_dx getOriginKey(vect_dist_key_dx vec_key)
367 {
368 return vect_dist_key_dx(pid.template get<0>(vec_key.getKey()));
369 }
370
371#endif
372
379 {
380#ifdef SE_CLASS3
381 se3.getIterator();
382#endif
383
384 return vector_dist_iterator_subset(0,pid.size(),pid);
385 }
386
397 template<typename CellL = CellList_gen<dim, St, Process_keys_lin, Mem_fast<>, shift<dim, St>, typename std::remove_reference<decltype(vd.getPosVector())>::type > >
398 CellL getCellList(St r_cut, bool no_se3 = false)
399 {
400#ifdef SE_CLASS3
401 if (no_se3 == false)
402 {se3.getNN();}
403#endif
404
405 // Get ghost and anlarge by 1%
406 Ghost<dim,St> g = vd.getDecomposition().getGhost();
407 g.magnify(1.013);
408
409 return getCellList<CellL>(r_cut, g,no_se3);
410 }
411
417 bool isSubset() const
418 {
419 return true;
420 }
421
438 template<typename CellL = CellList_gen<dim, St, Process_keys_lin, Mem_fast<>, shift<dim, St> > >
439 CellL getCellList(St r_cut, const Ghost<dim, St> & enlarge, bool no_se3 = false)
440 {
441#ifdef SE_CLASS3
442 if (no_se3 == false)
443 {se3.getNN();}
444#endif
445
446 CellL cell_list;
447
448 // Division array
449 size_t div[dim];
450
451 // get the processor bounding box
452 Box<dim, St> pbox = vd.getDecomposition().getProcessorBounds();
453
454 // Processor bounding box
455 cl_param_calculate(pbox, div, r_cut, enlarge);
456
457 cell_list.Initialize(pbox, div);
458 cell_list.set_gm(pid.size());
459 cell_list.set_ndec(vd.getDecomposition().get_ndec());
460
461 cell_list.clear();
462
463 auto it = getDomainIterator();
464
465 while (it.isNext())
466 {
467 auto key = it.get();
468
469 Point<dim,St> pos = getPos(key);
470
471 cell_list.add(pos,pid.template get<0>(key.getKey()));
472
473 ++it;
474 }
475
476 // Add also the ghost
477
478 auto git = vd.getGhostIterator();
479
480 while (git.isNext())
481 {
482 auto key = git.get();
483
484 Point<dim,St> pos = vd.getPos(key);
485
486 if (vd.template getProp<flag_prop::value>(key) == sub_id)
487 {
488 cell_list.add(pos,key.getKey());
489 }
490
491 ++git;
492 }
493
494 return cell_list;
495 }
496
506 {
507 vd = v.vd;
508 pid = v.pid;
509
510 return *this;
511 }
512};
513
514
515template<unsigned int dim, typename St, typename prop, typename Decomposition = CartDecomposition<dim,St,CudaMemory,memory_traits_lin>> using vector_dist_ws_gpu = vector_dist_ws<dim,St,prop,Decomposition,CudaMemory,memory_traits_lin>;
516template<unsigned int dim, typename St, typename prop, typename Decomposition = CartDecomposition<dim,St,CudaMemory,memory_traits_lin>> using vector_dist_subset_gpu = vector_dist_subset<dim,St,prop,Decomposition,CudaMemory,memory_traits_lin>;
517
518#endif //OPENFPM_PDATA_VECTOR_DIST_SUBSET_HPP
This class represent an N-dimensional box.
Definition Box.hpp:61
void magnify(T mg)
Magnify the box.
Definition Box.hpp:889
This class decompose a space into sub-sub-domains and distribute them across processors.
Class for FAST cell list implementation.
Definition CellList.hpp:357
This class define the domain decomposition interface.
This class allocate, and destroy CPU memory.
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
Grid key for a distributed grid.
__device__ __host__ size_t getKey() const
Get the key.
Iterator that Iterate across particle indexes.
vect_dist_key_dx get()
Get the actual key.
auto getPos(vect_dist_key_dx vec_key) const -> decltype(vd.getPos(vec_key))
Get the position of an element.
auto getPosOrig(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
Get the position of an element.
std::integral_constant< bool, true > is_it_a_subset
Subset detection.
auto getPosOrig(vect_dist_key_dx vec_key) const -> decltype(vd.getPos(vec_key))
Get the position of an element.
auto getProp(vect_dist_key_dx vec_key) -> decltype(vd.template getProp< id >(vec_key))
Get the property of an element.
static const unsigned int dims
dimensions of space
CellL getCellList(St r_cut, bool no_se3=false)
Construct a cell list starting from the stored particles.
void hostToDeviceProp()
Move the memory from the device to host memory.
size_t size_local() const
return the local size of the vector
ivector_dist::stype stype
space type
Decomposition & getDecomposition()
Get the decomposition.
bool isSubset() const
Indicate that this class is not a subset.
const Decomposition & getDecomposition() const
Get the decomposition.
vector_dist_subset< dim, St, prop, Decomposition, Memory, layout_base > & operator=(const vector_dist_subset< dim, St, prop, Decomposition, Memory, layout_base > &v)
Operator= for distributed vector.
vector_dist_iterator_subset getDomainIterator() const
Get an iterator that traverse the particles in the domain.
ivector_dist::value_type value_type
property object
size_t size_local_orig() const
return the local size of the original vector
auto getPos(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
Get the position of an element.
void update()
Update the subset indexes.
openfpm::vector< aggregate< int > > & getIds()
Return the ids.
CellL getCellList(St r_cut, const Ghost< dim, St > &enlarge, bool no_se3=false)
Construct a cell list starting from the stored particles.
void hostToDevicePos()
Move the memory from the device to host memory.
auto getProp(vect_dist_key_dx vec_key) const -> decltype(vd.template getProp< id >(vec_key))
Get the property of an element.
Distributed vector.
size_t size_local() const
return the local size of the vector
static const unsigned int dims
template parameters typedefs
vector_dist_iterator getGhostIterator() const
Get the iterator across the position of the ghost particles.
auto getPos(vect_dist_key_dx vec_key) -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
size_t opt
option used to create this vector
vector_dist_iterator getDomainIterator() const
Get an iterator that traverse the particles in the domain.
openfpm::vector< std::string > & getPropNames()
Get the properties names.
Decomposition & getDecomposition()
Get the decomposition.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Transform the boost::fusion::vector into memory specification (memory_traits)