OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
vector_dist_operators.hpp
1/*
2 * vector_dist_operators.hpp
3 *
4 * Created on: Jun 11, 2016
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_HPP_
9#define OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_HPP_
10
11#include "Vector/vector_dist.hpp"
12#include "Vector/vector_dist_subset.hpp"
13#include "lib/pdata.hpp"
14#include "cuda/vector_dist_operators_cuda.cuh"
15
16#define PROP_CUSTOM (unsigned int)-2
17
18#define VECT_SUM 1
19#define VECT_SUB 2
20#define VECT_MUL 3
21#define VECT_DIV 4
22
23#define VECT_APPLYKER_IN 7
24#define VECT_APPLYKER_OUT 8
25#define VECT_APPLYKER_REDUCE 9
26#define VECT_APPLYKER_IN_GEN 10
27#define VECT_APPLYKER_OUT_GEN 11
28#define VECT_APPLYKER_REDUCE_GEN 12
29#define VECT_APPLYKER_IN_SIM 13
30#define VECT_APPLYKER_OUT_SIM 14
31#define VECT_APPLYKER_REDUCE_SIM 15
32
33#define VECT_APPLYKER_IN_GEN_SORT 16
34#define VECT_APPLYKER_IN_SORT 17
35#define VECT_APPLYKER_IN_SIM_SORT 18
36
37#define VECT_NORM 56
38#define VECT_NORM2 57
39#define VECT_ABS 58
40#define VECT_EXP 59
41#define VECT_EXP2 60
42#define VECT_EXPM1 61
43#define VECT_LOG 62
44#define VECT_LOG10 63
45#define VECT_LOG2 64
46#define VECT_LOG1P 65
47#define VECT_SQRT 67
48#define VECT_CBRT 68
49#define VECT_SIN 69
50#define VECT_COS 70
51#define VECT_TAN 71
52#define VECT_ASIN 72
53#define VECT_ACOS 73
54#define VECT_ATAN 74
55#define VECT_SINH 75
56#define VECT_COSH 76
57#define VECT_TANH 77
58#define VECT_ASINH 78
59#define VECT_ACOSH 79
60#define VECT_ATANH 80
61#define VECT_ERF 81
62#define VECT_ERFC 82
63#define VECT_TGAMMA 83
64#define VECT_LGAMMA 84
65#define VECT_CEIL 85
66#define VECT_FLOOR 86
67#define VECT_TRUNC 87
68#define VECT_ROUND 88
69#define VECT_NEARBYINT 89
70#define VECT_RINT 90
71#define VECT_PMUL 91
72#define VECT_SUB_UNI 92
73#define VECT_SUM_REDUCE 93
74#define VECT_COMP 94
75#define VECT_NORM_INF 95
76
77
78#define VECT_DCPSE 100
79#define VECT_DCPSE_V 101
80#define VECT_DCPSE_V_SUM 102
81#define VECT_DCPSE_V_DOT 103
82#define VECT_DCPSE_V_DIV 104
83#define VECT_DCPSE_V_CURL2D 105
84#define VECT_COPY_1_TO_N 300
85#define VECT_COPY_N_TO_N 301
86#define VECT_COPY_N_TO_1 302
87#define VECT_PMUL 91
88#define VECT_SUB_UNI 92
89
90
91
92
93template<bool cond, typename exp1, typename exp2>
95{
96 typedef typename exp2::vtype vtype;
97
98 static auto getVector(const exp1 & o1, const exp2 & o2) -> decltype(o2.getVector())
99 {
100 return o2.getVector();
101 }
102};
103
104template<typename exp1, typename exp2>
105struct first_or_second<true,exp1,exp2>
106{
107 typedef typename exp1::vtype vtype;
108
109 static auto getVector(const exp1 & o1, const exp2 & o2) -> decltype(o1.getVector())
110 {
111 return o1.getVector();
112 }
113};
114
115template<typename T, typename Sfinae = void>
116struct has_vtype: std::false_type {};
117
127template<typename T>
128struct has_vtype<T, typename Void<typename T::vtype>::type> : std::true_type
129{};
130
131
132
133
143template<typename ObjType, typename Sfinae = void>
144struct has_init: std::false_type {};
145
146template<typename ObjType>
147struct has_init<ObjType, typename Void<typename ObjType::has_init>::type> : std::true_type
148{};
149
155template <typename T, bool has_init = has_init<T>::value >
157{
159 static inline void call(T & r_exp)
160 {
161 r_exp.init();
162 }
163};
164
170template <typename T>
171struct call_init_if_needed<T,false>
172{
174 static inline void call(T & r_exp)
175 {
176 }
177};
178
179
180
187template <typename exp1, typename exp2, unsigned int op>
189{
190
191};
192
193template<typename v1_type, typename v2_type>
195{
196 typedef v1_type type;
197
198 template<typename exp1, typename exp2>
199 static const type & getVector(const exp1 & o1, const exp2 & o2)
200 {
201 return o1.getVector();
202 }
203
204 template<typename exp1>
205 static const type & getVector(const exp1 & o1)
206 {
207 return o1.getVector();
208 }
209};
210
211
212template<typename v2_type>
213struct vector_result<void,v2_type>
214{
215 typedef v2_type type;
216
217 template<typename exp1, typename exp2>
218 static const type & getVector(const exp1 & o1, const exp2 & o2)
219 {
220 return o2.getVector();
221 }
222
223 template<typename exp2>
224 static const type & getVector(exp2 & o2)
225 {
226 return o2.getVector();
227 }
228};
229
230template<typename NN1_type, typename NN2_type>
232{
233 typedef NN1_type type;
234
235 template<typename exp1, typename exp2>
236 static type * getNN(exp1 & o1, exp2 & o2)
237 {
238 return o1.getNN();
239 }
240
241 template<typename exp1>
242 static type * getNN(exp1 & o1)
243 {
244 return o1.getNN();
245 }
246};
247
248
249template<typename NN2_type>
250struct nn_type_result<void,NN2_type>
251{
252 typedef NN2_type type;
253
254 template<typename exp1, typename exp2>
255 static type * getNN(exp1 & o1, exp2 & o2)
256 {
257 return o2.getNN();
258 }
259
260 template<typename exp2>
261 static type * getNN(exp2 & o2)
262 {
263 return o2.getNN();
264 }
265};
266
267template<bool s1, bool s2>
269{
270 typedef boost::mpl::bool_<s1 | s2> type;
271};
272
279template <typename exp1, typename exp2>
280class vector_dist_expression_op<exp1,exp2,VECT_SUM>
281{
283 const exp1 o1;
284
286 const exp2 o2;
287
288public:
289
291 typedef typename exp1::is_ker is_ker;
292
294 typedef typename first_or_second<has_vtype<exp1>::value,exp1,exp2>::vtype vtype;
295
297 typedef typename vector_is_sort_result<exp1::is_sort::value,exp2::is_sort::value>::type is_sort;
298
300 typedef typename nn_type_result<typename exp1::NN_type,typename exp2::NN_type>::type NN_type;
301
303 inline vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
304 :o1(o1),o2(o2)
305 {}
306
312 inline NN_type * getNN() const
313 {
315 }
316
322 inline void init() const
323 {
324 o1.init();
325 o2.init();
326 }
327
335 template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) + o2.value(vect_dist_key_dx()))>::type >
336 __device__ __host__ inline r_type value(const vect_dist_key_dx & key) const
337 {
338 return o1.value(key) + o2.value(key);
339 }
340
341 template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
342 inline void value_nz(pmap_type & p_map, const vect_dist_key_dx & key, unordered_map_type & cols, coeff_type & coeff, unsigned int comp) const
343 {
344 o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff, comp);
345 o2.template value_nz<Sys_eqs>(p_map,key,cols,coeff, comp);
346 }
347
355 const vtype & getVector()
356 {
357 return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
358 }
359
367 const vtype & getVector() const
368 {
369 return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
370 }
371
379 template<typename r_type=typename std::remove_reference<decltype(o1.value(0) + o2.value(0))>::type >
380 __device__ __host__ inline r_type value(const unsigned int & key) const
381 {
382 return o1.value(key) + o2.value(key);
383 }
384
385};
386
393template <typename exp1, typename exp2>
395{
397 const exp1 o1;
398
400 const exp2 o2;
401
402public:
403
405 typedef typename first_or_second<has_vtype<exp1>::value,exp1,exp2>::vtype vtype;
406
407 typedef typename exp1::is_ker is_ker;
408
410 typedef typename vector_is_sort_result<exp1::is_sort::value,exp2::is_sort::value>::type is_sort;
411
413 typedef typename nn_type_result<typename exp1::NN_type,typename exp2::NN_type>::type NN_type;
414
416 inline vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
417 :o1(o1),o2(o2)
418 {}
419
425 inline NN_type * getNN() const
426 {
428 }
429
430
436 inline void init() const
437 {
438 o1.init();
439 o2.init();
440 }
441
449 template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) - o2.value(vect_dist_key_dx()))>::type >
450 inline r_type value(const vect_dist_key_dx & key) const
451 {
452 return o1.value(key) - o2.value(key);
453 }
454
462 template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) - o2.value(vect_dist_key_dx()))>::type >
463 __device__ __host__ inline r_type value(const unsigned int & key) const
464 {
465 return o1.value(key) - o2.value(key);
466 }
467
475 const vtype & getVector()
476 {
477 return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
478 }
479
487 const vtype & getVector() const
488 {
489 return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
490 }
491
492 template<typename Sys_eqs,typename pmap_type, typename unordered_map_type, typename coeff_type>
493 inline void value_nz(pmap_type & p_map, const vect_dist_key_dx & key, unordered_map_type & cols, coeff_type & coeff, unsigned int comp) const
494 {
495 o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff,comp);
496 coeff_type tmp = -coeff;
497 o2.template value_nz<Sys_eqs>(p_map,key,cols,tmp,comp);
498 }
499};
500
507template <typename exp1, typename exp2>
508class vector_dist_expression_op<exp1,exp2,VECT_MUL>
509{
511 const exp1 o1;
512
514 const exp2 o2;
515
516public:
517
519 typedef typename first_or_second<has_vtype<exp1>::value,exp1,exp2>::vtype vtype;
520
521 typedef typename exp1::is_ker is_ker;
522
524 typedef typename vector_is_sort_result<exp1::is_sort::value,exp2::is_sort::value>::type is_sort;
525
527 typedef typename nn_type_result<typename exp1::NN_type,typename exp2::NN_type>::type NN_type;
528
530 vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
531 :o1(o1),o2(o2)
532 {}
533
539 inline void init() const
540 {
541 o1.init();
542 o2.init();
543 }
544
552 template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) * o2.value(vect_dist_key_dx()))>::type >
553 __device__ __host__ inline r_type value(const vect_dist_key_dx & key) const
554 {
555 return o1.value(key) * o2.value(key);
556 }
557
558 template<typename Sys_eqs,typename pmap_type, typename unordered_map_type, typename coeff_type>
559 inline void value_nz(pmap_type & p_map, const vect_dist_key_dx & key, unordered_map_type & cols, coeff_type & coeff, unsigned int comp) const
560 {
561 //o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff,comp);
562 auto coeff_tmp = o1.value(key) * coeff;
563 o2.template value_nz<Sys_eqs>(p_map,key,cols,coeff_tmp,comp);
564 }
565
573 const vtype & getVector()
574 {
575 return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
576 }
577
585 const vtype & getVector() const
586 {
587 return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
588 }
589
597 template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) * o2.value(vect_dist_key_dx()))>::type >
598 __device__ __host__ inline r_type value(const unsigned int & key) const
599 {
600 return o1.value(key) * o2.value(key);
601 }
602};
603
610template <typename exp1, typename exp2>
612{
614 const exp1 o1;
615
617 const exp2 o2;
618
619public:
620
622 typedef typename first_or_second<has_vtype<exp1>::value,exp1,exp2>::vtype vtype;
623
624 typedef typename exp1::is_ker is_ker;
625
627 typedef typename vector_is_sort_result<exp1::is_sort::value,exp2::is_sort::value>::type is_sort;
628
630 typedef typename nn_type_result<typename exp1::NN_type,typename exp2::NN_type>::type NN_type;
631
633 vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
634 :o1(o1),o2(o2)
635 {}
636
642 inline NN_type * getNN() const
643 {
645 }
646
647
653 inline void init() const
654 {
655 o1.init();
656 o2.init();
657 }
658
666 template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) / o2.value(vect_dist_key_dx()))>::type > inline r_type value(const vect_dist_key_dx & key) const
667 {
668 return o1.value(key) / o2.value(key);
669 }
670
671 template<typename Sys_eqs,typename pmap_type, typename unordered_map_type, typename coeff_type>
672 inline void value_nz(pmap_type & p_map, const vect_dist_key_dx & key, unordered_map_type & cols, coeff_type & coeff, unsigned int comp) const
673 {
674 std::cout << __FILE__ << ":" << __LINE__ << " You are trying to divide by an operator, this is not possible " << std::endl;
675 }
676
684 const vtype & getVector()
685 {
686 return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
687 }
688
696 const vtype & getVector() const
697 {
698 return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
699 }
700
708 template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) / o2.value(vect_dist_key_dx()))>::type >
709 __device__ __host__ inline r_type value(const unsigned int & key) const
710 {
711 return o1.value(key) / o2.value(key);
712 }
713};
714
715
720template <typename exp1>
722{
724 const exp1 o1;
725
726public:
727
728
729 typedef typename exp1::is_ker is_ker;
730
732 typedef typename vector_result<typename exp1::vtype,void>::type vtype;
733
735 typedef typename vector_is_sort_result<exp1::is_sort::value,false>::type is_sort;
736
738 typedef typename nn_type_result<typename exp1::NN_type,void>::type NN_type;
739
742 :o1(o1)
743 {}
744
750 inline NN_type * getNN() const
751 {
753 }
754
760 const vtype & getVector()
761 {
763 }
764
766 inline void init() const
767 {
768 o1.init();
769 }
770
778 const vtype & getVector() const
779 {
780 return o1.getVector();
781 }
782
783
785 template<typename r_type=typename std::remove_reference<decltype(-(o1.value(vect_dist_key_dx(0))))>::type >
786 __device__ __host__ inline r_type value(const vect_dist_key_dx & key) const
787 {
788 return -(o1.value(key));
789 }
790
791 template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
792 inline void value_nz(pmap_type & p_map, const vect_dist_key_dx & key, unordered_map_type & cols, coeff_type & coeff, unsigned int comp) const
793 {
794 coeff_type coeff_tmp = -coeff;
795 o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff_tmp, comp);
796 }
798 template<typename r_type=typename std::remove_reference<decltype(-(o1.value(vect_dist_key_dx(0))))>::type >
799 __device__ __host__ inline r_type value(const unsigned int & key) const
800 {
801 return -(o1.value(key));
802 }
803};
804
809template<int impl, bool vect_ker>
811{
812 typedef boost::mpl::int_<impl> type;
813};
814
815template<>
817{
818 typedef boost::mpl::int_<-1> type;
819};
820
821template<>
823{
824 typedef boost::mpl::int_<-1> type;
825};
826
830template<bool cond>
832{
833 template<bool cond_, typename v_type, typename exp_type>
834 static void compute(v_type &v,exp_type &v_exp)
836 ::compute_expr(v,v_exp);}
837};
838
839template<unsigned int prp, typename vector>
841
842template<typename v_exp>
844{
845 template<typename T>
846 static auto transform(T & v) -> decltype(v)
847 {
848 return v;
849 }
850};
851
852template<typename T>
853struct transform_if_temporal<vector_dist_expression<0,openfpm::vector_gpu<aggregate<T>>>>
854{
855 template<typename T_>
856 static auto transform(T_ & v) -> decltype(v.getVector().toKernel())
857 {
858 return v.getVector().toKernel();
859 }
860};
861
862
863template<>
865{
866 template<bool cond, typename v_type, typename exp_type>
867 static void compute(v_type &v, exp_type &v_exp)
868 { auto v_ker=v.toKernel();
869 auto v_exp_transformed = transform_if_temporal<typename std::remove_const<exp_type>::type>::transform(v_exp);
871 ::compute_expr(v_ker,v_exp_transformed);}
872};
873
874template<typename vector, bool is_ker = has_vector_kernel<vector>::type::value>
876{
877 typedef vector& type;
878};
879
880template<typename vector>
882{
883 typedef vector type;
884};
885
886template<typename vector>
888{
889 vector v;
890
891 v_mem_mutable(vector & v)
892 :v(v)
893 {}
894};
895
896
897
904template<unsigned int prp, typename vector>
906{
909
911
912public:
913
914 typedef typename has_vector_kernel<vector>::type is_ker;
915
917 typedef vector vtype;
918
920 typedef boost::mpl::bool_<false> is_sort;
921
923 typedef void NN_type;
924
926 static const unsigned int prop = prp;
927
928 int var_id = 0;
929
930 void setVarId(int var_id)
931 {
932 this->var_id = var_id;
933 }
934
937 :v(v),vdl(NULL)
938 {}
939
942 {
943 if (vdl != NULL)
944 {vdl->remove(v.v);}
945 }
946
952 inline void * getNN() const
953 {
954 return NULL;
955 }
956
964 __device__ __host__ const vector & getVector() const
965 {
966 return v.v;
967 }
968
976 __device__ __host__ vector & getVector()
977 {
978 return v.v;
979 }
980
987 {
988 vdkl.add(v.v,is_sort);
989 vdl = &vdkl;
990 }
991
997 inline void init() const
998 {}
999
1007 __host__ __device__ inline auto value(const vect_dist_key_dx & k) const -> decltype(pos_or_propR<vector,prp>::value(v.v,k))
1008 {
1010 }
1011
1019 __host__ __device__ inline auto value(const vect_dist_key_dx & k) -> decltype(pos_or_propR<vector,prp>::value(v.v,k))
1020 {
1022 }
1023
1031 __host__ __device__ inline auto value(const unsigned int & k) const -> decltype(pos_or_propR<vector,prp>::value(v.v,k))
1032 {
1034 }
1035
1043 __host__ __device__ inline auto value(const unsigned int & k) -> decltype(pos_or_propR<vector,prp>::value(v.v,k))
1044 {
1046 }
1047
1048 inline auto get(const vect_dist_key_dx & key) const -> decltype(value(key))
1049 {
1050 return this->value(key);
1051 }
1052
1060 template<unsigned int prp2> vector & operator=(const vector_dist_expression<prp2,vector> & v_exp)
1061 {
1062 if (v_exp.getVector().isSubset() == true)
1063 {
1064 std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1065 return v.v;
1066 }
1067
1069 {
1072 ::compute_expr(v.v,v_exp);
1073 }
1074 else
1075 {
1078 ::compute_expr(v.v,v_exp);
1079 }
1080
1081 return v.v;
1082 }
1083
1091 template<typename T,typename memory,template <typename> class layout_base > vector & operator=(const vector_dist_expression<0,openfpm::vector<aggregate<T>, memory, layout_base>> & v_exp)
1092 {
1093 //vector_dist_op_compute_op<prp,false,vector_dist_expression_comp_sel<comp_host,has_vector_kernel<vector>::type::value>::type::value>
1094 //::compute_expr(v.v,v_exp);
1097 ::compute_expr(v.v,v_exp);
1098
1099
1100 return v.v;
1101 }
1102
1110 template<typename T> vector & operator=(const vector_dist_expression<0,openfpm::vector_gpu<aggregate<T>>> & v_exp)
1111 {
1114 ::compute_expr(v.v,v_exp.getVector().toKernel());
1115 //constexpr bool cond=has_vector_kernel<vector>::type::value || std::is_same<vector,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value;
1116 //vector_dist_expression_comp_proxy_sel<!std::is_same<vector,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value>::template compute<cond>(v.v,v_exp);
1117
1118
1119 return v.v;
1120 }
1121
1129 template<typename exp1, typename exp2, unsigned int op>
1131 {
1132 if (v_exp.getVector().isSubset() == true)
1133 {
1134 std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1135 return v.v;
1136 }
1137
1139 {
1144 ::compute_expr(v.v,v_exp);
1145 }
1146 else
1147 {
1152 ::compute_expr(v.v,v_exp);
1153 }
1154
1155 return v.v;
1156 }
1157
1165 vector & operator=(double d)
1166 {
1168 {
1170 false,
1173 ::compute_const(v.v,d);
1174 }
1175 else
1176 {
1178 false,
1181 ::compute_const(v.v,d);
1182 }
1183
1184 return v.v;
1185 }
1186
1187
1188 template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
1189 inline void value_nz(pmap_type & p_map, const vect_dist_key_dx & key, unordered_map_type & cols, coeff_type & coeff, unsigned int comp) const
1190 {
1191 cols[p_map. template getProp<0>(key)*Sys_eqs::nvar + var_id + comp] += coeff;
1192 }
1193
1194 inline vector_dist_expression_op<vector_dist_expression<prp,vector>,boost::mpl::int_<1>,VECT_COMP> operator[](int comp)
1195 {
1196 int comp_n[1];
1197
1198 comp_n[0] = comp;
1199
1200 vector_dist_expression_op<vector_dist_expression<prp,vector>,boost::mpl::int_<1>,VECT_COMP> v_exp(*this,comp_n,var_id);
1201
1202 return v_exp;
1203 }
1204};
1205
1212template<typename vector_type>
1214{
1217 typedef typename boost::mpl::at<typename vector_type::value_type::type,boost::mpl::int_<0>>::type T;
1219 mutable vector v;
1220
1221public:
1222
1223 typedef T * iterator;
1224 typedef const T * const_iterator;
1225
1226 typedef typename has_vector_kernel<vector>::type is_ker;
1227
1229 typedef vector vtype;
1230
1232 typedef T value_type;
1233
1235 typedef boost::mpl::bool_<false> is_sort;
1236
1238 typedef void NN_type;
1239
1241 static const unsigned int prop = 0;
1242
1243 int var_id = 0;
1244
1245 void setVarId(int var_id)
1246 {
1247 this->var_id = var_id;
1248 }
1249
1251 iterator begin()
1252 { return &v.template get<0>(0); }
1253
1254 const_iterator begin() const
1255 { return &v.template get<0>(0); }
1256
1257 iterator end()
1258 { return &v.template get<0>(v.size()-1)+1; }
1259
1260 const_iterator end() const
1261 { return &v.template get<0>(v.size()-1)+1; }
1262
1263 size_t size() const
1264 { return v.size(); }
1265
1266 void resize(size_t n)
1267 {
1268 // Here
1269
1270 v.resize(n);
1271 }
1272
1273/* T * begin() {
1274 return &v.template get<0>(0);
1275 }
1276
1277 T * end() {
1278 return &v.template get<0>(v.size()-1);
1279 }*/
1280
1281 // ... [ implement container interface ]
1282//]
1283 //const double & operator[]( const size_t n ) const
1284 //{ return m_v[n]; }
1285
1286 //double & operator[]( const size_t n )
1287 //{ return m_v[n]; }
1288
1289
1291
1293 {}
1294
1295 template<unsigned int prp2, typename vector2>
1297 {
1298 this->operator=(v_exp);
1299 };
1300
1301 template<typename exp1, typename exp2, unsigned int op>
1303 {
1304 this->operator=(v_exp);
1305 }
1306
1312 inline void * getNN() const
1313 {
1314 return NULL;
1315 }
1316
1324 __device__ __host__ const vector & getVector() const
1325 {
1326 return v;
1327 }
1328
1336 __device__ __host__ vector & getVector()
1337 {
1338 return v;
1339 }
1340
1346 inline void init() const
1347 {}
1348
1356 __host__ __device__ inline auto value(const vect_dist_key_dx & k) const -> decltype(v.template get<0>(k.getKey()))
1357 {
1358 return v.template get<0>(k.getKey());
1359 }
1360
1361
1369 template<unsigned int prp2, typename vector2> vector & operator=(const vector_dist_expression<prp2,vector2> & v_exp)
1370 {
1371 if (v_exp.getVector().isSubset() == true)
1372 {
1373 std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1374 return v;
1375 }
1376
1377 v.resize(v_exp.getVector().size_local());
1378 constexpr bool cond=has_vector_kernel<vector>::type::value || std::is_same<vector,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value;
1379 //std::cout<<cond<<std::endl;
1380 //std::cout<< (vector_dist_expression_comp_sel<comp_host,has_vector_kernel<vector>::type::value>::type::value || std::is_same<vector,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value)<<std::endl;
1381 //std::cout<<(vector_dist_expression_comp_sel<2,
1382 // has_vector_kernel<vector>::type::value>::type::value || std::is_same<vector,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value)<<std::endl;
1383 //std::cout<<has_vector_kernel<vector>::type::value<<std::endl;
1384 //std::cout<<vector_dist_expression_comp_sel<2,false>::type::value<<std::endl;
1385 //std::cout<<!std::is_same<vector,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value<<std::endl;
1387 {
1389 ::compute_expr(v,v_exp);
1390 }
1391 else
1392 {
1394 }
1395
1396 return v;
1397 }
1398
1399
1407 template<typename exp1, typename exp2, unsigned int op>
1409 {
1410 if (v_exp.getVector().isSubset() == true)
1411 {
1412 std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1413 return v;
1414 }
1415
1416 v.resize(v_exp.getVector().size_local());
1417
1419 {
1424 ::compute_expr(v,v_exp);
1425 }
1426 else
1427 {
1432 ::compute_expr(v,v_exp);
1433 }
1434
1435 return v;
1436 }
1437
1445 vector & operator=(double d)
1446 {
1447 std::cout << __FILE__ << ":" << __LINE__ << " Error: temporal with constants is unsupported" << std::endl;
1448 }
1449
1450
1451 template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
1452 inline void value_nz(pmap_type & p_map, const vect_dist_key_dx & key, unordered_map_type & cols, coeff_type & coeff, unsigned int comp) const
1453 {
1454 std::cout << __FILE__ << ":" << __LINE__ << " Error: use of temporal is not supported to construct equations";
1455 }
1456
1457 inline vector_dist_expression_op<vector_dist_expression<0,vector>,boost::mpl::int_<1>,VECT_COMP> operator[](int comp)
1458 {
1459 int comp_n[1];
1460
1461 comp_n[0] = comp;
1462
1463 vector_dist_expression_op<vector_dist_expression<0,vector>,boost::mpl::int_<1>,VECT_COMP> v_exp(*this,comp_n,var_id);
1464
1465 return v_exp;
1466 }
1467};
1468
1475template<typename T, typename memory,template <typename> class layout_base >
1476class vector_dist_expression<0,openfpm::vector<aggregate<T>,memory, layout_base> > : public vector_dist_expression_impl<openfpm::vector<aggregate<T>,memory, layout_base>>
1477{
1478 typedef openfpm::vector<aggregate<T>,memory, layout_base> vector;
1480
1481public:
1483 {
1484 }
1485
1486 template<unsigned int prp2, typename vector2>
1488 :base(v_exp)
1489 {
1490 }
1491
1492 template<typename exp1, typename exp2, unsigned int op>
1494 : base(v_exp)
1495 {
1496 }
1497
1498 template<unsigned int prp2, typename vector2> vector & operator=(const vector_dist_expression<prp2,vector2> & v_exp)
1499 {
1500 return base::operator=(v_exp);
1501 }
1502 template<typename exp1, typename exp2, unsigned int op>
1504 {
1505 return base::operator=(v_exp);
1506 }
1507};
1508
1515template<typename T>
1516class vector_dist_expression<0,openfpm::vector_gpu<aggregate<T>>> : public vector_dist_expression_impl<openfpm::vector_gpu<aggregate<T>>>
1517{
1520public:
1522 {
1523 }
1524
1525 template<unsigned int prp2, typename vector2>
1527 :base(v_exp)
1528 {
1529 }
1530
1531 template<typename exp1, typename exp2, unsigned int op>
1533 : base(v_exp)
1534 {
1535 }
1536
1537 template<unsigned int prp2, typename vector2> vector & operator=(const vector_dist_expression<prp2,vector2> & v_exp)
1538 {
1539 return base::operator=(v_exp);
1540 }
1541
1543 {
1544 return base::operator=(v_exp);
1545 }
1546
1548 {
1549 return base::operator=(v_exp);
1550 }
1551
1552 template<typename exp1, typename exp2, unsigned int op>
1554 {
1555 return base::operator=(v_exp);
1556 }
1557
1558
1559};
1560
1563
1564
1565template<typename vector, unsigned int impl>
1567{
1568 typedef vector type;
1569
1570 static vector & get(vector & v) {return v;};
1571
1572 template<typename exp_type, typename vector_klist>
1573 static void register_vector(exp_type & exp_v, vector_klist & v,bool is_sort)
1574 {
1575 }
1576};
1577
1578template<typename vector>
1579struct switcher_get_v<vector,comp_dev>
1580{
1581 typedef decltype(std::declval<vector>().toKernel()) type;
1582
1583 static type get(vector & v) {return v.toKernel();};
1584
1585 template<typename exp_type, typename vector_klist>
1586 static void register_vector(exp_type & exp_v, vector_klist & v,bool is_sort)
1587 {
1588 exp_v.set_vector_dist_ker_list(v.private_get_vector_dist_ker_list(),is_sort);
1589 }
1590};
1591
1592/*template<unsigned int, bool is_valid>
1593struct get_vector_dist_expression_op
1594{
1595 template<typename exp_type>
1596 inline static auto get(exp_type & o1, const vect_dist_key_dx & key) -> decltype(o1.value(vect_dist_key_dx(0)))
1597 {
1598 return o1.value(key);
1599 }
1600
1601 template<unsigned int prop, typename exp_type, typename vector_type>
1602 inline static void assign(exp_type & o1, vector_type & v, const vect_dist_key_dx & key, const vect_dist_key_dx & key_orig)
1603 {
1604 pos_or_propL<vector_type,exp_type::prop>::value(v,key) = o1.value(key_orig);
1605 }
1606
1607 template<unsigned int prop, typename vector_type>
1608 inline static void assign_double(double d, vector_type & v, const vect_dist_key_dx & key)
1609 {
1610 pos_or_propL<vector_type,prop>::value(v,key) = d;
1611 }
1612};
1613
1614template<>
1615struct get_vector_dist_expression_op<1,false>
1616{
1617 template<typename exp_type>
1618 static int get(exp_type & o1, const vect_dist_key_dx & key, const int (& comp)[1])
1619 {
1620 printf("ERROR: Slicer, the expression is incorrect, please check it\n");
1621 return 0;
1622 }
1623
1624 template<unsigned int prop, typename exp_type, typename vector_type>
1625 inline static void assign(exp_type & o1, vector_type & v, const vect_dist_key_dx & key)
1626 {
1627 printf("ERROR: Slicer, the expression is incorrect, please check it\n");
1628 }
1629
1630 template<unsigned int prop, typename vector_type>
1631 inline static void assign_double(double d, vector_type & v, const vect_dist_key_dx & key)
1632 {
1633 printf("ERROR: Slicer, the expression is incorrect, please check it\n");
1634 }
1635};
1636
1637template<>
1638struct get_vector_dist_expression_op<1,true>
1639{
1640 template<typename exp_type>
1641 static auto get(exp_type & o1, const vect_dist_key_dx & key, const int (& comp)[1]) -> decltype(o1.value(vect_dist_key_dx(0))[0])
1642 {
1643 return o1.value(key)[comp[0]];
1644 }
1645
1646 template<unsigned int prop,typename exp_type, typename vector_type>
1647 inline static void assign(exp_type & o1, vector_type & v, const vect_dist_key_dx & key, const vect_dist_key_dx & key_orig, const int (& comp)[1])
1648 {
1649 pos_or_propL<vector_type,prop>::value(v,key)[comp[0]] = o1.value(key_orig);
1650 }
1651
1652 template<unsigned int prop, typename vector_type>
1653 inline static void assign_double(double d, vector_type & v, const vect_dist_key_dx & key, const int (& comp)[1])
1654 {
1655 pos_or_propL<vector_type,prop>::value(v,key)[comp[0]] = d;
1656 }
1657};
1658
1659template<>
1660struct get_vector_dist_expression_op<2,true>
1661{
1662 template<typename exp_type>
1663 static auto get(exp_type & o1, const vect_dist_key_dx & key, const int (& comp)[2]) -> decltype(o1.value(vect_dist_key_dx(0))[0][0])
1664 {
1665 return o1.value(key)[comp[0]][comp[1]];
1666 }
1667
1668 template<unsigned int prop,typename exp_type, typename vector_type>
1669 inline static void assign(exp_type & o1, vector_type & v, const vect_dist_key_dx & key, const vect_dist_key_dx & key_orig, const int (& comp)[2])
1670 {
1671 pos_or_propL<vector_type,prop>::value(v,key)[comp[0]][comp[1]] = o1.value(key_orig);
1672 }
1673
1674 template<unsigned int prop, typename vector_type>
1675 inline static void assign_double(double d, vector_type & v, const vect_dist_key_dx & key, const int (& comp)[2])
1676 {
1677 pos_or_propL<vector_type,prop>::value(v,key)[comp[0]][comp[1]] = d;
1678 }
1679};*/
1680
1681
1686template <typename exp1,int n>
1687class vector_dist_expression_op<exp1,boost::mpl::int_<n>,VECT_COMP>
1688{
1690 exp1 o1;
1691
1693 int comp[n];
1694
1695 int var_id = 0;
1696 void setVarId(int var_id)
1697 {
1698 this->var_id = var_id;
1699 }
1700
1702
1703public:
1704
1705 typedef std::false_type is_ker;
1706
1708 typedef boost::mpl::bool_<false> is_sort;
1709
1711 typedef boost::mpl::bool_<false> NN_type;
1712
1713 typedef typename exp1::vtype vtype;
1714
1716
1717 vector_dist_expression_op(const exp1 & o1, int (& comp)[n], int var_id)
1718 :o1(o1),var_id(var_id)
1719 {
1720 for (int i = 0 ; i < n ; i++)
1721 {this->comp[i] = comp[i];}
1722 }
1723
1731 __device__ __host__ const vtype & getVector() const
1732 {
1733 return o1.getVector();
1734 }
1735
1743 __device__ __host__ vtype & getVector()
1744 {
1745 return o1.getVector();
1746 }
1747
1749 inline void init() const
1750 {
1751 o1.init();
1752 }
1753
1755 //typedef typename boost::mpl::at<typename vtype::value_type::type,boost::mpl::int_<exp1::prop>>::type property_act;
1756 typedef typename pos_or_propL<vtype,exp1::prop>::property_act property_act;
1757
1768 __host__ __device__ inline auto value(const vect_dist_key_dx & key) const -> decltype(get_vector_dist_expression_op<n,n == rank_gen<property_act>::type::value>::get(o1,vect_dist_key_dx(0),comp))
1769 {
1771 }
1772
1783 __host__ __device__ inline auto value(const vect_dist_key_dx & key) -> decltype(get_vector_dist_expression_op<n,n == rank_gen<property_act>::type::value>::get(o1,vect_dist_key_dx(0),comp))
1784 {
1786 }
1787
1798 inline auto get(const vect_dist_key_dx & key) const -> decltype(value(key))
1799 {
1800 return this->value(key);
1801 }
1802
1803 template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
1804 inline void value_nz(pmap_type & p_map, const vect_dist_key_dx & key, unordered_map_type & cols, coeff_type & coeff, unsigned int comp_) const
1805 {
1806#ifdef SE_CLASS1
1807
1808 if (n != 1)
1809 {
1810 std::cout << __FILE__ << ":" << __LINE__ << " Error it only work for tensore of rank 1 ... like vectors " << std::endl;
1811 }
1812
1813#endif
1814
1815 o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff,comp_ + var_id + comp[0]);
1816 }
1817
1818 inline vector_dist_expression_op<exp1,boost::mpl::int_<2>,VECT_COMP> operator[](int comp_)
1819 {
1820 int comp_n[n+1];
1821
1822 for (int i = 0 ; i < n ; i++)
1823 {comp_n[i] = comp[i];}
1824 comp_n[n] = comp_;
1825
1826 vector_dist_expression_op<exp1,boost::mpl::int_<2>,VECT_COMP> v_exp(o1,comp_n,var_id);
1827
1828 return v_exp;
1829 }
1830
1838 template<typename T, typename memory> vtype & operator=(const vector_dist_expression<0,openfpm::vector<aggregate<T>,memory>> & v_exp)
1839 {
1840 v_exp.init();
1841
1842 auto & v = getVector();
1843/*#ifdef SE_CLASS1
1844 auto &v2=v_exp.getVector();
1845
1846 SubsetSelector_impl<std::remove_reference<decltype(v)>::type::is_it_a_subset::value>::check(v2,v);
1847#endif*/
1848
1849 auto it = v.getDomainIterator();
1850
1851 while (it.isNext())
1852 {
1853 auto key = it.get();
1854 auto key_orig = v.getOriginKey(key);
1855
1856 get_vector_dist_expression_op<n,n == rank_gen<property_act>::type::value>::template assign<exp1::prop>(v_exp,v,key,key_orig,comp);
1857
1858 ++it;
1859 }
1860
1861 return v;
1862 }
1863
1871 template<unsigned int prp2> vtype & operator=(const vector_dist_expression<prp2,vtype> & v_exp)
1872 {
1873 v_exp.init();
1874
1875 auto & v = getVector();
1876#ifdef SE_CLASS1
1877 auto &v2=v_exp.getVector();
1878
1879 SubsetSelector_impl<std::remove_reference<decltype(v)>::type::is_it_a_subset::value>::check(v2,v);
1880#endif
1881 auto it = v.getDomainIterator();
1882
1883 while (it.isNext())
1884 {
1885 auto key = it.get();
1886 auto key_orig = v.getOriginKey(key);
1887
1888 get_vector_dist_expression_op<n,n == rank_gen<property_act>::type::value>::template assign<exp1::prop>(v_exp,v,key,key_orig,comp);
1889
1890 ++it;
1891 }
1892
1893 return v;
1894 }
1895
1903 template<typename exp1_, typename exp2_, unsigned int op> vtype & operator=(const vector_dist_expression_op<exp1_,exp2_,op> & v_exp)
1904 {
1905 if (v_exp.getVector().isSubset() == true)
1906 {
1907 std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1908 return this->getVector();
1909 }
1910
1912 {
1915 ::compute_expr_slice(o1.getVector(),v_exp,comp);
1916 }
1917 else
1918 {
1921 ::compute_expr_slice(o1.getVector(),v_exp,comp);
1922 }
1923
1924 return this->getVector();
1925 }
1926
1934 vtype & operator=(double d)
1935 {
1936 auto & v = getVector();
1937
1938 auto it = v.getDomainIterator();
1939
1940 while (it.isNext())
1941 {
1942 auto key = it.get();
1943
1944 //pos_or_propL<vtype,exp1::prp>::value(v,key) = d;
1945 get_vector_dist_expression_op<n,n == rank_gen<property_act>::type::value>::template assign_double<exp1::prop>(d,v,key,comp);
1946
1947
1948 ++it;
1949 }
1950
1951 return v;
1952 }
1953};
1954
1961template <unsigned int prp,unsigned int impl = comp_host, typename vector>
1963{
1966
1968
1969 return exp_v;
1970}
1971
1972
1979template <unsigned int prp,typename vector>
1981{
1982 auto vk = v.toKernel_sorted();
1984
1985 exp_v.set_vector_dist_ker_list(v.private_get_vector_dist_ker_list(),true);
1986
1987 return exp_v;
1988}
1989
1995template<unsigned int prp>
1996class vector_dist_expression<prp,double>
1997{
1999 double d;
2000
2001public:
2002
2003 typedef std::false_type is_ker;
2004
2006 typedef boost::mpl::bool_<false> is_sort;
2007
2008 typedef void NN_type;
2009
2011 inline vector_dist_expression(const double & d)
2012 :d(d)
2013 {}
2014
2020 inline void init() const
2021 {}
2022
2032 __device__ __host__ inline double value(const vect_dist_key_dx & k) const
2033 {
2034 return d;
2035 }
2036
2037
2038 template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
2039 inline void value_nz(pmap_type & p_map, const vect_dist_key_dx & key, unordered_map_type & cols, coeff_type & coeff, unsigned int comp) const
2040 {
2041 cols[p_map. template getProp<0>(key)*Sys_eqs::nvar + comp] += coeff;
2042 }
2052 __host__ __device__ inline double value(const unsigned int & k) const
2053 {
2054 return d;
2055 }
2056};
2057
2058
2064template<unsigned int prp>
2066{
2068 float d;
2069
2070public:
2071
2072 typedef std::false_type is_ker;
2073
2074
2076 typedef boost::mpl::bool_<false> is_sort;
2077
2078 typedef void NN_type;
2079
2081 inline vector_dist_expression(const float & d)
2082 :d(d)
2083 {}
2084
2090 inline void init() const
2091 {}
2092
2102 inline float value(const vect_dist_key_dx & k) const
2103 {
2104 return d;
2105 }
2106
2116 __device__ __host__ inline float value(const unsigned int & k) const
2117 {
2118 return d;
2119 }
2120};
2121
2122/* \brief sum two distributed vector expression
2123 *
2124 * \param va vector expression one
2125 * \param vb vector expression two
2126 *
2127 * \return an object that encapsulate the expression
2128 *
2129 */
2130template<unsigned int p1, unsigned int p2, typename v1, typename v2>
2132operator+(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
2133{
2135
2136 return exp_sum;
2137}
2138
2139/* \brief sum two distributed vector expression
2140 *
2141 * \param va vector expression one
2142 * \param vb vector expression two
2143 *
2144 * \return an object that encapsulate the expression
2145 *
2146 */
2147template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>
2150{
2152
2153 return exp_sum;
2154}
2155
2156/* \brief sum two distributed vector expression
2157 *
2158 * \param va vector expression one
2159 * \param vb vector expression two
2160 *
2161 * \return an object that encapsulate the expression
2162 *
2163 */
2164template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>
2167{
2169
2170 return exp_sum;
2171}
2172
2173/* \brief sum two distributed vector expression
2174 *
2175 * \param va vector expression one
2176 * \param vb vector expression two
2177 *
2178 * \return an object that encapsulate the expression
2179 *
2180 */
2181template<typename exp1 , typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>
2184{
2186
2187 return exp_sum;
2188}
2189
2190/* \brief sum two distributed vector expression
2191 *
2192 * \param va vector expression one
2193 * \param vb vector expression two
2194 *
2195 * \return an object that encapsulate the expression
2196 *
2197 */
2198template<unsigned int prp1 , typename v1>
2200operator+(const vector_dist_expression<prp1,v1> & va, double d)
2201{
2203
2204 return exp_sum;
2205}
2206
2207/* \brief sum two distributed vector expression
2208 *
2209 * \param va vector expression one
2210 * \param vb vector expression two
2211 *
2212 * \return an object that encapsulate the expression
2213 *
2214 */
2215template<typename T, unsigned int prp1, typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2217operator+(const vector_dist_expression<prp1,v1> & va, T d)
2218{
2220
2221 return exp_sum;
2222}
2223
2224/* \brief sum two distributed vector expression
2225 *
2226 * \param va vector expression one
2227 * \param vb vector expression two
2228 *
2229 * \return an object that encapsulate the expression
2230 *
2231 */
2232template<unsigned int prp1 , typename v1>
2234operator+(double d, const vector_dist_expression<prp1,v1> & vb)
2235{
2237
2238 return exp_sum;
2239}
2240
2241/* \brief sum two distributed vector expression
2242 *
2243 * \param va vector expression one
2244 * \param vb vector expression two
2245 *
2246 * \return an object that encapsulate the expression
2247 *
2248 */
2249template<unsigned int prp1 , typename v1>
2251operator+(float d, const vector_dist_expression<prp1,v1> & vb)
2252{
2254
2255 return exp_sum;
2256}
2257
2258/* \brief sum two distributed vector expression
2259 *
2260 * \param va vector expression one
2261 * \param vb vector expression two
2262 *
2263 * \return an object that encapsulate the expression
2264 *
2265 */
2266template<typename exp1 , typename exp2, unsigned int op1>
2268operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
2269{
2271
2272 return exp_sum;
2273}
2274
2275/* \brief sum two distributed vector expression
2276 *
2277 * \param va vector expression one
2278 * \param vb vector expression two
2279 *
2280 * \return an object that encapsulate the expression
2281 *
2282 */
2283template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2285operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, T d)
2286{
2288
2289 return exp_sum;
2290}
2291
2292/* \brief subtract two distributed vector expression
2293 *
2294 * \param va vector expression one
2295 * \param vb vector expression two
2296 *
2297 * \return an object that encapsulate the expression
2298 *
2299 */
2300template<unsigned int p1, unsigned int p2, typename v1, typename v2>
2302operator-(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
2303{
2305
2306 return exp_sum;
2307}
2308
2309
2310/* \brief subtract two distributed vector expression
2311 *
2312 * \param va vector expression one
2313 * \param vb vector expression two
2314 *
2315 * \return an object that encapsulate the expression
2316 *
2317 */
2318template<typename exp1, typename exp2, unsigned int op1, unsigned int p2, typename v2>
2321{
2323
2324 return exp_sum;
2325}
2326
2327/* \brief minus of a distributed vector expression operator
2328 *
2329 * \param va vector expression one
2330 *
2331 * \return an object that encapsulate the expression
2332 *
2333 */
2334template<typename exp1, typename exp2_, unsigned int op1>
2337{
2339
2340 return exp_sum;
2341}
2342
2343/* \brief minus of a distributed vector expression
2344 *
2345 * \param va vector expression one
2346 *
2347 * \return an object that encapsulate the expression
2348 *
2349 */
2350template<unsigned int p1, typename v1>
2352operator-(const vector_dist_expression<p1,v1> & va)
2353{
2354 vector_dist_expression_op<vector_dist_expression<p1,v1>,void,VECT_SUB_UNI> exp_sum(va);
2355
2356 return exp_sum;
2357}
2358
2359
2360/* \brief subtract two distributed vector expression
2361 *
2362 * \param va vector expression one
2363 * \param vb vector expression two
2364 *
2365 * \return an object that encapsulate the expression
2366 *
2367 */
2368template<typename exp1, typename exp2, unsigned int op1, unsigned int p2, typename v2>
2371{
2373
2374 return exp_sum;
2375}
2376
2377/* \brief subtract two distributed vector expression
2378 *
2379 * \param va vector expression one
2380 * \param vb vector expression two
2381 *
2382 * \return an object that encapsulate the expression
2383 *
2384 */
2385template<typename exp1, typename exp2, unsigned int op1, typename exp3, typename exp4, unsigned int op2>
2388{
2390
2391 return exp_sum;
2392}
2393
2394/* \brief subtract two distributed vector expression
2395 *
2396 * \param va vector expression one
2397 * \param vb vector expression two
2398 *
2399 * \return an object that encapsulate the expression
2400 *
2401 */
2402template<unsigned int prp1, typename v1>
2404operator-(const vector_dist_expression<prp1,v1> & va, double d)
2405{
2407
2408 return exp_sum;
2409}
2410
2411/* \brief subtract two distributed vector expression
2412 *
2413 * \param va vector expression one
2414 * \param vb vector expression two
2415 *
2416 * \return an object that encapsulate the expression
2417 *
2418 */
2419//template<unsigned int prp1, typename v1>
2420template<typename T, unsigned int prp1,typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2422operator-(const vector_dist_expression<prp1,v1> & va, T d)
2423{
2425
2426 return exp_sum;
2427}
2428
2429/* \brief subtract two distributed vector expression
2430 *
2431 * \param va vector expression one
2432 * \param vb vector expression two
2433 *
2434 * \return an object that encapsulate the expression
2435 *
2436 */
2437template<unsigned int prp1, typename v1>
2439operator-(double d, const vector_dist_expression<prp1,v1> & vb)
2440{
2442
2443 return exp_sum;
2444}
2445
2446/* \brief subtract two distributed vector expression
2447 *
2448 * \param va vector expression one
2449 * \param vb vector expression two
2450 *
2451 * \return an object that encapsulate the expression
2452 *
2453 */
2454template<typename T, unsigned int prp1,typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2456operator-(T d, const vector_dist_expression<prp1,v1> & vb)
2457{
2459
2460 return exp_sum;
2461}
2462
2463/* \brief Multiply two distributed vector expression
2464 *
2465 * \param va vector expression one
2466 * \param vb vector expression two
2467 *
2468 * \return an object that encapsulate the expression
2469 *
2470 */
2471template<unsigned int p2, typename v2>
2473operator*(double d, const vector_dist_expression<p2,v2> & vb)
2474{
2476
2477 return exp_sum;
2478}
2479
2480/* \brief Multiply two distributed vector expression
2481 *
2482 * \param va vector expression one
2483 * \param vb vector expression two
2484 *
2485 * \return an object that encapsulate the expression
2486 *
2487 */
2488template<typename T, unsigned int p2,typename v2, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2490operator*(T d, const vector_dist_expression<p2,v2> & vb)
2491{
2493
2494 return exp_sum;
2495}
2496
2497/* \brief Multiply two distributed vector expression
2498 *
2499 * \param va vector expression one
2500 * \param vb vector expression two
2501 *
2502 * \return an object that encapsulate the expression
2503 *
2504 */
2505template<unsigned int p2, typename v2>
2507operator*(const vector_dist_expression<p2,v2> & va, double d)
2508{
2510
2511 return exp_sum;
2512}
2513
2514/* \brief Multiply two distributed vector expression
2515 *
2516 * \param va vector expression one
2517 * \param vb vector expression two
2518 *
2519 * \return an object that encapsulate the expression
2520 *
2521 */
2522template<typename T, unsigned int p2,typename v2, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2524operator*(const vector_dist_expression<p2,v2> & va, T d)
2525{
2527
2528 return exp_sum;
2529}
2530
2531/* \brief Multiply two distributed vector expression
2532 *
2533 * \param va vector expression one
2534 * \param vb vector expression two
2535 *
2536 * \return an object that encapsulate the expression
2537 *
2538 */
2539template<unsigned int p1, typename v1,unsigned int p2, typename v2>
2541operator*(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
2542{
2544
2545 return exp_sum;
2546}
2547
2548/* \brief Multiply two distributed vector expression
2549 *
2550 * \param va vector expression one
2551 * \param vb vector expression two
2552 *
2553 * \return an object that encapsulate the expression
2554 *
2555 */
2556template<unsigned int p1, typename v1, typename exp1, typename exp2, unsigned int op1>
2559{
2561
2562 return exp_sum;
2563}
2564
2565/* \brief Multiply two distributed vector expression
2566 *
2567 * \param va vector expression one
2568 * \param vb vector expression two
2569 *
2570 * \return an object that encapsulate the expression
2571 *
2572 */
2573template<unsigned int p1, typename v1, typename exp1, typename exp2, unsigned int op1>
2576{
2578
2579 return exp_sum;
2580}
2581
2582/* \brief Multiply two distributed vector expression
2583 *
2584 * \param va vector expression one
2585 * \param vb vector expression two
2586 *
2587 * \return an object that encapsulate the expression
2588 *
2589 */
2590template<typename exp1, typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>
2593{
2595
2596 return exp_sum;
2597}
2598
2599/* \brief Multiply a distributed vector expression by a number
2600 *
2601 * \param va vector expression
2602 * \param d number
2603 *
2604 * \return an object that encapsulate the expression
2605 *
2606 */
2607template<typename exp1 , typename exp2, unsigned int op1>
2609operator*(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
2610{
2612
2613 return exp_sum;
2614}
2615
2616/* \brief Multiply a distributed vector expression by a number
2617 *
2618 * \param va vector expression
2619 * \param d number
2620 *
2621 * \return an object that encapsulate the expression
2622 *
2623 */
2624template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2626operator*(const vector_dist_expression_op<exp1,exp2,op1> & va, T d)
2627{
2629
2630 return exp_sum;
2631}
2632
2633/* \brief Multiply a distributed vector expression by a number
2634 *
2635 * \param d number
2636 * \param vb vector expression
2637 *
2638 * \return an object that encapsulate the expression
2639 *
2640 */
2641template<typename exp1 , typename exp2, unsigned int op1>
2643operator*(double d, const vector_dist_expression_op<exp1,exp2,op1> & vb)
2644{
2646
2647 return exp_sum;
2648}
2649
2650/* \brief Multiply a distributed vector expression by a number
2651 *
2652 * \param d number
2653 * \param vb vector expression
2654 *
2655 * \return an object that encapsulate the expression
2656 *
2657 */
2658template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2660operator*(T d, const vector_dist_expression_op<exp1,exp2,op1> & vb)
2661{
2663
2664 return exp_sum;
2665}
2666
2667/* \brief Divide two distributed vector expression
2668 *
2669 * \param va vector expression one
2670 * \param vb vector expression two
2671 *
2672 * \return an object that encapsulate the expression
2673 *
2674 */
2675template<typename exp1, typename exp2, unsigned int op1>
2677operator/(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
2678{
2680
2681 return exp_sum;
2682}
2683
2684/* \brief Divide two distributed vector expression
2685 *
2686 * \param va vector expression one
2687 * \param vb vector expression two
2688 *
2689 * \return an object that encapsulate the expression
2690 *
2691 */
2692template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2694operator/(const vector_dist_expression_op<exp1,exp2,op1> & va, T d)
2695{
2697
2698 return exp_sum;
2699}
2700
2701/* \brief Divide two distributed vector expression
2702 *
2703 * \param va vector expression one
2704 * \param vb vector expression two
2705 *
2706 * \return an object that encapsulate the expression
2707 *
2708 */
2709template<typename exp1, typename exp2, unsigned int op1>
2711operator/(double d, const vector_dist_expression_op<exp1,exp2,op1> & va)
2712{
2714
2715 return exp_sum;
2716}
2717
2718/* \brief Divide two distributed vector expression
2719 *
2720 * \param va vector expression one
2721 * \param vb vector expression two
2722 *
2723 * \return an object that encapsulate the expression
2724 *
2725 */
2726template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2728operator/(T d, const vector_dist_expression_op<exp1,exp2,op1> & va)
2729{
2731
2732 return exp_sum;
2733}
2734
2735/* \brief Divide two distributed vector expression
2736 *
2737 * \param va vector expression one
2738 * \param vb vector expression two
2739 *
2740 * \return an object that encapsulate the expression
2741 *
2742 */
2743template<unsigned int prp1, typename v1>
2745operator/(const vector_dist_expression<prp1,v1> & va, double d)
2746{
2748
2749 return exp_sum;
2750}
2751
2752/* \brief Divide two distributed vector expression
2753 *
2754 * \param va vector expression one
2755 * \param vb vector expression two
2756 *
2757 * \return an object that encapsulate the expression
2758 *
2759 */
2760template<typename T, unsigned int prp1,typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2762operator/(const vector_dist_expression<prp1,v1> & va, T d)
2763{
2765
2766 return exp_sum;
2767}
2768
2769/* \brief Divide two distributed vector expression
2770 *
2771 * \param va vector expression one
2772 * \param vb vector expression two
2773 *
2774 * \return an object that encapsulate the expression
2775 *
2776 */
2777template<unsigned int prp1, typename v1>
2779operator/(double d, const vector_dist_expression<prp1,v1> & va)
2780{
2782
2783 return exp_sum;
2784}
2785
2786/* \brief Divide two distributed vector expression
2787 *
2788 * \param va vector expression one
2789 * \param vb vector expression two
2790 *
2791 * \return an object that encapsulate the expression
2792 *
2793 */
2794template<typename T, unsigned int prp1,typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2796operator/(T d, const vector_dist_expression<prp1,v1> & va)
2797{
2799
2800 return exp_sum;
2801}
2802
2803/* \brief Divide two distributed vector expression
2804 *
2805 * \param va vector expression one
2806 * \param vb vector expression two
2807 *
2808 * \return an object that encapsulate the expression
2809 *
2810 */
2811template<unsigned int prp1, typename v1, unsigned int prp2, typename v2>
2814{
2816
2817 return exp_sum;
2818}
2819
2820/* \brief Divide two distributed vector expression
2821 *
2822 * \param va vector expression one
2823 * \param vb vector expression two
2824 *
2825 * \return an object that encapsulate the expression
2826 *
2827 */
2828template<unsigned int prp1, typename v1, typename exp1,typename exp2, unsigned int op1>
2831{
2833
2834 return exp_sum;
2835}
2836
2837/* \brief Divide two distributed vector expression
2838 *
2839 * \param va vector expression one
2840 * \param vb vector expression two
2841 *
2842 * \return an object that encapsulate the expression
2843 *
2844 */
2845template<unsigned int prp1, typename v1, typename exp1,typename exp2, unsigned int op1>
2848{
2850
2851 return exp_sum;
2852}
2853
2854/* \brief Divide two distributed vector expression
2855 *
2856 * \param va vector expression one
2857 * \param vb vector expression two
2858 *
2859 * \return an object that encapsulate the expression
2860 *
2861 */
2862template<typename exp1,typename exp2, unsigned int op1, typename exp3, typename exp4, unsigned int op2>
2865{
2867
2868 return exp_sum;
2869}
2870
2871#include "vector_dist_operators_apply_kernel.hpp"
2872#include "vector_dist_operators_functions.hpp"
2873#include "vector_dist_operators_extensions.hpp"
2874#include "Operators/Vector/vector_dist_operator_assign.hpp"
2875
2876
2877#endif /* OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_HPP_ */
Implementation of 1-D std::vector like structure.
Grid key for a distributed grid.
Sub class that encapsulate a GPU vector properties operand to be used for expressions construction Te...
boost::mpl::bool_< false > is_sort
result for is sort
__device__ __host__ double value(const vect_dist_key_dx &k) const
Evaluate the expression.
vector_dist_expression(const double &d)
constructor from a constant expression
__host__ __device__ double value(const unsigned int &k) const
Evaluate the expression.
void init() const
This function must be called before value.
vector_dist_expression(const float &d)
constrictor from constant value
boost::mpl::bool_< false > is_sort
result for is sort
__device__ __host__ float value(const unsigned int &k) const
Evaluate the expression.
void init() const
This function must be called before value.
float value(const vect_dist_key_dx &k) const
Evaluate the expression.
Main class that encapsulate a vector properties operand to be used for expressions construction Tempo...
vector_type vector
Internal vector.
vector & operator=(const vector_dist_expression_op< exp1, exp2, op > &v_exp)
Fill the vector property with the evaluated expression.
T value_type
The type of the internal value.
vector & operator=(const vector_dist_expression< prp2, vector2 > &v_exp)
Fill the vector property with the evaluated expression.
vector & operator=(double d)
Fill the vector property with the double.
vector vtype
The type of the internal vector.
void init() const
This function must be called before value.
__device__ __host__ const vector & getVector() const
Return the vector on which is acting.
__device__ __host__ vector & getVector()
Return the vector on which is acting.
__host__ __device__ auto value(const vect_dist_key_dx &k) const -> decltype(v.template get< 0 >(k.getKey()))
Evaluate the expression.
void * getNN() const
get the NN object
boost::mpl::bool_< false > is_sort
result for is sort
__device__ __host__ const vtype & getVector() const
Return the vector on which is acting.
pos_or_propL< vtype, exp1::prop >::property_act property_act
property on which this view is acting
vtype & operator=(const vector_dist_expression_op< exp1_, exp2_, op > &v_exp)
Fill the vector property with the evaluated expression.
vtype & operator=(const vector_dist_expression< prp2, vtype > &v_exp)
Fill the vector property with the evaluated expression.
auto get(const vect_dist_key_dx &key) const -> decltype(value(key))
Return the result of the expression.
vtype & operator=(const vector_dist_expression< 0, openfpm::vector< aggregate< T >, memory > > &v_exp)
Fill the vector property with the evaluated expression.
__device__ __host__ vtype & getVector()
Return the vector on which is acting.
vector_dist_expression_op(const exp1 &o1, int(&comp)[n], int var_id)
constructor from an expresssion
vtype & operator=(double d)
Fill the vector property with the double.
__host__ __device__ auto value(const vect_dist_key_dx &key) -> decltype(get_vector_dist_expression_op< n, n==rank_gen< property_act >::type::value >::get(o1, vect_dist_key_dx(0), comp))
Return the result of the expression.
__host__ __device__ auto value(const vect_dist_key_dx &key) const -> decltype(get_vector_dist_expression_op< n, n==rank_gen< property_act >::type::value >::get(o1, vect_dist_key_dx(0), comp))
Return the result of the expression.
const vtype & getVector()
Return the vector on which is acting.
first_or_second< has_vtype< exp1 >::value, exp1, exp2 >::vtype vtype
The type of the internal vector.
vector_is_sort_result< exp1::is_sort::value, exp2::is_sort::value >::type is_sort
result for is sort
void init() const
This function must be called before value.
__device__ __host__ r_type value(const unsigned int &key) const
Evaluate the expression.
nn_type_result< typenameexp1::NN_type, typenameexp2::NN_type >::type NN_type
NN_type.
r_type value(const vect_dist_key_dx &key) const
Evaluate the expression.
vector_dist_expression_op(const exp1 &o1, const exp2 &o2)
constructor from two expressions
const vtype & getVector() const
Return the vector on which is acting.
void init() const
This function must be called before value.
const vtype & getVector() const
Return the vector on which is acting.
nn_type_result< typenameexp1::NN_type, typenameexp2::NN_type >::type NN_type
NN_type.
vector_is_sort_result< exp1::is_sort::value, exp2::is_sort::value >::type is_sort
result for is sort
first_or_second< has_vtype< exp1 >::value, exp1, exp2 >::vtype vtype
The type of the internal vector.
__device__ __host__ r_type value(const unsigned int &key) const
Evaluate the expression.
__device__ __host__ r_type value(const vect_dist_key_dx &key) const
Evaluate the expression.
const vtype & getVector()
Return the vector on which is acting.
vector_dist_expression_op(const exp1 &o1, const exp2 &o2)
constructor from two expressions
const vtype & getVector() const
Return the vector on which is acting.
void init() const
This function must be called before value.
const vtype & getVector()
Return the vector on which is acting.
vector_dist_expression_op(const exp1 &o1, const exp2 &o2)
Costruct a subtraction expression out of two expressions.
__device__ __host__ r_type value(const unsigned int &key) const
Evaluate the expression.
vector_is_sort_result< exp1::is_sort::value, exp2::is_sort::value >::type is_sort
result for is sort
first_or_second< has_vtype< exp1 >::value, exp1, exp2 >::vtype vtype
The type of the internal vector.
r_type value(const vect_dist_key_dx &key) const
Evaluate the expression.
nn_type_result< typenameexp1::NN_type, typenameexp2::NN_type >::type NN_type
NN_type.
__device__ __host__ r_type value(const unsigned int &key) const
Evaluate the expression.
exp1::is_ker is_ker
indicate if this vector is kernel type
const vtype & getVector()
Return the vector on which is acting.
const vtype & getVector() const
Return the vector on which is acting.
first_or_second< has_vtype< exp1 >::value, exp1, exp2 >::vtype vtype
return the vector type on which this expression operate
vector_dist_expression_op(const exp1 &o1, const exp2 &o2)
constructor of the expression to sum two expression
__device__ __host__ r_type value(const vect_dist_key_dx &key) const
Evaluate the expression.
void init() const
This function must be called before value.
vector_is_sort_result< exp1::is_sort::value, exp2::is_sort::value >::type is_sort
result for is sort
nn_type_result< typenameexp1::NN_type, typenameexp2::NN_type >::type NN_type
NN_type.
const vtype & getVector() const
Return the vector on which is acting.
vector_dist_expression_op(const exp1 &o1)
constructor from an expresssion
vector_is_sort_result< exp1::is_sort::value, false >::type is_sort
result for is sort
const vtype & getVector()
Return the underlying vector.
vector_result< typenameexp1::vtype, void >::type vtype
return the vector type on which this expression operate
nn_type_result< typenameexp1::NN_type, void >::type NN_type
NN_type.
__device__ __host__ r_type value(const unsigned int &key) const
return the result of the expression
__device__ __host__ r_type value(const vect_dist_key_dx &key) const
return the result of the expression
Unknown operation specialization.
Main class that encapsulate a vector properties operand to be used for expressions construction.
boost::mpl::bool_< false > is_sort
result for is sort
v_mem_mutable< typename vector_expression_transform< vector >::type > v
The vector.
void * getNN() const
get the NN object
void set_vector_dist_ker_list(vector_dist_ker_list< vector > &vdkl, bool is_sort)
set vector_dist_ker_list
vector & operator=(const vector_dist_expression< prp2, vector > &v_exp)
Fill the vector property with the evaluated expression.
vector & operator=(const vector_dist_expression_op< exp1, exp2, op > &v_exp)
Fill the vector property with the evaluated expression.
~vector_dist_expression()
constructor for an external vector
__host__ __device__ auto value(const vect_dist_key_dx &k) const -> decltype(pos_or_propR< vector, prp >::value(v.v, k))
Evaluate the expression.
__host__ __device__ auto value(const vect_dist_key_dx &k) -> decltype(pos_or_propR< vector, prp >::value(v.v, k))
Evaluate the expression.
vector & operator=(const vector_dist_expression< 0, openfpm::vector_gpu< aggregate< T > > > &v_exp)
Fill the vector property with the evaluated expression.
vector & operator=(const vector_dist_expression< 0, openfpm::vector< aggregate< T >, memory, layout_base > > &v_exp)
Fill the vector property with the evaluated expression.
vector & operator=(double d)
Fill the vector property with the double.
__host__ __device__ auto value(const unsigned int &k) -> decltype(pos_or_propR< vector, prp >::value(v.v, k))
Evaluate the expression.
__device__ __host__ const vector & getVector() const
Return the vector on which is acting.
__device__ __host__ vector & getVector()
Return the vector on which is acting.
vector vtype
The type of the internal vector.
__host__ __device__ auto value(const unsigned int &k) const -> decltype(pos_or_propR< vector, prp >::value(v.v, k))
Evaluate the expression.
vector_dist_expression(vector &v)
constructor for an external vector
void init() const
This function must be called before value.
This class contain a list of all tracked vector_dist_ker around.
void remove(vector_dist_ker_type &v)
Remove one vector_dist_kernels entry.
void add(vector_dist_ker_type &v, bool is_sorted)
Add a new vector_dist_kernel to track.
Distributed vector.
size_t size_local() const
return the local size of the vector
void resize(size_t rs)
Resize the vector (locally)
bool isSubset() const
Indicate that this class is not a subset.
convert a type into constant type
Void structure.
Definition common.hpp:74
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
static void call(T &r_exp)
it call the function init for r_exp if T has the function init
Call the init function if a type T has the function init.
static void call(T &r_exp)
it call the function init for r_exp if T has the function init
has_init check if a type has defined a method called init
Transform the boost::fusion::vector into memory specification (memory_traits)
__device__ static __host__ auto value(vector &v, const vect_dist_key_dx &k) -> decltype(v.template getProp< prp >(k))
return the value (position or property) of the particle k in the vector v
Expression implementation computation selector.
Expression implementation computation selector.