OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
grid_sm.hpp
1 #ifndef GRID_HPP
2 #define GRID_HPP
3 
4 
5 #include "config.h"
6 #include "util/cuda_launch.hpp"
7 #include <boost/shared_array.hpp>
8 #include <vector>
9 #include <initializer_list>
10 #include <array>
11 #include "memory/memory.hpp"
12 #include "Space/Shape/Box.hpp"
13 #include "grid_key.hpp"
14 #include <iostream>
15 #include "util/mathutil.hpp"
16 #include "iterators/stencil_type.hpp"
17 
18 
19 // Box need the definition of grid_key_dx_r
20 #define HARDWARE 1
21 
22 
23 struct No_check
24 {
25  template<typename SparseGrid_type>
26  __device__ __host__ bool check(SparseGrid_type & sggt,unsigned int dataBlockPos, unsigned int offset)
27  {
28  return true;
29  }
30 };
31 
32 template<unsigned int dim, typename T>
33 struct Box_check
34 {
35  Box<dim,T> box;
36 
37  template<typename T2>
38  explicit Box_check(Box<dim,T2> & box)
39  :box(box)
40  {}
41 
42  template<typename SparseGridGpu_type>
43  __device__ __host__ bool check(SparseGridGpu_type & sggt,unsigned int dataBlockId, unsigned int offset)
44  {
45  auto key = sggt.getCoord(dataBlockId,offset);
46 
47  return box.isInsideKey(key);
48  }
49 };
50 
51 
58 class NoCheck
59 {
60 public:
69  static bool valid(size_t v_id, size_t sz)
70  {
71  return true;
72  }
73 };
74 
82 {
83 public:
94  static bool valid(size_t v_id, size_t sz)
95  {
96  return v_id < sz;
97  }
98 };
99 
100 template<unsigned int dim>
101 struct ite_gpu
102 {
103 #if defined(CUDA_GPU)
104 
105  dim3 thr;
106  dim3 wthr;
107 
108  grid_key_dx<dim,int> start;
110 
111  size_t nblocks()
112  {
113  return wthr.x * wthr.y * wthr.z;
114  }
115 
116  size_t nthrs()
117  {
118  return thr.x * thr.y * thr.z;
119  }
120 
121 #endif
122 };
123 
124 template<unsigned int dim>
125 bool has_work_gpu(ite_gpu<dim> & ite)
126 {
127  size_t tot_work = 1;
128 
129  if (dim == 1)
130  {tot_work *= ite.wthr.x * ite.thr.x;}
131  else if(dim == 2)
132  {
133  tot_work *= ite.wthr.x * ite.thr.x;
134  tot_work *= ite.wthr.y * ite.thr.y;
135  }
136  else
137  {
138  tot_work *= ite.wthr.x * ite.thr.x;
139  tot_work *= ite.wthr.y * ite.thr.y;
140  tot_work *= ite.wthr.z * ite.thr.z;
141  }
142 
143  return tot_work != 0;
144 }
145 
147 template<unsigned int N, typename T> class grid_sm;
148 
149 template<unsigned int dim, typename grid_sm_type, typename T>
150 ite_gpu<dim> getGPUIterator_impl(const grid_sm_type & g1, const grid_key_dx<dim,T> & key1, const grid_key_dx<dim,T> & key2, size_t n_thr = default_kernel_wg_threads_);
151 
153 template <unsigned int dim, typename linearizer> class print_warning_on_adjustment;
154 
156 template<unsigned int dim,typename stencil=no_stencil, typename linearizer = grid_sm<dim,void>, typename warn=print_warning_on_adjustment<dim,linearizer>> class grid_key_dx_iterator_sub;
157 
165 template<unsigned int N, typename T>
166 class grid_sm
167 {
170 
172  size_t size_tot;
173 
175  size_t sz[N];
176 
178  size_t sz_s[N];
179 
189  inline void Initialize(const size_t sz)
190  {
192  sz_s[0] = sz;
193  this->sz[0] = sz;
194 
195  // set the box
196  box.setHigh(0,sz);
197  box.setLow(0,0);
198 
199  for (size_t i = 1 ; i < N ; i++)
200  {
201  /* coverity[dead_error_begin] */
202  sz_s[i] = sz*sz_s[i-1];
203  this->sz[i] = sz;
204 
205  // set the box
206  box.setHigh(i,sz);
207  box.setLow(i,0);
208  }
209  }
210 
220  inline void Initialize(const size_t (& sz)[N])
221  {
223  sz_s[0] = sz[0];
224  this->sz[0] = sz[0];
225 
226  // set the box
227  box.setHigh(0,sz[0]);
228  box.setLow(0,0);
229 
230  for (size_t i = 1 ; i < N ; i++)
231  {
232  /* coverity[dead_error_begin] */
233  sz_s[i] = sz[i]*sz_s[i-1];
234  this->sz[i] = sz[i];
235 
236  // set the box
237  box.setHigh(i,sz[i]);
238  box.setLow(i,0);
239  }
240  }
241 
248  inline void Initialize()
249  {
251  sz_s[0] = 0;
252  this->sz[0] = 0;
253 
254  // set the box
255  box.setHigh(0,0);
256  box.setLow(0,0);
257 
258  for (size_t i = 1 ; i < N ; i++)
259  {
260  /* coverity[dead_error_begin] */
261  sz_s[i] = sz[i]*sz_s[i-1];
262 
263  // set the box
264  box.setHigh(i,sz[i]);
265  box.setLow(i,0);
266  }
267  }
268 
274  template<typename a, typename ...lT>
275  __device__ __host__ inline mem_id Lin_impl(a v,lT...t) const
276  {
277  return v*sz_s[sizeof...(t)-1] + Lin_impl(t...);
278  }
279 
281  template<typename a> __device__ __host__ inline mem_id Lin_impl(a v) const
282  {
283  return v;
284  }
285 
286 public:
287 
288 
294  inline Box<N,size_t> getBox() const
295  {
296  return box;
297  }
298 
308  inline const Box<N,size_t> getBoxKey() const
309  {
310  Box<N,size_t> bx;
311 
312  for (size_t i = 0 ; i < N ; i++)
313  {
314  bx.setLow(i,box.getLow(i));
315  bx.setHigh(i,box.getHigh(i) - 1);
316  }
317 
318  return bx;
319  }
320 
326  inline void setDimensions(const size_t (& dims)[N])
327  {
328  Initialize(dims);
329  size_tot = totalSize(dims);
330  }
331 
338  inline grid_sm()
339  :size_tot(0)
340  {
341  // Initialize sz
342  for (size_t i = 0 ; i < N ; i++)
343  {sz[i] = 0;}
344 
345  Initialize();
346  }
347 
356  template<typename S> inline grid_sm(const grid_sm<N,S> & g)
357  {
358  size_tot = g.size_tot;
359 
360  for (size_t i = 0 ; i < N ; i++)
361  {
362  sz[i] = g.sz[i];
363  sz_s[i] = g.sz_s[i];
364  }
365  }
366 
367  // Static element to calculate total size
368 
369  inline size_t totalSize(const size_t sz)
370  {
371  size_t tSz = 1;
372 
373  for (size_t i = 0 ; i < N ; i++)
374  {
375  tSz *= sz;
376  }
377 
378  return tSz;
379  }
380 
381  // Static element to calculate total size
382 
383  inline size_t totalSize(const size_t (& sz)[N])
384  {
385  size_t tSz = 1;
386 
387  for (size_t i = 0 ; i < N ; i++)
388  {
389  tSz *= sz[i];
390  }
391 
392  return tSz;
393  }
394 
395 
404  inline grid_sm(const size_t & sz)
405  : size_tot(totalSize(sz))
406  {
407  Initialize(sz);
408  }
409 
418  inline grid_sm(const size_t (& sz)[N])
419  : size_tot(totalSize(sz))
420  {
421  Initialize(sz);
422  }
423 
433  template<typename check=NoCheck, typename ids_type>
434  inline mem_id LinId(const grid_key_dx<N,ids_type> & gk, const char sum_id[N]) const
435  {
436  mem_id lid;
437 
438  // Check the sum produce a valid key
439 
440  if (check::valid(gk.get(0) + sum_id[0],sz[0]) == false)
441  return -1;
442 
443  lid = gk.get(0) + sum_id[0];
444 
445 
446  for (mem_id i = 1 ; i < N ; i++)
447  {
448  // Check the sum produce a valid key
449 
450  if (check::valid(gk.get(i) + sum_id[i],sz[i]) == false)
451  return -1;
452 
453  lid += (gk.get(i) + sum_id[i]) * sz_s[i-1];
454  }
455 
456  return lid;
457  }
458 
469  template<typename check=NoCheck,typename ids_type>
470  inline mem_id LinId(const grid_key_dx<N,ids_type> & gk, const char sum_id[N], const size_t (&bc)[N]) const
471  {
472  mem_id lid;
473 
474  // Check the sum produce a valid key
475 
476  if (bc[0] == NON_PERIODIC)
477  {
478  if (check::valid(gk.get(0) + sum_id[0],sz[0]) == false)
479  return -1;
480 
481  lid = gk.get(0) + sum_id[0];
482  }
483  else
484  {
485  lid = openfpm::math::positive_modulo(gk.get(0) + sum_id[0],sz[0]);
486  }
487 
488  for (mem_id i = 1 ; i < N ; i++)
489  {
490  // Check the sum produce a valid key
491 
492  /* coverity[dead_error_line] */
493  if (bc[i] == NON_PERIODIC)
494  {
495  if (check::valid(gk.get(i) + sum_id[i],sz[i]) == false)
496  return -1;
497 
498  lid += (gk.get(i) + sum_id[i]) * sz_s[i-1];
499  }
500  else
501  {
502  lid += (openfpm::math::positive_modulo(gk.get(i) + sum_id[i],sz[i])) * sz_s[i-1];
503  }
504  }
505 
506  return lid;
507  }
508 
517  inline mem_id LinIdPtr(size_t * k) const
518  {
519  mem_id lid = k[0];
520  for (mem_id i = 1 ; i < N ; i++)
521  {
522  lid += k[i] * sz_s[i-1];
523  }
524 
525  return lid;
526  }
527 
537  __device__ __host__ inline mem_id LinId(const size_t (& k)[N]) const
538  {
539  mem_id lid = k[0];
540  for (mem_id i = 1 ; i < N ; i++)
541  {
542  /* coverity[dead_error_line] */
543  lid += k[i] * sz_s[i-1];
544  }
545 
546  return lid;
547  }
548 
558  template<typename ids_type> __device__ __host__ inline mem_id LinId(const grid_key_dx<N,ids_type> & gk) const
559  {
560  mem_id lid = gk.get(0);
561  for (mem_id i = 1 ; i < N ; i++)
562  {
563  /* coverity[dead_error_line] */
564  lid += gk.get(i) * sz_s[i-1];
565  }
566 
567  return lid;
568  }
569 
575  template<typename a, typename ...lT, typename enabler = typename std::enable_if<sizeof...(lT) == N-1>::type >
576  __device__ __host__ inline mem_id Lin(a v,lT...t) const
577  {
578  return v*sz_s[sizeof...(t)-1] + Lin_impl(t...);
579  }
580 
582 
589  __device__ __host__ inline grid_key_dx<N> InvLinId(mem_id id) const
590  {
591  // Inversion of linearize
592 
593  grid_key_dx<N> gk;
594 
595  for (mem_id i = 0 ; i < N ; i++)
596  {
597  gk.set_d(i,id % sz[i]);
598  id /= sz[i];
599  }
600 
601  return gk;
602  }
603 
604 
614  //#pragma openfpm layout(get)
615  inline mem_id LinId(mem_id * id) const
616  {
617  mem_id lid = 0;
618  lid += id[0];
619  for (mem_id i = 1 ; i < N ; i++)
620  {
621  lid += id[i] * sz_s[i-1];
622  }
623 
624  return lid;
625  }
626 
628  ~grid_sm() {};
629 
637  __device__ __host__ inline size_t size() const
638  {
639  return size_tot;
640  };
641 
648  __device__ __host__ inline grid_sm<N,T> & operator=(const grid_sm<N,T> & g)
649  {
650  size_tot = g.size_tot;
651 
652  for (size_t i = 0 ; i < N ; i++)
653  {
654  sz[i] = g.sz[i];
655  sz_s[i] = g.sz_s[i];
656  }
657 
658  box = g.box;
659 
660  return *this;
661  }
662 
671  inline bool operator==(const grid_sm<N,T> & g)
672  {
673  for (size_t i = 0 ; i < N ; i++)
674  {
675  if (sz[i] != g.sz[i])
676  return false;
677  }
678 
679 #ifdef SE_CLASS1
680 
681  if (size_tot != g.size_tot)
682  return false;
683 
684  for (size_t i = 0 ; i < N ; i++)
685  {
686  if (sz_s[i] != g.sz_s[i])
687  return false;
688  }
689 
690 #endif
691  return true;
692  }
693 
700  inline bool operator!=(const grid_sm<N,T> & g)
701  {
702  return ! this->operator==(g);
703  }
704 
716  inline size_t size_s(unsigned int i) const
717  {
718  return sz_s[i];
719  }
720 
730  __device__ __host__ inline size_t size(unsigned int i) const
731  {
732  return sz[i];
733  }
734 
740  inline const size_t (& getSize() const)[N]
741  {
742  return sz;
743  }
744 
754  {
755  return grid_key_dx_iterator_sub<N>(*this,start,stop);
756  }
757 
758 #if defined(CUDA_GPU)
759 
766  template<typename T2>
767  struct ite_gpu<N> getGPUIterator(const grid_key_dx<N,T2> & key1, const grid_key_dx<N,T2> & key2, size_t n_thr = default_kernel_wg_threads_) const
768  {
769  return getGPUIterator_impl<N>(*this,key1,key2,n_thr);
770  }
771 
778  struct ite_gpu<N> getGPUIterator(size_t n_thr = default_kernel_wg_threads_) const
779  {
780  grid_key_dx<N> k1;
781  grid_key_dx<N> k2;
782 
783  for (size_t i = 0 ; i < N ; i++)
784  {
785  k1.set_d(i,0);
786  k2.set_d(i,size(i));
787  }
788 
789  return getGPUIterator_impl<N>(*this,k1,k2,n_thr);
790  }
791 
792 #endif
793 
799  inline void swap(grid_sm<N,T> & g)
800  {
801  size_t tmp = size_tot;
802  size_tot = g.size_tot;
803  g.size_tot = tmp;
804 
805  for (size_t i = 0 ; i < N ; i++)
806  {
807  tmp = sz[i];
808  sz[i] = g.sz[i];
809  g.sz[i] = tmp;
810 
811  tmp = sz_s[i];
812  sz_s[i] = g.sz_s[i];
813  g.sz_s[i] = tmp;
814  }
815  }
816 
822  std::string toString() const
823  {
824  std::stringstream str;
825 
826  for (size_t i = 0 ; i < N ; i++)
827  str << "sz[" << i << "]=" << size(i) << " ";
828 
829  return str.str();
830  }
831 
833  template <unsigned int,typename> friend class grid_sm;
834 };
835 
836 
837 template<unsigned int dim, typename grid_sm_type, typename T>
838 ite_gpu<dim> getGPUIterator_impl(const grid_sm_type & g1, const grid_key_dx<dim,T> & key1, const grid_key_dx<dim,T> & key2, const size_t n_thr)
839 {
840  size_t tot_work = 1;
841  for (size_t i = 0 ; i < dim ; i++)
842  {tot_work *= key2.get(i) - key1.get(i) + 1;}
843 
844  size_t n = (tot_work <= n_thr)?openfpm::math::round_big_2(tot_work):n_thr;
845 
846  // Work to do
847  ite_gpu<dim> ig;
848 
849  if (tot_work == 0)
850  {
851  ig.thr.x = 0;
852  ig.thr.y = 0;
853  ig.thr.z = 0;
854 
855  ig.wthr.x = 0;
856  ig.wthr.y = 0;
857  ig.wthr.z = 0;
858 
859  return ig;
860  }
861 
862  ig.thr.x = 1;
863  ig.thr.y = 1;
864  ig.thr.z = 1;
865 
866  int dir = 0;
867 
868  while (n != 1)
869  {
870  if (dir % 3 == 0)
871  {ig.thr.x = ig.thr.x << 1;}
872  else if (dir % 3 == 1)
873  {ig.thr.y = ig.thr.y << 1;}
874  else if (dir % 3 == 2)
875  {ig.thr.z = ig.thr.z << 1;}
876 
877  n = n >> 1;
878 
879  dir++;
880  dir %= dim;
881  }
882 
883  if (dim >= 1)
884  {ig.wthr.x = (key2.get(0) - key1.get(0) + 1) / ig.thr.x + (((key2.get(0) - key1.get(0) + 1)%ig.thr.x != 0)?1:0);}
885 
886  if (dim >= 2)
887  {ig.wthr.y = (key2.get(1) - key1.get(1) + 1) / ig.thr.y + (((key2.get(1) - key1.get(1) + 1)%ig.thr.y != 0)?1:0);}
888  else
889  {ig.wthr.y = 1;}
890 
891  if (dim >= 3)
892  {
893  // Roll the other dimensions on z
894  ig.wthr.z = 1;
895  for (size_t i = 2 ; i < dim ; i++)
896  {ig.wthr.z *= (key2.get(i) - key1.get(i) + 1) / ig.thr.z + (((key2.get(i) - key1.get(i) + 1)%ig.thr.z != 0)?1:0);}
897  }
898  else
899  {ig.wthr.z = 1;}
900 
901  // crop if wthr == 1
902 
903  if (dim >= 1 && ig.wthr.x == 1)
904  {ig.thr.x = (key2.get(0) - key1.get(0) + 1);}
905 
906  if (dim >= 2 && ig.wthr.y == 1)
907  {ig.thr.y = key2.get(1) - key1.get(1) + 1;}
908 
909  if (dim == 3 && ig.wthr.z == 1)
910  {ig.thr.z = key2.get(2) - key1.get(2) + 1;}
911 
912  for (size_t i = 0 ; i < dim ; i++)
913  {
914  ig.start.set_d(i,key1.get(i));
915  ig.stop.set_d(i,key2.get(i));
916  }
917 
918  return ig;
919 }
920 
921 
929 {
930  size_t dim;
931 
932 public:
933 
940  size_t getDim()
941  {
942  return dim;
943  }
944 
951  :dim(key.dim)
952  {
953  // Allocate the key
954  k = new mem_id[dim];
955 
956  // Copy the key
957  for(unsigned int i = 0 ; i < dim ; i++)
958  {
959  k[i] = key.k[i];
960  }
961  }
962 
970  grid_key_dx_r(size_t dim)
971  :dim(dim)
972  {
973  // Allocate the key
974  k = new mem_id[dim];
975  }
976 
977  ~grid_key_dx_r()
978  {
979  delete [] k;
980  }
981 
983  template<typename a, typename ...T>void set(a v, T...t)
984  {
985  k[dim-1] = v;
986  invert_assign(t...);
987  }
988 
998  mem_id get(size_t i)
999  {
1000  return k[i];
1001  }
1002 
1011  void set_d(size_t i, mem_id id)
1012  {
1013  k[i] = id;
1014  }
1015 
1017  mem_id * k;
1018 
1019 private:
1020 
1026  template<typename a, typename ...T>void invert_assign(a v,T...t)
1027  {
1028  k[sizeof...(T)] = v;
1029  invert_assign(t...);
1030  }
1031 
1032  template<typename a, typename ...T>void invert_assign(a v)
1033  {
1034  k[0] = v;
1035  }
1036 
1037  void invert_assign()
1038  {
1039  }
1040 
1041 };
1042 
1043 
1052 {
1053  size_t dim;
1054 
1056  size_t sz;
1057 
1058  // Actual grid_key position
1059  grid_key_dx_r gk;
1060 
1061 public:
1062 
1069  size_t getDim()
1070  {
1071  return dim;
1072  }
1073 
1081  Iterator_g_const(size_t n, size_t sz)
1082  :dim(n),sz(sz),gk(n)
1083  {
1084  // fill gk with the first grid element that satisfied the constrain: 0,1,2,3... dim
1085 
1086  for (size_t i = 0 ; i < dim ; i++)
1087  {
1088  gk.set_d(i,dim-i-1);
1089  }
1090  }
1091 
1101  {
1103 
1104  gk.set_d(0,gk.get(0)+1);
1105 
1107 
1108  unsigned int i = 0;
1109  for ( ; i < dim-1 ; i++)
1110  {
1111  size_t id = gk.get(i);
1112  if (id >= sz)
1113  {
1114  // ! overflow, increment the next index
1115 
1116  id = gk.get(i+1);
1117  if (id+i+2 >= sz)
1118  {
1119  // there is no-way to produce a valid key
1120  // there is not need to check the previous index
1121  // overflow i+1
1122 
1123  gk.set_d(i+1,sz);
1124  }
1125  else
1126  {
1127 
1128  // reinitialize the previous index
1129 
1130  for (unsigned int s = 0 ; s <= i+1 ; s++)
1131  {
1132  gk.set_d(i+1-s,id+1+s);
1133  }
1134  }
1135  }
1136  else
1137  {
1138  break;
1139  }
1140  }
1141 
1142  return *this;
1143  }
1144 
1153  bool isNext()
1154  {
1155  // If dimensionless return immediately
1156  if (dim == 0)
1157  return false;
1158 
1159  if (gk.get(dim-1) < static_cast<mem_id>(sz-dim+1))
1160  {
1162 
1163  return true;
1164  }
1165 
1167  return false;
1168  }
1169 
1179  {
1180  return gk;
1181  }
1182 };
1183 
1184 #endif
Declaration print_warning_on_adjustment.
Definition: grid_sm.hpp:153
grid_sm()
Default constructor.
Definition: grid_sm.hpp:338
size_t sz_s[N]
size of the grid on each stride (used for linearization)
Definition: grid_sm.hpp:178
__device__ __host__ mem_id Lin_impl(a v) const
Linearize a set of index.
Definition: grid_sm.hpp:281
__device__ __host__ grid_key_dx< N > InvLinId(mem_id id) const
Construct.
Definition: grid_sm.hpp:589
Iterator_g_const(size_t n, size_t sz)
Constructor.
Definition: grid_sm.hpp:1081
std::string toString() const
Produce a string from the object.
Definition: grid_sm.hpp:822
__device__ __host__ mem_id Lin_impl(a v, lT...t) const
linearize an arbitrary set of index
Definition: grid_sm.hpp:275
__device__ __host__ size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:637
void set_d(size_t i, mem_id id)
Set the i index.
Definition: grid_sm.hpp:1011
grid_key_dx_r(size_t dim)
constructor
Definition: grid_sm.hpp:970
void set(a v, T...t)
set the grid key from a list of numbers
Definition: grid_sm.hpp:983
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:556
__device__ __host__ mem_id LinId(const grid_key_dx< N, ids_type > &gk) const
Linearization of the grid_key_dx.
Definition: grid_sm.hpp:558
grid_key_dx_iterator_sub< N > getSubIterator(const grid_key_dx< N > &start, const grid_key_dx< N > &stop) const
Return a sub-grid iterator.
Definition: grid_sm.hpp:753
Emulate grid_key_dx with runtime dimensionality.
Definition: grid_sm.hpp:928
size_t size_tot
total number of the elements in the grid
Definition: grid_sm.hpp:172
Box< N, size_t > box
Box enclosing the grid.
Definition: grid_sm.hpp:169
static bool valid(size_t v_id, size_t sz)
Check if vertex exist.
Definition: grid_sm.hpp:94
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition: grid_key.hpp:503
__device__ __host__ mem_id LinId(const size_t(&k)[N]) const
Linearization of the grid_key_dx.
Definition: grid_sm.hpp:537
mem_id get(size_t i)
get the i index
Definition: grid_sm.hpp:998
grid_key_dx_r(grid_key_dx_r &key)
constructor from another key
Definition: grid_sm.hpp:950
size_t sz[N]
size of the grid
Definition: grid_sm.hpp:175
bool operator==(const grid_sm< N, T > &g)
Check if the two grid_sm are the same.
Definition: grid_sm.hpp:671
bool operator!=(const grid_sm< N, T > &g)
Check if the two grid_sm are the same.
Definition: grid_sm.hpp:700
void invert_assign(a v, T...t)
Recursively invert the assignment.
Definition: grid_sm.hpp:1026
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:544
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition: grid_sm.hpp:434
void Initialize()
Initialize the basic structure.
Definition: grid_sm.hpp:248
mem_id LinIdPtr(size_t *k) const
Linearization of the set of indexes.
Definition: grid_sm.hpp:517
const Box< N, size_t > getBoxKey() const
Return the box enclosing the grid.
Definition: grid_sm.hpp:308
grid_sm(const size_t &sz)
Construct a grid of a specified size.
Definition: grid_sm.hpp:404
__device__ __host__ mem_id Lin(a v, lT...t) const
linearize an arbitrary set of index
Definition: grid_sm.hpp:576
~grid_sm()
Destructor.
Definition: grid_sm.hpp:628
static bool valid(size_t v_id, size_t sz)
No check is performed.
Definition: grid_sm.hpp:69
void swap(grid_sm< N, T > &g)
swap the grid_sm informations
Definition: grid_sm.hpp:799
grid_sm(const grid_sm< N, S > &g)
construct a grid from another grid
Definition: grid_sm.hpp:356
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:533
size_t sz
size of the grid (the grid is assumed a square so equal on each dimension)
Definition: grid_sm.hpp:1056
size_t getDim()
Get the dimensionality of the iterator.
Definition: grid_sm.hpp:1069
const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Definition: grid_sm.hpp:740
__device__ __host__ size_t size(unsigned int i) const
Definition: grid_sm.hpp:730
void Initialize(const size_t(&sz)[N])
Initialize the basic structure.
Definition: grid_sm.hpp:220
size_t size_s(unsigned int i) const
Definition: grid_sm.hpp:716
This class represent an N-dimensional box.
Definition: Box.hpp:60
friend class grid_sm
It simply mean that all the classes grid are friend of all its specialization.
Definition: grid_sm.hpp:833
Iterator_g_const & operator++()
Get the next element.
Definition: grid_sm.hpp:1100
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const char sum_id[N], const size_t(&bc)[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition: grid_sm.hpp:470
Declaration grid_sm.
Definition: grid_sm.hpp:147
__device__ __host__ bool isInsideKey(const KeyType &k) const
Check if the point is inside the region (Border included)
Definition: Box.hpp:1153
grid_key_dx_r & get()
Return the actual key.
Definition: grid_sm.hpp:1178
Declaration grid_key_dx_iterator_sub.
Definition: grid_sm.hpp:156
Class to check if the edge can be created or not.
Definition: grid_sm.hpp:58
bool isNext()
Check if there is the next element.
Definition: grid_sm.hpp:1153
__device__ __host__ grid_sm< N, T > & operator=(const grid_sm< N, T > &g)
Copy the grid from another grid.
Definition: grid_sm.hpp:648
Definition: ids.hpp:168
Box< N, size_t > getBox() const
Return the box enclosing the grid.
Definition: grid_sm.hpp:294
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition: grid_key.hpp:516
mem_id * k
structure that store all the index
Definition: grid_sm.hpp:1017
mem_id LinId(mem_id *id) const
Linearization of an array of mem_id (long int)
Definition: grid_sm.hpp:615
Class to check if the edge can be created or not.
Definition: grid_sm.hpp:81
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:567
void Initialize(const size_t sz)
Initialize the basic structure.
Definition: grid_sm.hpp:189
void setDimensions(const size_t(&dims)[N])
Reset the dimension of the grid.
Definition: grid_sm.hpp:326
size_t getDim()
Get the dimensionality of the key.
Definition: grid_sm.hpp:940
grid_sm(const size_t(&sz)[N])
Construct a grid of a specified size.
Definition: grid_sm.hpp:418