OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
object_s_di.hpp
1 /*
2  * object_write.hpp
3  *
4  * Created on: Jun 11, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OBJECT_WRITE_HPP_
9 #define OBJECT_WRITE_HPP_
10 
11 
12 #include "for_each_ref.hpp"
13 #include "util/variadic_to_vmpl.hpp"
14 #include "util/copy_compare/meta_copy.hpp"
15 #include <boost/mpl/range_c.hpp>
16 #include <boost/fusion/include/size.hpp>
17 
18 template<typename T>
20 {
21  template<unsigned int T_value, typename v_prp, typename copy_rtype, typename Tsrc, typename Tdst>
22  static inline void copy(const Tsrc & src, Tdst & dst, int sub_id)
23  {
24  meta_copy<typename copy_rtype::value_type>::meta_copy_(src.template get<T_value>(),dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T_value>>::type::value>()[sub_id]);
25  }
26 };
27 
28 template<unsigned int N1, typename T>
30 {
31  template<unsigned int T_value, typename v_prp, typename copy_rtype, typename Tsrc, typename Tdst>
32  static inline void copy(const Tsrc & src, Tdst & dst, int sub_id)
33  {
34  for (int i = 0 ; i < N1 ; i++)
35  {
36  meta_copy<typename T::value_type>::meta_copy_(src.template get<T_value>()[i],dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T_value>>::type::value>()[i][sub_id]);
37  }
38  }
39 };
40 
53 template<typename v_src,typename v_dst, int... prp>
55 {
57  typedef typename to_boost_vmpl<prp...>::type v_prp;
58 
60  const v_src & src;
61 
63  v_dst & dst;
64 
66  size_t sub_id;
67 
74  object_s_di_e_cnk(const v_src & src, v_dst & dst,size_t sub_id)
76  {
77  };
78 
80  template<typename T>
81  void operator()(T& t)
82  {
83  // Remove the reference from the type to copy
84  typedef typename boost::remove_reference<decltype(dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>())>::type copy_rtype;
85 
86  //meta_copy<copy_rtype>::meta_copy_(src.template get<T::value>(),dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>()[sub_id]);
87 
89  }
90 };
91 
92 
105 template<typename v_src,typename v_dst, int... prp>
107 {
109  typedef typename to_boost_vmpl<prp...>::type v_prp;
110 
112  const v_src & src;
113 
115  v_dst & dst;
116 
123  __device__ __host__ object_s_di_e(const v_src & src, v_dst & dst)
124  :src(src),dst(dst)
125  {
126  };
127 
128 #ifdef SE_CLASS1
129 
135  object_s_di_e(const v_src && src, v_dst & dst)
136  :src(src),dst(dst)
137  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
138 #endif
139 
141  template<typename T>
142  __device__ __host__ void operator()(T& t)
143  {
144  // Remove the reference from the type to copy
145  typedef typename boost::remove_reference<decltype(dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>())>::type copy_dtype;
146  typedef typename std::remove_reference<decltype(src.template get<T::value>())>::type copy_stype;
147 
148  meta_copy_d<copy_stype,copy_dtype>::meta_copy_d_(src.template get<T::value>(),dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>());
149  }
150 };
151 
152 
166 template<template<typename,typename> class op, typename v_src,typename v_dst, int... prp>
168 {
170  typedef typename to_boost_vmpl<prp...>::type v_prp;
171 
173  const v_src & src;
174 
176  v_dst & dst;
177 
184  __device__ __host__ object_s_di_e_op(const v_src & src, v_dst & dst)
185  :src(src),dst(dst)
186  {
187  };
188 
189 #ifdef SE_CLASS1
190 
196  object_s_di_e_op(v_src && src, v_dst & dst)
197  :src(src),dst(dst)
198  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
199 #endif
200 
202  template<typename T>
203  __device__ __host__ void operator()(T& t)
204  {
205  // Remove the reference from the type to copy
206  typedef typename boost::remove_reference<decltype(dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>())>::type copy_dtype;
207  typedef typename std::remove_reference<decltype(src.template get<T::value>())>::type copy_stype;
208 
209  meta_copy_op_d<op,copy_stype,copy_dtype>::meta_copy_op_d_(src.template get<T::value>(),dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>());
210  }
211 };
212 
226 template<template<typename,typename> class op, typename v_src,typename v_dst, int... prp>
228 {
230  typedef typename to_boost_vmpl<prp...>::type v_prp;
231 
233  const v_src & src;
234 
236  v_dst & dst;
237 
239  size_t sub_id;
240 
247  object_s_di_e_op_cnk(const v_src & src, v_dst & dst,size_t sub_id)
248  :src(src),dst(dst),sub_id(sub_id)
249  {
250  };
251 
252 #ifdef SE_CLASS1
253 
259  object_s_di_e_op_cnk(v_src && src, v_dst & dst, size_t sub_id)
260  :src(src),dst(dst),sub_id(sub_id)
261  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
262 #endif
263 
265  template<typename T>
266  void operator()(T& t)
267  {
268  // Remove the reference from the type to copy
269  typedef typename boost::remove_reference<decltype(dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>()[sub_id])>::type copy_rtype;
270 
271  meta_copy_op<op,copy_rtype>::meta_copy_op_(src.template get<T::value>(),dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>()[sub_id]);
272  }
273 };
274 
286 template<typename v_src,typename v_dst, int... prp>
288 {
290  typedef typename to_boost_vmpl<prp...>::type v_prp;
291 
293  const v_src & src;
294 
296  v_dst & dst;
297 
304  object_s_di_f(const v_src & src, v_dst & dst)
305  :src(src),dst(dst)
306  {
307  };
308 
309 #ifdef DEBUG
310 
316  object_s_di_f(const v_src && src, v_dst & dst)
317  :src(src),dst(dst)
318  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
319 #endif
320 
322  template<typename T>
323  void operator()(T& t)
324  {
325  typedef typename boost::mpl::at<typename v_dst::type,typename boost::mpl::int_<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>>::type ctype;
326 
327  meta_copy<ctype>::meta_copy_(boost::fusion::at_c<T::value>(src.data),boost::fusion::at_c<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>(dst.data));
328  }
329 };
330 
331 
344 template<template<typename,typename> class op, typename v_src,typename v_dst, int... prp>
346 {
348  typedef typename to_boost_vmpl<prp...>::type v_prp;
349 
351  const v_src & src;
352 
354  v_dst & dst;
355 
362  object_s_di_f_op(const v_src & src, v_dst & dst)
363  :src(src),dst(dst)
364  {
365  };
366 
367 #ifdef DEBUG
368 
374  object_s_di_f_op(v_src && src, v_dst & dst)
375  :src(src),dst(dst)
376  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
377 #endif
378 
380  template<typename T>
381  void operator()(T& t)
382  {
383  typedef typename boost::mpl::at<typename v_dst::type,typename boost::mpl::int_<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>>::type ctype;
384 
385  meta_copy_op<op,ctype>::meta_copy_op_(boost::fusion::at_c<T::value>(src.data),boost::fusion::at_c<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>(dst.data));
386  }
387 };
388 
389 #define OBJ_ENCAP 1
390 #define OBJ_NORMAL 2
391 #define OBJ_ENCAP_CHUNKING 3
392 
401 template<typename v_src, typename v_dst,int type_copy, int... prp>
403 {
410  inline object_s_di(const v_src & vs, v_dst & vd)
411  {
412  std::cerr << "Error object_copy: " << __FILE__ << " " << __LINE__ << "\n";
413  };
414 };
415 
423 template<typename v_src, typename v_dst, int... prp>
424 struct object_s_di<v_src,v_dst,OBJ_NORMAL,prp...>
425 {
432  inline object_s_di(const v_src && vs, v_dst && vd)
433  {
434  object_s_di_f<v_src,v_dst,prp...> obj(vs,vd);
435  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
436  }
437 
444  inline object_s_di(const v_src & vs, v_dst & vd)
445  {
446  object_s_di_f<v_src,v_dst,prp...> obj(vs,vd);
447  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
448  }
449 };
450 
465 template<typename v_src, typename v_dst, int... prp>
466 struct object_s_di<v_src,v_dst,OBJ_ENCAP,prp...>
467 {
474  __host__ __device__ inline object_s_di(const v_src & vs, v_dst && vd)
475  {
476  object_s_di_e<v_src,v_dst,prp...> obj(vs,vd);
477  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,(int)sizeof...(prp)> >(obj);
478  }
479 
486  __host__ __device__ inline object_s_di(const v_src & vs, v_dst & vd)
487  {
488  object_s_di_e<v_src,v_dst,prp...> obj(vs,vd);
489  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
490  }
491 };
492 
493 
494 
495 template<typename v_src, typename v_dst, int... prp>
496 struct object_s_di<v_src,v_dst,OBJ_ENCAP_CHUNKING,prp...>
497 {
504  inline object_s_di(const v_src & vs, v_dst && vd, size_t sub_id)
505  {
506  object_s_di_e_cnk<v_src,v_dst,prp...> obj(vs,vd,sub_id);
507  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
508  }
509 
516  inline object_s_di(const v_src & vs, v_dst & vd, size_t sub_id)
517  {
518  object_s_di_e_cnk<v_src,v_dst,prp...> obj(vs,vd,sub_id);
519  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
520  }
521 };
522 
524 
533 template<template<typename,typename> class op, typename v_src, typename v_dst,int type_copy, int... prp>
535 {
542  inline object_s_di_op(const v_src & vs, v_dst & vd)
543  {
544  std::cerr << "Error object_copy: " << __FILE__ << " " << __LINE__ << "\n";
545  };
546 };
547 
556 template<template<typename,typename> class op, typename v_src, typename v_dst, int... prp>
557 struct object_s_di_op<op,v_src,v_dst,OBJ_NORMAL,prp...>
558 {
565  inline object_s_di_op(const v_src && vs, v_dst && vd)
566  {
567  object_s_di_f_op<op,v_src,v_dst,prp...> obj(vs,vd);
568  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
569  }
570 
577  inline object_s_di_op(const v_src & vs, v_dst & vd)
578  {
579  object_s_di_f_op<op,v_src,v_dst,prp...> obj(vs,vd);
580  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
581  }
582 };
583 
584 
599 template<template<typename,typename> class op, typename v_src, typename v_dst, int... prp>
600 struct object_s_di_op<op, v_src,v_dst,OBJ_ENCAP,prp...>
601 {
608  __device__ __host__ inline object_s_di_op(const v_src & vs, v_dst && vd)
609  {
610  object_s_di_e_op<op,v_src,v_dst,prp...> obj(vs,vd);
611  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
612  }
613 
620  __device__ __host__ inline object_s_di_op(const v_src & vs, v_dst & vd)
621  {
622  object_s_di_e_op<op,v_src,v_dst,prp...> obj(vs,vd);
623  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
624  }
625 };
626 
641 template<template<typename,typename> class op, typename v_src, typename v_dst, int... prp>
642 struct object_s_di_op<op, v_src,v_dst,OBJ_ENCAP_CHUNKING,prp...>
643 {
650  inline object_s_di_op(const v_src & vs, v_dst && vd)
651  {
652  object_s_di_e_op_cnk<op,v_src,v_dst,prp...> obj(vs,vd);
653  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
654  }
655 
662  inline object_s_di_op(const v_src & vs, v_dst & vd, size_t sub_id)
663  {
664  object_s_di_e_op_cnk<op,v_src,v_dst,prp...> obj(vs,vd,sub_id);
665  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
666  }
667 };
668 
669 #endif /* OBJECT_WRITE_HPP_ */
size_t sub_id
element id
Definition: object_s_di.hpp:66
to_boost_vmpl< prp... >::type v_prp
Convert the packed properties into an MPL vector.
It copy the properties from one object to another.
object_s_di_op(const v_src &&vs, v_dst &&vd)
Implementation of the copy with operation.
__device__ __host__ object_s_di_e(const v_src &src, v_dst &dst)
Constructor.
void operator()(T &t)
It call the functor for each member.
to_boost_vmpl< prp... >::type v_prp
Convert the packed properties into an MPL vector.
__device__ static __host__ void meta_copy_(const T &src, T &dst)
copy and object from src to dst
Definition: meta_copy.hpp:60
to_boost_vmpl< prp... >::type v_prp
Convert the packed properties into an MPL vector.
const v_src & src
Source object.
const v_src & src
Source object.
void operator()(T &t)
It call the functor for each member.
Definition: object_s_di.hpp:81
this class is a functor for "for_each" algorithm
static void meta_copy_op_(const T &src, T &dst)
Meta-copy applying an operation.
Definition: meta_copy.hpp:710
__device__ __host__ object_s_di_op(const v_src &vs, v_dst &vd)
Implementation of the copy with operation.
__device__ __host__ object_s_di_op(const v_src &vs, v_dst &&vd)
Implementation of the copy with operation.
object_s_di(const v_src &vs, v_dst &vd, size_t sub_id)
Implementation of the copy.
__host__ __device__ object_s_di(const v_src &vs, v_dst &vd)
Implementation of the copy.
object_s_di_f_op(const v_src &src, v_dst &dst)
Constructor.
v_dst & dst
Destination object.
Definition: object_s_di.hpp:63
to_boost_vmpl< prp... >::type v_prp
Convert the packed properties into an MPL vector.
Definition: object_s_di.hpp:57
const v_src & src
Source object.
Definition: object_s_di.hpp:60
this class is a functor for "for_each" algorithm
object_s_di_f(const v_src &src, v_dst &dst)
Constructor.
object_s_di(const v_src &&vs, v_dst &&vd)
Implementation of the copy.
v_dst & dst
Destination object.
this class is a functor for "for_each" algorithm
void operator()(T &t)
It call the functor for each member.
to_boost_vmpl< prp... >::type v_prp
Convert the packed properties into an MPL vector.
__device__ static __host__ void meta_copy_op_d_(const Tsrc &src, Tdst &dst)
Meta-copy applying an operation.
Definition: meta_copy.hpp:845
__device__ static __host__ void meta_copy_d_(const Tsrc &src, Tdst &dst)
copy and object from src to dst
Definition: meta_copy.hpp:92
v_dst & dst
Destination object.
object_s_di(const v_src &vs, v_dst &vd)
Stub method.
to_boost_vmpl< prp... >::type v_prp
Convert the packed properties into an MPL vector.
It copy the properties from one object to another applying an operation.
object_s_di_op(const v_src &vs, v_dst &vd)
Implementation of the copy with operation.
this class is a functor for "for_each" algorithm
void operator()(T &t)
It call the functor for each member.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
object_s_di(const v_src &vs, v_dst &vd)
Implementation of the copy.
object_s_di_op(const v_src &vs, v_dst &vd)
Stub method.
size_t sub_id
element id
this class is a functor for "for_each" algorithm
Definition: object_s_di.hpp:54
object_s_di(const v_src &vs, v_dst &&vd, size_t sub_id)
Implementation of the copy.
const v_src & src
Source object.
object_s_di_e_op_cnk(const v_src &src, v_dst &dst, size_t sub_id)
Constructor.
__device__ __host__ object_s_di_e_op(const v_src &src, v_dst &dst)
Constructor.
v_dst & dst
Destination object.
const v_src & src
Source object.
__device__ __host__ void operator()(T &t)
It call the functor for each member.
v_dst & dst
Destination object.
__host__ __device__ object_s_di(const v_src &vs, v_dst &&vd)
Implementation of the copy.
const v_src & src
Source object.
v_dst & dst
Destination object.
object_s_di_e_cnk(const v_src &src, v_dst &dst, size_t sub_id)
Constructor.
Definition: object_s_di.hpp:74
object_s_di_op(const v_src &vs, v_dst &&vd)
Implementation of the copy with operation.
object_s_di_op(const v_src &vs, v_dst &vd, size_t sub_id)
Implementation of the copy with operation.
this class is a functor for "for_each" algorithm
__device__ __host__ void operator()(T &t)
It call the functor for each member.