OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
create_vmpl_sequence.hpp
1 /*
2  * mpl_sequence.hpp
3  *
4  * Set of classes to create an mpl::vector with a filled sequence
5  *
6  * Created on: Aug 27, 2014
7  * Author: Pietro Incardona
8  */
9 
10 #ifndef MPL_SEQUENCE_HPP
11 #define MPL_SEQUENCE_HPP
12 
13 #include <boost/mpl/int.hpp>
14 #include <boost/mpl/reverse.hpp>
15 
16 template<int ...> struct index_tuple_sq{};
17 
27 template<int c,int end>
28 struct exit_impl_sq : boost::mpl::equal_to<boost::mpl::int_<c>,boost::mpl::int_<end>>
29 {};
30 
39 template<int c , int end, bool exit,int ... vars>
41 {
42  typedef typename exit_impl_sq<c,end>::type exit_;
43  typedef typename to_variadic_impl<c+1,end,exit_::value,vars ..., c>::type type;
44 };
45 
46 
48 template<int c, int end, int ... vars>
49 struct to_variadic_impl<c,end,true, vars ...>
50 {
51  typedef index_tuple_sq<vars ...> type;
52 };
53 
68 template<unsigned int N, unsigned int M>
70 {
72  typedef typename exit_impl_sq<N,M>::type exit_;
73 
75  typedef typename to_variadic_impl<N+1,M,exit_::value,N>::type type;
76 };
77 
78 
80 
89 template<int c , int end, int ele, bool exit,int ... vars>
91 {
92  typedef typename exit_impl_sq<c,end-1>::type exit_;
93  typedef typename to_variadic_const_impl<c+1,end,ele,exit_::value,vars ..., ele>::type type;
94 };
95 
96 
98 template<int c, int end, int ele, int ... vars>
99 struct to_variadic_const_impl<c,end,ele,true, vars ...>
100 {
101  typedef boost::mpl::vector<boost::mpl::int_<vars> ...> type;
102 };
103 
117 template<unsigned int N, unsigned int M>
119 {
121  typedef typename exit_impl_sq<N,M>::type exit_;
122 
124  typedef typename to_variadic_const_impl<1,N,M,exit_::value,M>::type type;
125 };
126 
128 
129 template<typename bint, unsigned int ele>
130 struct sum_ele
131 {
132 };
133 
134 template<int op1, unsigned int ele>
135 struct sum_ele<boost::mpl::int_<op1>,ele>
136 {
137  typedef boost::mpl::int_<op1+ele> type;
138 };
139 
140 template<unsigned int ele>
141 struct sum_ele<boost::mpl::na,ele>
142 {
143  typedef boost::mpl::na type;
144 };
145 
146 
147 template <unsigned int ele, typename ... vmpl>
149 {
151  typedef boost::mpl::vector<typename sum_ele<vmpl,ele>::type ...> type;
152 };
153 
154 template <unsigned int ele, typename vmpl>
156 {
157  typedef int type;
158 };
170 template <unsigned int ele, typename ... vars>
171 struct vmpl_sum_constant<ele, boost::mpl::vector<vars ... > >
172 {
174  typedef boost::mpl::vector<typename sum_ele<vars,ele>::type ...> type;
175 };
176 
177 
178 
180 
181 template<int c, int accu, int stop, typename vmpl, bool exit>
183 {
184  typedef typename exit_impl_sq<c,stop>::type exit_;
185  typedef typename boost::mpl::at<vmpl,boost::mpl::int_<c>>::type ele;
186  typedef typename vmpl_reduce_prod_impl<c+1,accu*ele::value,stop,vmpl,exit_::value>::type type;
187 };
188 
189 
191 template<int c, int accu, int stop, typename vmpl>
192 struct vmpl_reduce_prod_impl<c,accu,stop,vmpl,true>
193 {
194  typedef boost::mpl::int_<accu> type;
195 };
196 
197 
198 template<typename vmpl>
200 {
201  typedef typename vmpl_reduce_prod_impl<0,1,(int)vmpl::size::value-1,vmpl,false>::type type;
202 };
203 
204 template<typename vmpl, int stop>
206 {
207  typedef typename vmpl_reduce_prod_impl<0,1,stop,vmpl,false>::type type;
208 };
209 
210 template<typename vmpl>
211 struct vmpl_reduce_prod_stop<vmpl,-1>
212 {
213  typedef typename boost::mpl::int_<1> type;
214 };
215 
217 template<typename vmpl, typename a> __device__ __host__ inline unsigned int Lin_vmpl(a v)
218 {
219  return v*vmpl_reduce_prod_stop<vmpl,((int)vmpl::size::value) - 2>::type::value;
220 }
221 
227 template<typename vmpl, typename a, typename ...lT>
228 __device__ __host__ inline unsigned int Lin_vmpl(a v,lT...t)
229 {
230  return v*vmpl_reduce_prod_stop<vmpl,(int)vmpl::size::value - (int)sizeof...(t) - 2>::type::value + Lin_vmpl<vmpl>(t...);
231 }
232 
234 template<typename vmpl, typename vmpl_off, typename a> __device__ __host__ inline unsigned int Lin_vmpl_off(a v)
235 {
236  return (v + boost::mpl::at<vmpl_off,boost::mpl::int_< ((int)vmpl::size::value) - 1 > >::type::value )*vmpl_reduce_prod_stop<vmpl,(int)vmpl::size::value - 2>::type::value;
237 }
238 
244 template<typename vmpl, typename vmpl_off, typename a, typename ...lT>
245 __device__ __host__ inline unsigned int Lin_vmpl_off(a v,lT...t)
246 {
247  return (v + boost::mpl::at<vmpl_off,boost::mpl::int_<((int)vmpl::size::value) - (int)sizeof...(t) - 1> >::type::value)*vmpl_reduce_prod_stop<vmpl,(int)((int)vmpl::size::value - sizeof...(t) - 2)>::type::value + Lin_vmpl_off<vmpl,vmpl_off>(t...);
248 }
249 
250 #endif
Recursive specialization of to_variadic.
exit_impl_sq< N, M >::type exit_
end condition
exit_impl_sq< N, M >::type exit_
end condition
to_variadic_impl< N+1, M, exit_::value, N >::type type
generate the boost::fusion::vector apply H on each term
Exit condition.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
boost::mpl::vector< typename sum_ele< vmpl, ele >::type ... > type
construct an mpl vector from the variadic
Recursive specialization of to_variadic.
to_variadic_const_impl< 1, N, M, exit_::value, M >::type type
generate the boost::fusion::vector apply H on each term
boost::mpl::vector< typename sum_ele< vars, ele >::type ... > type
construct an mpl vector from the variadic