OpenFPM  5.2.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_util.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() const
112  {
113  return wthr.x * ((wthr.y != 0)?wthr.y:1) * ((wthr.z != 0)?wthr.z:1);
114  }
115 
116  size_t nthrs() const
117  {
118  return thr.x * ((thr.y != 0)?thr.y:1) * ((thr.z != 0)?thr.z:1);
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  __device__ __host__ 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  __device__ __host__ 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>
357  __device__ __host__ inline grid_sm(const grid_sm<N,S> & g)
358  {
359  size_tot = g.size_tot;
360 
361  for (size_t i = 0 ; i < N ; i++)
362  {
363  sz[i] = g.sz[i];
364  sz_s[i] = g.sz_s[i];
365  }
366  }
367 
376  __device__ __host__ inline grid_sm(const grid_sm<N,T> & g)
377  {
378  size_tot = g.size_tot;
379 
380  for (size_t i = 0 ; i < N ; i++)
381  {
382  sz[i] = g.sz[i];
383  sz_s[i] = g.sz_s[i];
384  }
385  }
386 
387  // Static element to calculate total size
388 
389  inline size_t totalSize(const size_t sz)
390  {
391  size_t tSz = 1;
392 
393  for (size_t i = 0 ; i < N ; i++)
394  {
395  tSz *= sz;
396  }
397 
398  return tSz;
399  }
400 
401  // Static element to calculate total size
402 
403  __device__ __host__ inline size_t totalSize(const size_t (& sz)[N])
404  {
405  size_t tSz = 1;
406 
407  for (size_t i = 0 ; i < N ; i++)
408  {
409  tSz *= sz[i];
410  }
411 
412  return tSz;
413  }
414 
415 
424  inline grid_sm(const size_t & sz)
425  : size_tot(totalSize(sz))
426  {
427  Initialize(sz);
428  }
429 
438  __device__ __host__ inline grid_sm(const size_t (& sz)[N])
439  : size_tot(totalSize(sz))
440  {
441  Initialize(sz);
442  }
443 
453  template<typename check=NoCheck, typename ids_type>
454  inline mem_id LinId(const grid_key_dx<N,ids_type> & gk, const signed char sum_id[N]) const
455  {
456  mem_id lid;
457 
458  // Check the sum produce a valid key
459 
460  if (check::valid(gk.get(0) + sum_id[0],sz[0]) == false)
461  return -1;
462 
463  lid = gk.get(0) + sum_id[0];
464 
465 
466  for (mem_id i = 1 ; i < N ; i++)
467  {
468  // Check the sum produce a valid key
469 
470  if (check::valid(gk.get(i) + sum_id[i],sz[i]) == false)
471  return -1;
472 
473  lid += (gk.get(i) + sum_id[i]) * sz_s[i-1];
474  }
475 
476  return lid;
477  }
478 
489  template<typename check=NoCheck,typename ids_type>
490  inline mem_id LinId(const grid_key_dx<N,ids_type> & gk, const signed char sum_id[N], const size_t (&bc)[N]) const
491  {
492  mem_id lid;
493 
494  // Check the sum produce a valid key
495 
496  if (bc[0] == NON_PERIODIC)
497  {
498  if (check::valid(gk.get(0) + sum_id[0],sz[0]) == false)
499  return -1;
500 
501  lid = gk.get(0) + sum_id[0];
502  }
503  else
504  {
505  lid = openfpm::math::positive_modulo(gk.get(0) + sum_id[0],sz[0]);
506  }
507 
508  for (mem_id i = 1 ; i < N ; i++)
509  {
510  // Check the sum produce a valid key
511 
512  /* coverity[dead_error_line] */
513  if (bc[i] == NON_PERIODIC)
514  {
515  if (check::valid(gk.get(i) + sum_id[i],sz[i]) == false)
516  return -1;
517 
518  lid += (gk.get(i) + sum_id[i]) * sz_s[i-1];
519  }
520  else
521  {
522  lid += (openfpm::math::positive_modulo(gk.get(i) + sum_id[i],sz[i])) * sz_s[i-1];
523  }
524  }
525 
526  return lid;
527  }
528 
537  inline mem_id LinIdPtr(size_t * k) const
538  {
539  mem_id lid = k[0];
540  for (mem_id i = 1 ; i < N ; i++)
541  {
542  lid += k[i] * sz_s[i-1];
543  }
544 
545  return lid;
546  }
547 
557  __device__ __host__ inline mem_id LinId(const size_t (& k)[N]) const
558  {
559  mem_id lid = k[0];
560  for (mem_id i = 1 ; i < N ; i++)
561  {
562  /* coverity[dead_error_line] */
563  lid += k[i] * sz_s[i-1];
564  }
565 
566  return lid;
567  }
568 
578  template<typename ids_type> __device__ __host__ inline mem_id LinId(const grid_key_dx<N,ids_type> & gk) const
579  {
580  mem_id lid = gk.get(0);
581  for (mem_id i = 1 ; i < N ; i++)
582  {
583  /* coverity[dead_error_line] */
584  lid += gk.get(i) * sz_s[i-1];
585  }
586 
587  return lid;
588  }
589 
595  template<typename a, typename ...lT, typename enabler = typename std::enable_if<sizeof...(lT) == N-1>::type >
596  __device__ __host__ inline mem_id Lin(a v,lT...t) const
597  {
598  return v*sz_s[sizeof...(t)-1] + Lin_impl(t...);
599  }
600 
602 
609  __device__ __host__ inline grid_key_dx<N> InvLinId(mem_id id) const
610  {
611  // Inversion of linearize
612 
613  grid_key_dx<N> gk;
614 
615  for (mem_id i = 0 ; i < N ; i++)
616  {
617  gk.set_d(i,id % sz[i]);
618  id /= sz[i];
619  }
620 
621  return gk;
622  }
623 
624 
634  //#pragma openfpm layout(get)
635  inline mem_id LinId(mem_id * id) const
636  {
637  mem_id lid = 0;
638  lid += id[0];
639  for (mem_id i = 1 ; i < N ; i++)
640  {
641  lid += id[i] * sz_s[i-1];
642  }
643 
644  return lid;
645  }
646 
648  __device__ __host__ ~grid_sm() {};
649 
657  __device__ __host__ inline size_t size() const
658  {
659  return size_tot;
660  };
661 
668  __device__ __host__ inline grid_sm<N,T> & operator=(const grid_sm<N,T> & g)
669  {
670  size_tot = g.size_tot;
671 
672  for (size_t i = 0 ; i < N ; i++)
673  {
674  sz[i] = g.sz[i];
675  sz_s[i] = g.sz_s[i];
676  }
677 
678  box = g.box;
679 
680  return *this;
681  }
682 
691  inline bool operator==(const grid_sm<N,T> & g)
692  {
693  for (size_t i = 0 ; i < N ; i++)
694  {
695  if (sz[i] != g.sz[i])
696  return false;
697  }
698 
699 #ifdef SE_CLASS1
700 
701  if (size_tot != g.size_tot)
702  return false;
703 
704  for (size_t i = 0 ; i < N ; i++)
705  {
706  if (sz_s[i] != g.sz_s[i])
707  return false;
708  }
709 
710 #endif
711  return true;
712  }
713 
720  inline bool operator!=(const grid_sm<N,T> & g)
721  {
722  return ! this->operator==(g);
723  }
724 
736  __device__ __host__ inline size_t size_s(unsigned int i) const
737  {
738  return sz_s[i];
739  }
740 
750  __device__ __host__ inline size_t size(unsigned int i) const
751  {
752  return sz[i];
753  }
754 
760  __device__ __host__ inline const size_t (& getSize() const)[N]
761  {
762  return sz;
763  }
764 
770  __device__ __host__ inline void getSize(size_t (&size) [N]) const
771  {
772  for (size_t i = 0; i < N; ++i) size[i] = sz[i];
773  }
774 
784  {
785  return grid_key_dx_iterator_sub<N>(*this,start,stop);
786  }
787 
788 #if defined(CUDA_GPU)
789 
796  template<typename T2>
797  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
798  {
799  return getGPUIterator_impl<N>(*this,key1,key2,n_thr);
800  }
801 
808  struct ite_gpu<N> getGPUIterator(size_t n_thr = default_kernel_wg_threads_) const
809  {
810  grid_key_dx<N> k1;
811  grid_key_dx<N> k2;
812 
813  for (size_t i = 0 ; i < N ; i++)
814  {
815  k1.set_d(i,0);
816  k2.set_d(i,size(i));
817  }
818 
819  return getGPUIterator_impl<N>(*this,k1,k2,n_thr);
820  }
821 
822 
823 #endif
824 
830  inline void swap(grid_sm<N,T> & g)
831  {
832  size_t tmp = size_tot;
833  size_tot = g.size_tot;
834  g.size_tot = tmp;
835 
836  for (size_t i = 0 ; i < N ; i++)
837  {
838  tmp = sz[i];
839  sz[i] = g.sz[i];
840  g.sz[i] = tmp;
841 
842  tmp = sz_s[i];
843  sz_s[i] = g.sz_s[i];
844  g.sz_s[i] = tmp;
845  }
846  }
847 
853  std::string toString() const
854  {
855  std::stringstream str;
856 
857  for (size_t i = 0 ; i < N ; i++)
858  str << "sz[" << i << "]=" << size(i) << " ";
859 
860  return str.str();
861  }
862 
864  template <unsigned int,typename> friend class grid_sm;
865 };
866 
867 
868 template<unsigned int dim, typename grid_sm_type, typename T>
869 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)
870 {
871  // Work to do
872  ite_gpu<dim> ig;
873 
874  if (n_thr == static_cast<size_t>(-1)) {
875  ig.thr.x = 0xFFFFFFFF;
876  ig.thr.y = 0xFFFFFFFF;
877  ig.thr.z = 0xFFFFFFFF;
878 
879  if (dim >= 1)
880  ig.wthr.x = key2.get(0) - key1.get(0) + 1;
881  else
882  ig.wthr.x = 0;
883 
884  if (dim >= 2)
885  ig.wthr.y = key2.get(1) - key1.get(1) + 1;
886  else
887  ig.wthr.y = 0;
888 
889  if (dim >= 3)
890  {
891  ig.wthr.z = 1;
892  for (size_t i = 2 ; i < dim ; i++)
893  {ig.wthr.z *= (key2.get(i) - key1.get(i) + 1);}
894  }
895  else
896  ig.wthr.z = 0;
897 
898  for (size_t i = 0 ; i < dim ; i++)
899  {
900  ig.start.set_d(i,key1.get(i));
901  ig.stop.set_d(i,key2.get(i));
902  }
903 
904  return ig;
905 
906  }
907 
908  size_t tot_work = 1;
909  for (size_t i = 0 ; i < dim ; i++)
910  {tot_work *= key2.get(i) - key1.get(i) + 1;}
911 
912  size_t n = (tot_work <= n_thr)?openfpm::math::round_big_2(tot_work):n_thr;
913 
914  if (tot_work == 0)
915  {
916  ig.thr.x = 0;
917  ig.thr.y = 0;
918  ig.thr.z = 0;
919 
920  ig.wthr.x = 0;
921  ig.wthr.y = 0;
922  ig.wthr.z = 0;
923 
924  for (size_t i = 0 ; i < dim ; i++)
925  {
926  ig.start.set_d(i,key1.get(i));
927  ig.stop.set_d(i,key2.get(i));
928  }
929 
930  return ig;
931  }
932 
933  ig.thr.x = 1;
934  ig.thr.y = 1;
935  ig.thr.z = 1;
936 
937  int dir = 0;
938 
939  while (n != 1)
940  {
941  if (dir % 3 == 0)
942  {ig.thr.x = ig.thr.x << 1;}
943  else if (dir % 3 == 1)
944  {ig.thr.y = ig.thr.y << 1;}
945  else if (dir % 3 == 2)
946  {ig.thr.z = ig.thr.z << 1;}
947 
948  n = n >> 1;
949 
950  dir++;
951  dir %= dim;
952  }
953 
954  if (dim >= 1)
955  {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);}
956 
957  if (dim >= 2)
958  {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);}
959  else
960  {ig.wthr.y = 1;}
961 
962  if (dim >= 3)
963  {
964  // Roll the other dimensions on z
965  ig.wthr.z = 1;
966  for (size_t i = 2 ; i < dim ; i++)
967  {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);}
968  }
969  else
970  {ig.wthr.z = 1;}
971 
972  // crop if wthr == 1
973 
974  if (dim >= 1 && ig.wthr.x == 1)
975  {ig.thr.x = (key2.get(0) - key1.get(0) + 1);}
976 
977  if (dim >= 2 && ig.wthr.y == 1)
978  {ig.thr.y = key2.get(1) - key1.get(1) + 1;}
979 
980  if (dim == 3 && ig.wthr.z == 1)
981  {ig.thr.z = key2.get(2) - key1.get(2) + 1;}
982 
983  for (size_t i = 0 ; i < dim ; i++)
984  {
985  ig.start.set_d(i,key1.get(i));
986  ig.stop.set_d(i,key2.get(i));
987  }
988 
989  return ig;
990 }
991 
992 
1000 {
1001  size_t dim;
1002 
1003 public:
1004 
1011  size_t getDim()
1012  {
1013  return dim;
1014  }
1015 
1022  :dim(key.dim)
1023  {
1024  // Allocate the key
1025  k = new mem_id[dim];
1026 
1027  // Copy the key
1028  for(unsigned int i = 0 ; i < dim ; i++)
1029  {
1030  k[i] = key.k[i];
1031  }
1032  }
1033 
1041  grid_key_dx_r(size_t dim)
1042  :dim(dim)
1043  {
1044  // Allocate the key
1045  k = new mem_id[dim];
1046  }
1047 
1048  ~grid_key_dx_r()
1049  {
1050  delete [] k;
1051  }
1052 
1054  template<typename a, typename ...T>void set(a v, T...t)
1055  {
1056  k[dim-1] = v;
1057  invert_assign(t...);
1058  }
1059 
1069  mem_id get(size_t i)
1070  {
1071  return k[i];
1072  }
1073 
1082  void set_d(size_t i, mem_id id)
1083  {
1084  k[i] = id;
1085  }
1086 
1088  mem_id * k;
1089 
1090 private:
1091 
1097  template<typename a, typename ...T>void invert_assign(a v,T...t)
1098  {
1099  k[sizeof...(T)] = v;
1100  invert_assign(t...);
1101  }
1102 
1103  template<typename a, typename ...T>void invert_assign(a v)
1104  {
1105  k[0] = v;
1106  }
1107 
1108  void invert_assign()
1109  {
1110  }
1111 
1112 };
1113 
1114 
1123 {
1124  size_t dim;
1125 
1127  size_t sz;
1128 
1129  // Actual grid_key position
1130  grid_key_dx_r gk;
1131 
1132 public:
1133 
1140  size_t getDim()
1141  {
1142  return dim;
1143  }
1144 
1152  Iterator_g_const(size_t n, size_t sz)
1153  :dim(n),sz(sz),gk(n)
1154  {
1155  // fill gk with the first grid element that satisfied the constrain: 0,1,2,3... dim
1156 
1157  for (size_t i = 0 ; i < dim ; i++)
1158  {
1159  gk.set_d(i,dim-i-1);
1160  }
1161  }
1162 
1172  {
1174 
1175  gk.set_d(0,gk.get(0)+1);
1176 
1178 
1179  unsigned int i = 0;
1180  for ( ; i < dim-1 ; i++)
1181  {
1182  size_t id = gk.get(i);
1183  if (id >= sz)
1184  {
1185  // ! overflow, increment the next index
1186 
1187  id = gk.get(i+1);
1188  if (id+i+2 >= sz)
1189  {
1190  // there is no-way to produce a valid key
1191  // there is not need to check the previous index
1192  // overflow i+1
1193 
1194  gk.set_d(i+1,sz);
1195  }
1196  else
1197  {
1198 
1199  // reinitialize the previous index
1200 
1201  for (unsigned int s = 0 ; s <= i+1 ; s++)
1202  {
1203  gk.set_d(i+1-s,id+1+s);
1204  }
1205  }
1206  }
1207  else
1208  {
1209  break;
1210  }
1211  }
1212 
1213  return *this;
1214  }
1215 
1224  bool isNext()
1225  {
1226  // If dimensionless return immediately
1227  if (dim == 0)
1228  return false;
1229 
1230  if (gk.get(dim-1) < static_cast<mem_id>(sz-dim+1))
1231  {
1233 
1234  return true;
1235  }
1236 
1238  return false;
1239  }
1240 
1250  {
1251  return gk;
1252  }
1253 };
1254 
1255 #endif
This class represent an N-dimensional box.
Definition: Box.hpp:60
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:555
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:566
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:543
__device__ __host__ bool isInsideKey(const KeyType &k) const
Check if the point is inside the region (Border included)
Definition: Box.hpp:1160
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:532
Class to check if the edge can be created or not.
Definition: grid_sm.hpp:82
static bool valid(size_t v_id, size_t sz)
Check if vertex exist.
Definition: grid_sm.hpp:94
size_t getDim()
Get the dimensionality of the iterator.
Definition: grid_sm.hpp:1140
bool isNext()
Check if there is the next element.
Definition: grid_sm.hpp:1224
Iterator_g_const & operator++()
Get the next element.
Definition: grid_sm.hpp:1171
Iterator_g_const(size_t n, size_t sz)
Constructor.
Definition: grid_sm.hpp:1152
grid_key_dx_r & get()
Return the actual key.
Definition: grid_sm.hpp:1249
size_t sz
size of the grid (the grid is assumed a square so equal on each dimension)
Definition: grid_sm.hpp:1127
Class to check if the edge can be created or not.
Definition: grid_sm.hpp:59
static bool valid(size_t v_id, size_t sz)
No check is performed.
Definition: grid_sm.hpp:69
Declaration grid_key_dx_iterator_sub.
Emulate grid_key_dx with runtime dimensionality.
Definition: grid_sm.hpp:1000
void set_d(size_t i, mem_id id)
Set the i index.
Definition: grid_sm.hpp:1082
grid_key_dx_r(size_t dim)
constructor
Definition: grid_sm.hpp:1041
mem_id * k
structure that store all the index
Definition: grid_sm.hpp:1088
mem_id get(size_t i)
get the i index
Definition: grid_sm.hpp:1069
void set(a v, T...t)
set the grid key from a list of numbers
Definition: grid_sm.hpp:1054
size_t getDim()
Get the dimensionality of the key.
Definition: grid_sm.hpp:1011
void invert_assign(a v, T...t)
Recursively invert the assignment.
Definition: grid_sm.hpp:1097
grid_key_dx_r(grid_key_dx_r &key)
constructor from another key
Definition: grid_sm.hpp:1021
__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
Declaration grid_sm.
Definition: grid_sm.hpp:167
__device__ __host__ grid_sm< N, T > & operator=(const grid_sm< N, T > &g)
Copy the grid from another grid.
Definition: grid_sm.hpp:668
void setDimensions(const size_t(&dims)[N])
Reset the dimension of the grid.
Definition: grid_sm.hpp:326
__device__ __host__ grid_sm(const size_t(&sz)[N])
Construct a grid of a specified size.
Definition: grid_sm.hpp:438
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:783
size_t size_tot
total number of the elements in the grid
Definition: grid_sm.hpp:172
mem_id LinId(mem_id *id) const
Linearization of an array of mem_id (long int)
Definition: grid_sm.hpp:635
__device__ __host__ void Initialize(const size_t sz)
Initialize the basic structure.
Definition: grid_sm.hpp:189
grid_sm(const size_t &sz)
Construct a grid of a specified size.
Definition: grid_sm.hpp:424
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition: grid_sm.hpp:454
__device__ __host__ void Initialize(const size_t(&sz)[N])
Initialize the basic structure.
Definition: grid_sm.hpp:220
__device__ __host__ const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Definition: grid_sm.hpp:760
__device__ __host__ void getSize(size_t(&size)[N]) const
Returns the size of the grid in the passed array.
Definition: grid_sm.hpp:770
__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_s(unsigned int i) const
Definition: grid_sm.hpp:736
mem_id LinIdPtr(size_t *k) const
Linearization of the set of indexes.
Definition: grid_sm.hpp:537
grid_sm()
Default constructor.
Definition: grid_sm.hpp:338
Box< N, size_t > box
Box enclosing the grid.
Definition: grid_sm.hpp:169
__device__ __host__ ~grid_sm()
Destructor.
Definition: grid_sm.hpp:648
bool operator!=(const grid_sm< N, T > &g)
Check if the two grid_sm are the same.
Definition: grid_sm.hpp:720
void swap(grid_sm< N, T > &g)
swap the grid_sm informations
Definition: grid_sm.hpp:830
size_t sz_s[N]
size of the grid on each stride (used for linearization)
Definition: grid_sm.hpp:178
void Initialize()
Initialize the basic structure.
Definition: grid_sm.hpp:248
__device__ __host__ size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:657
friend class grid_sm
It simply mean that all the classes grid are friend of all its specialization.
Definition: grid_sm.hpp:864
__device__ __host__ grid_key_dx< N > InvLinId(mem_id id) const
Construct.
Definition: grid_sm.hpp:609
__device__ __host__ mem_id LinId(const grid_key_dx< N, ids_type > &gk) const
Linearization of the grid_key_dx.
Definition: grid_sm.hpp:578
const Box< N, size_t > getBoxKey() const
Return the box enclosing the grid.
Definition: grid_sm.hpp:308
std::string toString() const
Produce a string from the object.
Definition: grid_sm.hpp:853
bool operator==(const grid_sm< N, T > &g)
Check if the two grid_sm are the same.
Definition: grid_sm.hpp:691
size_t sz[N]
size of the grid
Definition: grid_sm.hpp:175
__device__ __host__ grid_sm(const grid_sm< N, T > &g)
copy constructor
Definition: grid_sm.hpp:376
__device__ __host__ mem_id Lin_impl(a v) const
Linearize a set of index.
Definition: grid_sm.hpp:281
__device__ __host__ size_t size(unsigned int i) const
Definition: grid_sm.hpp:750
__device__ __host__ grid_sm(const grid_sm< N, S > &g)
construct a grid from another grid
Definition: grid_sm.hpp:357
Box< N, size_t > getBox() const
Return the box enclosing the grid.
Definition: grid_sm.hpp:294
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N], const size_t(&bc)[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition: grid_sm.hpp:490
__device__ __host__ mem_id LinId(const size_t(&k)[N]) const
Linearization of the grid_key_dx.
Definition: grid_sm.hpp:557
__device__ __host__ mem_id Lin(a v, lT...t) const
linearize an arbitrary set of index
Definition: grid_sm.hpp:596
Declaration print_warning_on_adjustment.
Definition: ids.hpp:169