OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
object_si_d.hpp
1/*
2 * object_si_d.hpp
3 *
4 * Created on: May 31, 2015
5 * Author: Pietro Incardona
6 */
7
8#ifndef OBJECT_SI_D_HPP_
9#define OBJECT_SI_D_HPP_
10
11#include "for_each_ref.hpp"
12#include <boost/mpl/range_c.hpp>
13#include <boost/fusion/include/size.hpp>
14
26template<typename v_src,typename v_dst, int... prp>
28{
30 typedef typename to_boost_vmpl<prp...>::type v_prp;
31
33 const v_src & src;
34
36 v_dst & dst;
37
44 __device__ __host__ object_si_d_e(const v_src & src, v_dst & dst)
45 :src(src),dst(dst)
46 {
47 };
48
50 template<typename T>
51 __device__ __host__ void operator()(T& t)
52 {
53 typedef decltype(src.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>()) stype;
54
55 // In case of layout switch use this
56 //meta_copy_d<stype,dtype>::meta_copy_d_(src.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>(),dst.template get<T::value>());
57
58 meta_copy<typename std::remove_reference<stype>::type>::meta_copy_(src.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>(),dst.template get<T::value>());
59 }
60};
61
62template<typename T>
64{
65 template<unsigned int T_value, typename v_prp, typename ctype, typename Tsrc, typename Tdst>
66 static inline void copy(const Tsrc & src, Tdst & dst, int sub_id)
67 {
68 meta_copy<ctype>::meta_copy_(src.template get<boost::mpl::at<v_prp,boost::mpl::int_<T_value>>::type::value>()[sub_id],dst.template get<T_value>());
69 }
70};
71
72template<unsigned int N1, typename T>
74{
75 template<unsigned int T_value, typename v_prp, typename ctype, typename Tsrc, typename Tdst>
76 static inline void copy(const Tsrc & src, Tdst & dst, int sub_id)
77 {
78 for (int i = 0 ; i < N1 ; i++)
79 {
80 meta_copy<T>::meta_copy_(src.template get<boost::mpl::at<v_prp,boost::mpl::int_<T_value>>::type::value>()[i][sub_id],dst.template get<T_value>()[i]);
81 }
82 }
83};
84
96template<typename v_src,typename v_dst, int... prp>
98{
99 // Convert the packed properties into an MPL vector
100 typedef typename to_boost_vmpl<prp...>::type v_prp;
101
102 // Source object
103 const v_src & src;
104
105 // Destination object
106 v_dst & dst;
107
108 // Element id
109 size_t sub_id;
110
117 object_si_d_e_cnk(const v_src & src, size_t sub_id, v_dst & dst)
118 :src(src),dst(dst),sub_id(sub_id)
119 {
120 };
121
123 template<typename T>
124 void operator()(T& t)
125 {
126 typedef typename boost::mpl::at<typename v_dst::type,typename boost::mpl::int_<T::value>>::type ctype;
127
128 object_si_d_e_cnk_meta_copy_selector<ctype>::template copy<T::value,v_prp,ctype>(src,dst,sub_id);
129 }
130};
131
143template<typename v_src,typename v_dst, int... prp>
145{
146 // Convert the packed properties into an MPL vector
147 typedef typename to_boost_vmpl<prp...>::type v_prp;
148
149 // Source object
150 const v_src & src;
151
152 // Destination object
153 v_dst & dst;
154
161 object_si_d_f(const v_src & src, v_dst & dst)
162 :src(src),dst(dst)
163 {
164 };
165
167 template<typename T>
168 void operator()(T& t)
169 {
170 typedef typename boost::mpl::at<typename v_dst::type,typename boost::mpl::int_<T::value>>::type ctype;
171
172 meta_copy<ctype>::meta_copy_(boost::fusion::at_c<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>(src.data),boost::fusion::at_c<T::value>(dst.data));
173 }
174};
175
176#define OBJ_ENCAP 1
177#define OBJ_NORMAL 2
178#define OBJ_ENCAP_CHUNKING 3
179
188template<typename v_src, typename v_dst,int type_copy, int... prp>
190{
191 inline object_si_d(const v_src & vs, v_dst & vd)
192 {
193 std::cerr << "Error object_copy: " << __FILE__ << " " << __LINE__ << "\n";
194 };
195};
196
206template<typename v_src, typename v_dst, int... prp>
207struct object_si_d<v_src,v_dst,OBJ_NORMAL,prp...>
208{
209 inline object_si_d(const v_src && vs, v_dst && vd)
210 {
211 object_si_d_f<v_src,v_dst,prp...> obj(vs,vd);
212 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,v_dst::max_prop> >(obj);
213 }
214
215 inline object_si_d(const v_src & vs, v_dst & vd)
216 {
217 object_si_d_f<v_src,v_dst,prp...> obj(vs,vd);
218 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,v_dst::max_prop> >(obj);
219 }
220};
221
236template<typename v_src, typename v_dst, int... prp>
237struct object_si_d<v_src,v_dst,OBJ_ENCAP,prp...>
238{
239 __device__ __host__ inline object_si_d(const v_src && vs, v_dst && vd)
240 {
241 object_si_d_e<v_src,v_dst,prp...> obj(vs,vd);
242 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,v_dst::max_prop> >(obj);
243 }
244
245 __device__ __host__ inline object_si_d(const v_src & vs, v_dst & vd)
246 {
247 object_si_d_e<v_src,v_dst,prp...> obj(vs,vd);
248 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,v_dst::max_prop> >(obj);
249 }
250};
251
252
267template<typename v_src, typename v_dst, int... prp>
268struct object_si_d<v_src,v_dst,OBJ_ENCAP_CHUNKING,prp...>
269{
270 inline object_si_d(const v_src && vs, size_t sub_id, v_dst && vd)
271 {
272 object_si_d_e_cnk<v_src,v_dst,prp...> obj(vs,sub_id,vd);
273 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,v_dst::max_prop> >(obj);
274 }
275
276 inline object_si_d(const v_src & vs, size_t sub_id, v_dst & vd)
277 {
278 object_si_d_e_cnk<v_src,v_dst,prp...> obj(vs,sub_id,vd);
279 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,v_dst::max_prop> >(obj);
280 }
281};
282
283template<typename v_src, typename v_dst>
284struct object_si_d<v_src,v_dst,OBJ_ENCAP>
285{
286 __device__ __host__ inline object_si_d(const v_src && vs, v_dst && vd)
287 {
288 }
289
290 __device__ __host__ inline object_si_d(const v_src & vs, v_dst & vd)
291 {
292 }
293};
294
295#endif /* VECTOR_PROP_COPY_HPP_ */
This class copy general objects.
Definition meta_copy.hpp:53
__device__ static __host__ void meta_copy_(const T &src, T &dst)
copy and object from src to dst
Definition meta_copy.hpp:60
this class is a functor for "for_each" algorithm
void operator()(T &t)
It call the functor for each member.
object_si_d_e_cnk(const v_src &src, size_t sub_id, v_dst &dst)
Constructor.
this class is a functor for "for_each" algorithm
v_dst & dst
Destination object.
__device__ __host__ 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.
const v_src & src
Source object.
__device__ __host__ object_si_d_e(const v_src &src, v_dst &dst)
Constructor.
this class is a functor for "for_each" algorithm
object_si_d_f(const v_src &src, v_dst &dst)
Constructor.
void operator()(T &t)
It call the functor for each member.
It copy the properties from one object to another.