OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
copy_general.hpp
1 /*
2  * aggregate_copy.hpp
3  *
4  * Created on: Oct 31, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_UTIL_COPY_GENERAL_HPP_
9 #define OPENFPM_DATA_SRC_UTIL_COPY_GENERAL_HPP_
10 
11 #include "util/common.hpp"
12 #include "util/util_debug.hpp"
13 #include "copy_compare_aggregates.hpp"
14 #include "util/for_each_ref.hpp"
15 #include <boost/mpl/range_c.hpp>
16 #include <iostream>
17 #include "util/cuda_util.hpp"
18 #include "data_type/aggregate.hpp"
19 
26 template<typename Tdst, typename Tsrc>
27 struct max_
28 {
35  static inline void operation(Tdst & dst, const Tsrc & src)
36  {
37  dst = (src > dst)?src:dst;
38  }
39 };
40 
47 template<typename Tdst, typename Tsrc>
48 struct min_
49 {
56  static inline void operation(Tdst & dst, const Tsrc & src)
57  {
58  dst = (src < dst)?src:dst;
59  }
60 };
61 
68 template<typename Tdst, typename Tsrc>
69 struct add_
70 {
77  __device__ __host__ static inline void operation(Tdst & dst, const Tsrc & src)
78  {
79  dst += src;
80  }
81 };
82 
83 #if defined(__clang__) && !defined(CUDA_ON_CPU)
84 
85 template<typename Tsrc>
86 __host__ Tsrc atomicAdd(Tsrc * ptr, Tsrc value)
87 {
88  std::cout << __FILE__ << ":" << __LINE__ << "Error: atomicAdd is supported only in device code not host" << std::endl;
89  return 0;
90 }
91 #endif
92 
99 template<typename Tdst, typename Tsrc>
101 {
108  __device__ __host__ static inline void operation(Tdst & dst, const Tsrc & src)
109  {
110  atomicAdd(&dst,src);
111  }
112 };
113 
120 template<typename Tdst, typename Tsrc>
121 struct replace_
122 {
129  static inline void operation(Tdst & dst, const Tsrc & src)
130  {
131  dst = src;
132  }
133 };
134 
141 template<typename Tdst, typename Tsrc>
142 struct merge_
143 {
150  static inline void operation(Tdst & dst, const Tsrc & src)
151  {
152  dst.add(src);
153  }
154 };
155 
161 template<typename T, unsigned int agg=2 * is_aggregate<T>::value + std::is_copy_assignable<T>::value>
163 {
170  inline copy_general(const T & src, T & dst)
171  {
172 #ifndef DISABLE_ALL_RTTI
173  std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " " << demangle(typeid(T).name()) << " does not have an operator= and is not an aggregate or an openfpm native structure, copy is not possible" << "\n";
174 #endif
175  }
176 };
177 
179 template<typename T>
180 struct copy_general<T,1>
181 {
188  __device__ __host__ inline copy_general(const T & src, T & dst)
189  {
190  dst = src;
191  }
192 };
193 
195 template<typename T>
196 struct copy_general<T,2>
197 {
204  inline copy_general(const T & src, T & dst)
205  {
206  copy_aggregate<T> cp(src,dst);
207 
208  boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::max_prop>>(cp);
209  }
210 };
211 
213 template<typename T>
214 struct copy_general<T,3>
215 {
222  inline copy_general(const T & src, T & dst)
223  {
224  dst = src;
225  }
226 };
227 
229 
235 template<template<typename,typename> class op, typename T, unsigned int agg=2 * is_aggregate<T>::value + std::is_copy_assignable<T>::value>
237 {
244  inline copy_general_op(const T & src, T & dst)
245  {
246 #ifndef DISABLE_ALL_RTTI
247  std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " " << demangle(typeid(T).name()) << " does not have an operator " << demangle(typeid(op<T,T>).name()) << "defined" << std::endl;
248 #endif
249  }
250 };
251 
253 template<template<typename,typename> class op,typename T>
254 struct copy_general_op<op,T,1>
255 {
262  __device__ __host__ inline copy_general_op(const T & src, T & dst)
263  {
264  op<T,T>::operation(dst,src);
265  }
266 };
267 
269 template<template<typename,typename> class op, typename T>
270 struct copy_general_op<op,T,3>
271 {
278  __device__ __host__ inline copy_general_op(const T & src, T & dst)
279  {
280  copy_aggregate_op<op,T> cp(src,dst);
281 
282  boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::max_prop>>(cp);
283  }
284 };
285 
286 
287 #endif /* OPENFPM_DATA_SRC_UTIL_COPY_GENERAL_HPP_ */
__device__ __host__ copy_general(const T &src, T &dst)
copy objects that has an operator= (implicit or explicit)
__device__ static __host__ void operation(Tdst &dst, const Tsrc &src)
Defition of the add operation.
Structure to copy aggregates.
__device__ __host__ copy_general_op(const T &src, T &dst)
copy objects that are aggregates
structure to copy aggregates applying an operation
This structure define the operation add to use with copy general.
This structure define the operation add to use with copy general.
structure to copy aggregates
This structure define the operation add to use with copy general.
static void operation(Tdst &dst, const Tsrc &src)
Defition of the add operation.
Structure to copy aggregates applying an operation.
static void operation(Tdst &dst, const Tsrc &src)
Defition of the add operation.
copy_general(const T &src, T &dst)
copy objects that are aggregates but define an operator=
static void operation(Tdst &dst, const Tsrc &src)
Defition of the replace operation.
copy_general_op(const T &src, T &dst)
Specialization when there is unknown copy method.
This structure define the operation add to use with copy general.
static void operation(Tdst &dst, const Tsrc &src)
Defition of the add operation.
copy_general(const T &src, T &dst)
Specialization when there is unknown copy method.
__device__ __host__ copy_general_op(const T &src, T &dst)
copy objects that has an operator= (implicit or explicit)
__device__ static __host__ void operation(Tdst &dst, const Tsrc &src)
Defition of the add operation.
This structure define the operation add to use with copy general.
This structure define the operation add to use with copy general.
copy_general(const T &src, T &dst)
copy objects that are aggregates