OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
map_grid.hpp
1 #ifndef MAP_HPP_
2 #define MAP_HPP_
3 
4 #include "config.h"
5 
8 #include "util/object_util.hpp"
9 #include "Grid/util.hpp"
10 #include "Vector/vect_isel.hpp"
11 #include "Vector/util.hpp"
12 #include "Vector/map_vector_grow_p.hpp"
13 #include "memory/ExtPreAlloc.hpp"
14 #include "util/util_debug.hpp"
15 #include "util/Pack_stat.hpp"
16 //#include "Vector/map_vector.hpp"
17 //#include "Pack_selector.hpp"
18 #include <boost/fusion/include/mpl.hpp>
19 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
20 #include <boost/fusion/include/at_c.hpp>
21 #include <boost/fusion/include/for_each.hpp>
22 #include <boost/fusion/container/vector.hpp>
23 #include <boost/fusion/include/vector.hpp>
24 #include <boost/fusion/container/vector/vector_fwd.hpp>
25 #include <boost/fusion/include/vector_fwd.hpp>
26 #include <boost/type_traits.hpp>
27 #include <boost/fusion/include/for_each.hpp>
28 #include <boost/mpl/range_c.hpp>
29 #include <boost/mpl/for_each.hpp>
30 #include "memory_ly/memory_conf.hpp"
31 #include "util/copy_compare/meta_copy.hpp"
32 #ifdef SE_CLASS2
33 #include "Memleak_check.hpp"
34 #endif
35 #include "util/for_each_ref.hpp"
36 #include "util.hpp"
37 #include <utility>
38 #ifdef CUDA_GPU
39 #include "memory/CudaMemory.cuh"
40 #endif
41 #include "grid_sm.hpp"
42 #include "Encap.hpp"
43 #include "memory_ly/memory_array.hpp"
44 #include "memory_ly/memory_c.hpp"
45 #include <vector>
46 #include "se_grid.hpp"
47 #include "memory/HeapMemory.hpp"
48 #include "memory/PtrMemory.hpp"
49 #include "grid_common.hpp"
50 #include "util/se_util.hpp"
51 #include "iterators/grid_key_dx_iterator.hpp"
52 #include "iterators/grid_key_dx_iterator_sub.hpp"
53 #include "iterators/grid_key_dx_iterator_sp.hpp"
54 #include "iterators/grid_key_dx_iterator_sub_bc.hpp"
55 
56 #ifndef CUDA_GPU
57 typedef HeapMemory CudaMemory;
58 #endif
59 
92 namespace openfpm {
93 
94 template<typename T, typename Memory=HeapMemory, typename grow_p=grow_policy_double, unsigned int impl=vect_isel<T>::value> class vector;
95 }
96 
97 template<unsigned int dim, typename T, typename S=HeapMemory, typename Mem = typename memory_traits_lin< typename T::type >::type >
98 class grid_cpu
99 {
100 public:
101  // expose the dimansionality as a static const
102  static constexpr unsigned int dims = dim;
103 
106 
108  typedef typename T::type T_type;
109 
110  typedef Mem memory_conf;
111 
123  static bool pack()
124  {
125  return false;
126  }
127 
128  static bool packRequest()
129  {
130  return false;
131  }
132 
133  static bool calculateMem()
134  {
135  return false;
136  }
137 
138  template<int ... prp> void pack(ExtPreAlloc<S> & mem, Pack_stat & sts)
139  {
140 #ifdef DEBUG
141  if (mem.ref() == 0)
142  std::cerr << "Error : " << __FILE__ << ":" << __LINE__ << " the reference counter of mem should never be zero when packing \n";
143 #endif
144 
145  // Sending property object and vector
148  dtype dvect;
149 
150  // Calculate the required memory for packing
151  size_t alloc_ele = dvect.calculateMem(size(),0);
152 
153  // Create an object over the preallocated memory (No allocation is produced)
154  dtype dest;
155  dest.setMemory(mem);
156  dest.resize(size());
157 
158  auto it = getIterator();
159 
160  pack_with_iterator<decltype(it),dtype,prp...>(it,dest);
161 
162  // Update statistic
163  sts.incReq();
164  }
165 
166 
176  template<int ... prp> void pack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims> & sub_it, Pack_stat & sts)
177  {
178 #ifdef DEBUG
179  if (mem.ref() == 0)
180  std::cerr << "Error : " << __FILE__ << ":" << __LINE__ << " the reference counter of mem should never be zero when packing \n";
181 #endif
182 
183  // Sending property object
184  typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
186 
187  // Create an object over the preallocated memory (No allocation is produced)
188  dtype dest;
189  dest.setMemory(mem);
190  dest.resize(sub_it.getVolume());
191 
192  pack_with_iterator<grid_key_dx_iterator_sub<dims>,dtype,prp...>(sub_it,dest);
193 
194  // Update statistic
195  sts.incReq();
196  }
197 
203  template<int ... prp> void packRequest(std::vector<size_t> & v)
204  {
205  // Sending property object
206  typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
208  dtype dvect;
209 
210  // Calculate the required memory for packing
211  size_t alloc_ele = dvect.calculateMem(size(),0);
212 
213  v.push_back(alloc_ele);
214  }
215 
225  template<int ... prp> void packRequest(grid_key_dx_iterator_sub<dims> & sub, std::vector<size_t> & v)
226  {
228  dtype dvect;
229 
230  // Calculate the required memory for packing
231  size_t alloc_ele = dvect.template calculateMem<prp...>(sub.getVolume(),0);
232 
233  v.push_back(alloc_ele);
234  }
235 
248  template <typename it, typename dtype, int ... prp> void pack_with_iterator(it & sub_it, dtype & dest)
249  {
250  // Sending property object
251  typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
252 
253  size_t id = 0;
254 
255  // Packing the information
256  while (sub_it.isNext())
257  {
258  // copy all the object in the send buffer
259  typedef encapc<dims,value_type,memory_conf > encap_src;
260  // destination object type
262 
263  // Copy only the selected properties
264  object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(get_o(sub_it.get()),dest.get(id));
265 
266  ++id;
267  ++sub_it;
268  }
269  }
270 
277  template <typename it, typename stype, unsigned int ... prp> void unpack_with_iterator(ExtPreAlloc<S> & mem, it & sub_it, stype & src, Unpack_stat & ps)
278  {
279  size_t id = 0;
280 
281  // Sending property object
282  typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
283 
284  // unpacking the information
285  while (sub_it.isNext())
286  {
287  // copy all the object in the send buffer
288  typedef encapc<dims,grid_cpu<dim,T,S,Mem>::value_type,grid_cpu<dim,T,S,Mem>::memory_conf > encap_dst;
289  // destination object type
291 
292  // Copy only the selected properties
293  object_s_di<encap_src,encap_dst,OBJ_ENCAP,prp...>(src.get(id),this->get_o(sub_it.get()));
294 
295  ++id;
296  ++sub_it;
297  }
298  }
299 
308  template<unsigned int ... prp> void unpack(ExtPreAlloc<S> & mem, Unpack_stat & ps)
309  {
310  // object that store the information in mem
311  typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
313  stype svect;
314 
315 
316  // Calculate the size to pack the object
317  size_t size = svect.calculateMem(this->size(),0);
318 
319  // Create an Pointer object over the preallocated memory (No allocation is produced)
320  PtrMemory & ptr = *(new PtrMemory(mem.getPointerOffset(ps.getOffset()),size));
321 
322  // Create an object over a pointer (No allocation is produced)
323  stype src;
324  src.setMemory(mem);
325  src.resize(this->size());
326 
327  auto it = this->getIterator();
328 
329  unpack_with_iterator<decltype(it),stype,prp...>(mem,it,src,ps);
330 
331  ps.addOffset(size);
332  }
333 
343  template<unsigned int ... prp> void unpack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims> & sub_it, Unpack_stat & ps)
344  {
345  // object that store the information in mem
346  typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
348 
349  size_t size = stype::template calculateMem(sub_it.getVolume(),0);
350 
351  // Create an object over the preallocated memory (No allocation is produced)
352  PtrMemory & ptr = *(new PtrMemory(mem.getPointerOffset(ps.getOffset()),size));
353 
354  // Create an object of the packed information over a pointer (No allocation is produced)
355  stype src;
356  src.setMemory(ptr);
357  src.resize(sub_it.getVolume());
358 
359  unpack_with_iterator<grid_key_dx_iterator_sub<dims>,stype,prp...>(mem,sub_it,src,ps);
360 
361  ps.addOffset(size);
362  }
363 
364 private:
365 
367  bool is_mem_init = false;
368 
371 
373  Mem data_;
374 
377 
379  size_t err_code;
380 
388  std::vector<size_t> getV()
389  {
390  std::vector<size_t> tmp;
391 
392  for (unsigned int i = 0 ; i < dim ; i++)
393  {
394  tmp.push_back(0);
395  }
396 
397  return tmp;
398  }
399 
400 #ifdef SE_CLASS1
401 
406  inline void check_init() const
407  {
408  if (is_mem_init == false)
409  {
410  std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";
411  size_t * err_code_pointer = (size_t *)&this->err_code;
412  *err_code_pointer = 1001;
413  ACTION_ON_ERROR(GRID_ERROR);
414  }
415  }
416 
422  inline void check_bound(const grid_key_dx<dim> & v1) const
423  {
424  for (long int i = 0 ; i < dim ; i++)
425  {
426  if (v1.get(i) >= (long int)getGrid().size(i))
427  {
428  std::cerr << "Error " __FILE__ << ":" << __LINE__ <<" grid overflow " << "x=[" << i << "]=" << v1.get(i) << " >= " << getGrid().size(i) << "\n";
429  size_t * err_code_pointer = (size_t *)&this->err_code;
430  *err_code_pointer = 1002;
431  ACTION_ON_ERROR(GRID_ERROR);
432  }
433  else if (v1.get(i) < 0)
434  {
435  std::cerr << "Error " __FILE__ << ":" << __LINE__ <<" grid overflow " << "x=[" << i << "]=" << v1.get(i) << " is negative " << "\n";
436  size_t * err_code_pointer = (size_t *)&this->err_code;
437  *err_code_pointer = 1003;
438  ACTION_ON_ERROR(GRID_ERROR);
439  }
440  }
441  }
442 
451  inline void check_bound(const grid_cpu<dim,T,S,Mem> & g,const grid_key_dx<dim> & key2) const
452  {
453  for (size_t i = 0 ; i < dim ; i++)
454  {
455  if (key2.get(i) >= (long int)g.g1.size(i))
456  {
457  std::cerr << "Error " __FILE__ << ":" << __LINE__ <<" grid overflow " << "x=[" << i << "]=" << key2.get(i) << " >= " << g.g1.size(i) << "\n";
458  size_t * err_code_pointer = (size_t *)&this->err_code;
459  *err_code_pointer = 1004;
460  ACTION_ON_ERROR(GRID_ERROR);
461  }
462  else if (key2.get(i) < 0)
463  {
464  std::cerr << "Error " __FILE__ << ":" << __LINE__ <<" grid overflow " << "x=[" << i << "]=" << key2.get(i) << " is negative " << "\n";
465  size_t * err_code_pointer = (size_t *)&this->err_code;
466  *err_code_pointer = 1005;
467  ACTION_ON_ERROR(GRID_ERROR);
468  }
469  }
470  }
471 
472 #endif
473 
474 public:
475 
477  typedef int yes_i_am_grid;
478 
481 
483  typedef Mem memory_t;
484 
486  // you can access all the properties of T
488 
489  // The object type the grid is storing
490  typedef T value_type;
491 
493  grid_cpu() THROW
494  :g1(getV()),isExternal(false),err_code(0)
495  {
496  // Add this pointer
497 #ifdef SE_CLASS2
498  check_new(this,8,GRID_EVENT,1);
499 #endif
500  }
501 
510  grid_cpu(const grid_cpu & g) THROW
511  :isExternal(false),err_code(0)
512  {
513  this->operator=(g);
514  }
515 
517  grid_cpu(std::vector<size_t> & sz) THROW
518  :g1(sz),isExternal(false),err_code(0)
519  {
520  // Add this pointer
521 #ifdef SE_CLASS2
522  check_new(this,8,GRID_EVENT,1);
523 #endif
524  }
525 
527  grid_cpu(std::vector<size_t> && sz) THROW
528  :g1(sz),isExternal(false),err_code(0)
529  {
530  // Add this pointer
531 #ifdef SE_CLASS2
532  check_new(this,8,GRID_EVENT,1);
533 #endif
534  }
535 
537  grid_cpu(const size_t (& sz)[dim]) THROW
538  :g1(sz),isExternal(false),err_code(0)
539  {
540  // Add this pointer
541 #ifdef SE_CLASS2
542  check_new(this,8,GRID_EVENT,1);
543 #endif
544  }
545 
547  ~grid_cpu() THROW
548  {
549  // delete this pointer
550 #ifdef SE_CLASS2
551  check_delete(this);
552 #endif
553  }
554 
561  {
562  // Add this pointer
563 #ifdef SE_CLASS2
564  check_new(this,8,GRID_EVENT,1);
565 #endif
566  swap(g.duplicate());
567 
568  return *this;
569  }
570 
577  {
578  // Add this pointer
579 #ifdef SE_CLASS2
580  check_new(this,8,GRID_EVENT,1);
581 #endif
582 
583  swap(g);
584 
585  return *this;
586  }
587 
596  {
597  // check if the have the same size
598  if (g1 != g.g1)
599  return false;
600 
601  auto it = getIterator();
602 
603  while (it.isNext())
604  {
605  auto key = it.get();
606 
607  if (this->get_o(key) != this->get_o(key))
608  return false;
609 
610  ++it;
611  }
612 
613  return true;
614  }
615 
620  {
621 #ifdef SE_CLASS2
622  check_valid(this,8);
623 #endif
624 
626  grid_cpu<dim,T,S,Mem> grid_new(g1.getSize());
627 
629  grid_new.setMemory();
630 
631  // We know that, if it is 1D we can safely copy the memory
632 // if (dim == 1)
633 // {
635 // grid_new.data_.mem->copy(*data_.mem);
636 // }
637 // else
638 // {
640 
643 
644  while(it.isNext())
645  {
646  grid_new.get_o(it.get()) = this->get_o(it.get());
647 
648  ++it;
649  }
650 // }
651 
652  // copy grid_new to the base
653 
654  return grid_new;
655  }
656 
665  const grid_sm<dim,T> & getGrid() const
666  {
667 #ifdef SE_CLASS2
668  check_valid(this,8);
669 #endif
670  return g1;
671  }
672 
681  void setMemory()
682  {
683 #ifdef SE_CLASS2
684  check_valid(this,8);
685 #endif
686  S * mem = new S();
687 
689  data_.setMemory(*mem);
690 
692  if (g1.size() != 0) data_.allocate(g1.size());
693 
694  is_mem_init = true;
695  }
696 
708  void setMemory(S & m)
709  {
710 #ifdef SE_CLASS2
711  check_valid(this,8);
712 #endif
713  isExternal = true;
715 
717  data_.setMemory(m);
718 
720  if (g1.size() != 0) data_.allocate(g1.size());
721 
722  is_mem_init = true;
723  }
724 
733  void * getPointer()
734  {
735 #ifdef SE_CLASS2
736  check_valid(this,8);
737 #endif
738  if (data_.mem_r == NULL)
739  return NULL;
740 
741  return data_.mem_r->get_pointer();
742  }
743 
752  const void * getPointer() const
753  {
754 #ifdef SE_CLASS2
755  check_valid(this,8);
756 #endif
757  if (data_.mem_r == NULL)
758  return NULL;
759 
760  return data_.mem_r->get_pointer();
761  }
762 
770  template <unsigned int p>inline typename type_cpu_prop<p,memory_lin>::type & get(grid_key_d<dim,p> & v1)
771  {
772 #ifdef SE_CLASS2
773  check_valid(this,8);
774 #endif
775 #ifdef SE_CLASS1
776  check_init();
777  check_bound(v1);
778 #endif
779 #ifdef SE_CLASS2
780  if (check_valid(&boost::fusion::at_c<p>(data_.mem_r->operator[](g1.LinId(v1)))) == false) {ACTION_ON_ERROR();}
781 #endif
782  return boost::fusion::at_c<p>(data_.mem_r->operator[](g1.LinId(v1)));
783  }
784 
792  template <unsigned int p>inline const typename type_cpu_prop<p,memory_lin>::type & get(grid_key_d<dim,p> & v1) const
793  {
794 #ifdef SE_CLASS2
795  check_valid(this,8);
796 #endif
797 #ifdef SE_CLASS1
798  check_init();
799  check_bound(v1);
800 #endif
801 #ifdef SE_CLASS2
802  if (check_valid(&boost::fusion::at_c<p>(data_.mem_r->operator[](g1.LinId(v1)))) == false) {ACTION_ON_ERROR()};
803 #endif
804  return boost::fusion::at_c<p>(data_.mem_r->operator[](g1.LinId(v1)));
805  }
806 
814  template <unsigned int p>inline typename type_cpu_prop<p,memory_lin>::type & get(const grid_key_dx<dim> & v1)
815  {
816 #ifdef SE_CLASS2
817  check_valid(this,8);
818 #endif
819 #ifdef SE_CLASS1
820  check_init();
821  check_bound(v1);
822 #endif
823 #ifdef SE_CLASS2
824  if (check_valid(&boost::fusion::at_c<p>(data_.mem_r->operator[](g1.LinId(v1))),sizeof(typename type_cpu_prop<p,memory_lin>::type)) == false) {ACTION_ON_ERROR()};
825 #endif
826  return boost::fusion::at_c<p>(data_.mem_r->operator[](g1.LinId(v1)));
827  }
828 
836  template <unsigned int p>inline const typename type_cpu_prop<p,memory_lin>::type & get(const grid_key_dx<dim> & v1) const
837  {
838 #ifdef SE_CLASS2
839  check_valid(this,8);
840 #endif
841 #ifdef SE_CLASS1
842  check_init();
843  check_bound(v1);
844 #endif
845 #ifdef SE_CLASS2
846  if (check_valid(&boost::fusion::at_c<p>(data_.mem_r->operator[](g1.LinId(v1))),sizeof(typename type_cpu_prop<p,memory_lin>::type)) == false) {ACTION_ON_ERROR()};
847 #endif
848  return boost::fusion::at_c<p>(data_.mem_r->operator[](g1.LinId(v1)));
849  }
850 
859  {
860 #ifdef SE_CLASS2
861  check_valid(this,8);
862 #endif
863 #ifdef SE_CLASS1
864  check_init();
865  check_bound(v1);
866 #endif
867 #ifdef SE_CLASS2
868  check_valid(&data_.mem_r->operator[](g1.LinId(v1)),sizeof(T));
869 #endif
870  return encapc<dim,T,Mem>(data_.mem_r->operator[](g1.LinId(v1)));
871  }
872 
880  inline const encapc<dim,T,Mem> get_o(const grid_key_dx<dim> & v1) const
881  {
882 #ifdef SE_CLASS2
883  check_valid(this,8);
884 #endif
885 #ifdef SE_CLASS1
886  check_init();
887  check_bound(v1);
888 #endif
889 #ifdef SE_CLASS2
890  if (check_valid(&data_.mem_r->operator[](g1.LinId(v1)),sizeof(T)) == false) {ACTION_ON_ERROR()}
891 #endif
892  return encapc<dim,T,Mem>(data_.mem_r->operator[](g1.LinId(v1)));
893  }
894 
902  void fill(unsigned char fl)
903  {
904 #ifdef SE_CLASS2
905  check_valid(this,8);
906 #endif
907  memset(getPointer(),fl,size() * sizeof(T));
908  }
909 
919  void resize(const size_t (& sz)[dim])
920  {
921 #ifdef SE_CLASS2
922  check_valid(this,8);
923 #endif
924 
926  grid_cpu<dim,T,S,Mem> grid_new(sz);
927 
929  if (isExternal == true)
930  {
931  grid_new.setMemory(static_cast<S&>(data_.getMemory()));
932 
933  // Create an empty memory allocator for the actual structure
934 
935  setMemory();
936  }
937  else
938  grid_new.setMemory();
939 
940 
941  // We know that, if it is 1D we can safely copy the memory
942 // if (dim == 1)
943 // {
944 // //! 1-D copy (This case is simple we use raw memory copy because is the fastest option)
945 // grid_new.data_.mem->copy(*data_.mem);
946 // }
947 // else
948 // {
949  // It should be better to separate between fast and slow cases
950 
952 
955 
956  while(it.isNext())
957  {
958  // get the grid key
959  grid_key_dx<dim> key = it.get();
960 
961  // create a copy element
962 
963  grid_new.get_o(key) = this->get_o(key);
964 
965  ++it;
966  }
967 // }
968 
969  // copy grid_new to the base
970 
971  this->swap(grid_new);
972  }
973 
978  void remove(size_t key)
979  {
980 #ifdef SE_CLASS2
981  check_valid(this,8);
982 #endif
983  if (dim != 1)
984  {
985 #ifdef SE_CLASS1
986  std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " remove work only on dimension == 1 " << "\n";
987 #endif
988  return;
989  }
990 
991  // It is safe to do a memory copy
992 
993  data_.move(&this->template get<0>());
994  }
995 
996 
1007  {
1008 #ifdef SE_CLASS2
1009  check_valid(this,8);
1010 #endif
1011  // move the data
1012  data_.swap(grid.data_);
1013 
1014  // exghange the grid info
1015  g1.swap(grid.g1);
1016 
1017  // exchange the init status
1018  bool exg = is_mem_init;
1019  is_mem_init = grid.is_mem_init;
1020  grid.is_mem_init = exg;
1021 
1022  // exchange the is external status
1023  exg = isExternal;
1024  isExternal = grid.isExternal;
1025  grid.isExternal = exg;
1026  }
1027 
1038  {
1039 #ifdef SE_CLASS2
1040  check_valid(this,8);
1041 #endif
1042  swap(grid);
1043  }
1044 
1054  template<typename Memory> inline void set(grid_key_dx<dim> dx, const encapc<1,T,Memory> & obj)
1055  {
1056 #ifdef SE_CLASS2
1057  check_valid(this,8);
1058 #endif
1059 #ifdef SE_CLASS1
1060  check_init();
1061  check_bound(dx);
1062 #endif
1063 
1064  // create the object to copy the properties
1065  copy_cpu_encap<dim,grid_cpu<dim,T,S,Mem>,Mem> cp(dx,*this,obj);
1066 
1067  // copy each property
1068  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(cp);
1069  }
1070 
1080  inline void set(grid_key_dx<dim> dx, const T & obj)
1081  {
1082 #ifdef SE_CLASS2
1083  check_valid(this,8);
1084 #endif
1085 #ifdef SE_CLASS1
1086  check_init();
1087  check_bound(dx);
1088 #endif
1089 
1090  this->get_o(dx) = obj;
1091  }
1092 
1093 
1102  inline void set(const grid_key_dx<dim> & key1,const grid_cpu<dim,T,S,Mem> & g, const grid_key_dx<dim> & key2)
1103  {
1104 #ifdef SE_CLASS2
1105  check_valid(this,8);
1106 #endif
1107 #ifdef SE_CLASS1
1108  check_init();
1109  check_bound(key1);
1110  check_bound(g,key2);
1111 #endif
1112 
1113  this->get_o(key1) = g.get_o(key2);
1114  }
1115 
1122  inline size_t size() const
1123  {
1124 #ifdef SE_CLASS2
1125  check_valid(this,8);
1126 #endif
1127  return g1.size();
1128  }
1129 
1139  {
1140 #ifdef SE_CLASS2
1141  check_valid(this,8);
1142 #endif
1143  return g1.getSubIterator(start,stop);
1144  }
1145 
1155  {
1156 #ifdef SE_CLASS2
1157  check_valid(this,8);
1158 #endif
1160  }
1161 
1169  {
1170 #ifdef SE_CLASS2
1171  check_valid(this,8);
1172 #endif
1173  return grid_key_dx_iterator<dim>(g1);
1174  }
1175 
1185  {
1186 #ifdef SE_CLASS2
1187  check_valid(this,8);
1188 #endif
1189  // get the starting point and the end point of the real domain
1190 
1191  return grid_key_dx_iterator_sub<dim>(g1,start,stop);
1192  }
1193 
1197  size_t getLastError()
1198  {
1199 #ifdef SE_CLASS2
1200  check_valid(this,8);
1201 #endif
1202  return err_code;
1203  }
1204 
1215  {
1216 #ifdef SE_CLASS2
1217  check_valid(this,8);
1218 #endif
1219  return 0;
1220  }
1221 
1231  size_t packObject(void * mem)
1232  {
1233 #ifdef SE_CLASS2
1234  check_valid(this,8);
1235 #endif
1236  return 0;
1237  }
1238 
1239  /* \brief It return the id of structure in the allocation list
1240  *
1241  * \see print_alloc and SE_CLASS2
1242  *
1243  */
1244  long int who()
1245  {
1246 #ifdef SE_CLASS2
1247  return check_whoami(this,8);
1248 #else
1249  return -1;
1250 #endif
1251  }
1252 };
1253 
1263 template<typename S>
1264 struct allocate
1265 {
1267  size_t sz;
1268 
1270  allocate(size_t sz)
1271  :sz(sz){};
1272 
1274  template<typename T>
1275  void operator()(T& t) const
1276  {
1278  t.setMemory(*new S());
1279 
1281  t.allocate(sz);
1282  }
1283 };
1284 
1285 #include "grid_gpu.hpp"
1286 
1287 #endif
1288 
1289 
size_t size() const
return the size of the grid
Definition: map_grid.hpp:1122
size_t getOffset()
Return the actual counter.
Definition: Pack_stat.hpp:39
bool isExternal
The memory allocator is not internally created.
Definition: map_grid.hpp:376
It copy the properties from one object to another.
void setMemory(S &m)
Get the object that provide memory.
Definition: map_grid.hpp:708
allocate(size_t sz)
constructor it fix the size
Definition: map_grid.hpp:1270
Transform the boost::fusion::vector into memory specification (memory_traits)
Definition: memory_conf.hpp:71
void set(grid_key_dx< dim > dx, const T &obj)
set an element of the grid
Definition: map_grid.hpp:1080
void fill(unsigned char fl)
Fill the memory with the selected byte.
Definition: map_grid.hpp:902
size_t err_code
Error code.
Definition: map_grid.hpp:379
grid_cpu(std::vector< size_t > &&sz) THROW
Constructor allocate memory and give them a representation.
Definition: map_grid.hpp:527
void pack_with_iterator(it &sub_it, dtype &dest)
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
Definition: map_grid.hpp:248
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
const encapc< dim, T, Mem > get_o(const grid_key_dx< dim > &v1) const
Get the of the selected element as a boost::fusion::vector.
Definition: map_grid.hpp:880
size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:552
void unpack_with_iterator(ExtPreAlloc< S > &mem, it &sub_it, stype &src, Unpack_stat &ps)
unpack the grid given an iterator
Definition: map_grid.hpp:277
void swap(grid_cpu< dim, T, S, Mem > &&grid)
It move the allocated object from one grid to another.
Definition: map_grid.hpp:1037
size_t packObject(void *mem)
It fill the message packet.
Definition: map_grid.hpp:1231
grid_cpu(const size_t(&sz)[dim]) THROW
Constructor allocate memory and give them a representation.
Definition: map_grid.hpp:537
grid_cpu< dim, T, S, Mem > & operator=(grid_cpu< dim, T, S, Mem > &&g)
It copy an operator.
Definition: map_grid.hpp:576
bool is_mem_init
Is the memory initialized.
Definition: map_grid.hpp:367
grid_cpu< dim, T, S, Mem > & operator=(const grid_cpu< dim, T, S, Mem > &g)
It copy an operator.
Definition: map_grid.hpp:560
bool operator==(const grid_cpu< dim, T, S, Mem > &g)
Compare two grids.
Definition: map_grid.hpp:595
grid_sm< dim, T > g1
This is a structure that store all information related to the grid and how indexes are linearized...
Definition: map_grid.hpp:370
size_t sz
size to allocate
Definition: map_grid.hpp:1267
encapc< dim, T, Mem > get_o(const grid_key_dx< dim > &v1)
Get the of the selected element as a boost::fusion::vector.
Definition: map_grid.hpp:858
void resize(const size_t(&sz)[dim])
Resize the space.
Definition: map_grid.hpp:919
This is a container to create a general object.
this class is a functor for "for_each" algorithm
Definition: grid_common.hpp:28
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:302
const grid_sm< dim, T > & getGrid() const
Return the internal grid information.
Definition: map_grid.hpp:665
size_t packObjectSize()
Return the size of the message needed to pack this object.
Definition: map_grid.hpp:1214
memory_traits_lin< typename T::type >::type memory_lin
Definition of the layout.
Definition: map_grid.hpp:480
Grow policy define how the vector should grow every time we exceed the size.
void pack(ExtPreAlloc< S > &mem, grid_key_dx_iterator_sub< dims > &sub_it, Pack_stat &sts)
Pack the object into the memory given an iterator.
Definition: map_grid.hpp:176
void operator()(T &t) const
It call the allocate function for each member.
Definition: map_grid.hpp:1275
static bool pack()
Pack the object into the memory given an iterator.
Definition: map_grid.hpp:123
void * getPointer()
Return a plain pointer to the internal data.
Definition: map_grid.hpp:733
grid_cpu(std::vector< size_t > &sz) THROW
Constructor allocate memory and give them a representation.
Definition: map_grid.hpp:517
bool isNext()
Check if there is the next element.
void packRequest(grid_key_dx_iterator_sub< dims > &sub, std::vector< size_t > &v)
Insert an allocation request.
Definition: map_grid.hpp:225
void swap(grid_sm< N, T > &g)
swap the grid_sm informations
Definition: grid_sm.hpp:697
void incReq()
Increment the request pointer.
Definition: Pack_stat.hpp:64
void unpack(ExtPreAlloc< S > &mem, grid_key_dx_iterator_sub< dims > &sub_it, Unpack_stat &ps)
unpack the sub-grid object
Definition: map_grid.hpp:343
~grid_cpu() THROW
Destructor.
Definition: map_grid.hpp:547
const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Definition: grid_sm.hpp:674
Mem data_
Memory layout specification + memory chunk pointer.
Definition: map_grid.hpp:373
this class is a functor for "for_each" algorithm
Definition: map_grid.hpp:1264
const void * getPointer() const
Return a plain pointer to the internal data.
Definition: map_grid.hpp:752
void set(grid_key_dx< dim > dx, const encapc< 1, T, Memory > &obj)
set an element of the grid
Definition: map_grid.hpp:1054
void addOffset(size_t off)
Increment the request pointer.
Definition: Pack_stat.hpp:30
Unpacking status object.
Definition: Pack_stat.hpp:15
this structure encapsulate an object of the grid
Definition: Encap.hpp:209
grid_key_dx< dim > access_key
Access key.
Definition: map_grid.hpp:105
grid_key_dx_iterator_sub< dim > getSubIterator(size_t m)
Return a sub-grid iterator.
Definition: map_grid.hpp:1154
void unpack(ExtPreAlloc< S > &mem, Unpack_stat &ps)
unpack the grid object
Definition: map_grid.hpp:308
grid_cpu() THROW
Default constructor.
Definition: map_grid.hpp:493
size_t getLastError()
Return the last error.
Definition: map_grid.hpp:1197
grid_cpu< dim, T, S, Mem > duplicate() const THROW
create a duplicated version of the grid
Definition: map_grid.hpp:619
grid_cpu(const grid_cpu &g) THROW
create a grid from another grid
Definition: map_grid.hpp:510
grid_key_dx_iterator_sub< dim > getSubIterator(grid_key_dx< dim > &start, grid_key_dx< dim > &stop) const
Return a sub-grid iterator.
Definition: map_grid.hpp:1138
void setMemory()
Create the object that provide memory.
Definition: map_grid.hpp:681
void swap(grid_cpu< dim, T, S, Mem > &grid)
It move the allocated object from one grid to another.
Definition: map_grid.hpp:1006
const grid_key_dx< dim > & get()
Get the actual key.
void set(const grid_key_dx< dim > &key1, const grid_cpu< dim, T, S, Mem > &g, const grid_key_dx< dim > &key2)
Set an element of the grid from another element of another grid.
Definition: map_grid.hpp:1102
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:202
grid_key_dx_iterator_sub< dim > getIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
Return a grid iterator over all the point with the exception of the ghost part.
Definition: map_grid.hpp:1184
int yes_i_am_grid
it define that it is a grid
Definition: map_grid.hpp:477
T::type T_type
boost::vector that describe the data type
Definition: map_grid.hpp:108
Mem memory_t
Memory traits.
Definition: map_grid.hpp:483
grid_key_d is the key to access any element in the grid
Definition: grid_key.hpp:364
std::vector< size_t > getV()
Get 1D vector with the.
Definition: map_grid.hpp:388
boost::fusion::result_of::at< vtype, boost::mpl::int_< p > >::type type
return a memory_c<...>
Definition: Encap.hpp:170
grid_key_dx_iterator_sub< N > getSubIterator(grid_key_dx< N > &start, grid_key_dx< N > &stop) const
Return a sub-grid iterator.
Definition: grid_sm.hpp:687
size_t getVolume()
Get the volume spanned by this sub-grid iterator.
mem_id LinId(const grid_key_dx< N > &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:354
Implementation of 1-D std::vector like structure.
Definition: map_grid.hpp:94
Packing status object.
Definition: Pack_stat.hpp:49
grid_key_dx_iterator< dim > getIterator() const
Return a grid iterator.
Definition: map_grid.hpp:1168
It copy the properties from one object to another.
encapc< dim, T, Mem > container
Object container for T, it is the return type of get_o it return a object type trough.
Definition: map_grid.hpp:487
void packRequest(std::vector< size_t > &v)
Insert an allocation request.
Definition: map_grid.hpp:203