OpenFPM  5.2.0
Project that contain the implementation of distributed structures
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_NORM 56
34 #define VECT_NORM2 57
35 #define VECT_ABS 58
36 #define VECT_EXP 59
37 #define VECT_EXP2 60
38 #define VECT_EXPM1 61
39 #define VECT_LOG 62
40 #define VECT_LOG10 63
41 #define VECT_LOG2 64
42 #define VECT_LOG1P 65
43 #define VECT_SQRT 67
44 #define VECT_CBRT 68
45 #define VECT_SIN 69
46 #define VECT_COS 70
47 #define VECT_TAN 71
48 #define VECT_ASIN 72
49 #define VECT_ACOS 73
50 #define VECT_ATAN 74
51 #define VECT_SINH 75
52 #define VECT_COSH 76
53 #define VECT_TANH 77
54 #define VECT_ASINH 78
55 #define VECT_ACOSH 79
56 #define VECT_ATANH 80
57 #define VECT_ERF 81
58 #define VECT_ERFC 82
59 #define VECT_TGAMMA 83
60 #define VECT_LGAMMA 84
61 #define VECT_CEIL 85
62 #define VECT_FLOOR 86
63 #define VECT_TRUNC 87
64 #define VECT_ROUND 88
65 #define VECT_NEARBYINT 89
66 #define VECT_RINT 90
67 #define VECT_PMUL 91
68 #define VECT_SUB_UNI 92
69 #define VECT_SUM_REDUCE 93
70 #define VECT_COMP 94
71 #define VECT_NORM_INF 95
72 
73 
74 #define VECT_DCPSE 100
75 #define VECT_DCPSE_V 101
76 #define VECT_DCPSE_V_SUM 102
77 #define VECT_DCPSE_V_DOT 103
78 #define VECT_DCPSE_V_DIV 104
79 #define VECT_DCPSE_V_CURL2D 105
80 #define VECT_COPY_1_TO_N 300
81 #define VECT_COPY_N_TO_N 301
82 #define VECT_COPY_N_TO_1 302
83 #define VECT_PMUL 91
84 #define VECT_SUB_UNI 92
85 
86 
87 
88 
89 template<bool cond, typename exp1, typename exp2>
91 {
92  typedef typename exp2::vtype vtype;
93 
94  static auto getVector(const exp1 & o1, const exp2 & o2) -> decltype(o2.getVector())
95  {
96  return o2.getVector();
97  }
98 };
99 
100 template<typename exp1, typename exp2>
101 struct first_or_second<true,exp1,exp2>
102 {
103  typedef typename exp1::vtype vtype;
104 
105  static auto getVector(const exp1 & o1, const exp2 & o2) -> decltype(o1.getVector())
106  {
107  return o1.getVector();
108  }
109 };
110 
111 template<typename T, typename Sfinae = void>
112 struct has_vtype: std::false_type {};
113 
123 template<typename T>
124 struct has_vtype<T, typename Void<typename T::vtype>::type> : std::true_type
125 {};
126 
127 
128 
129 
139 template<typename ObjType, typename Sfinae = void>
140 struct has_init: std::false_type {};
141 
142 template<typename ObjType>
143 struct has_init<ObjType, typename Void<typename ObjType::has_init>::type> : std::true_type
144 {};
145 
151 template <typename T, bool has_init = has_init<T>::value >
153 {
155  static inline void call(T & r_exp)
156  {
157  r_exp.init();
158  }
159 };
160 
166 template <typename T>
167 struct call_init_if_needed<T,false>
168 {
170  static inline void call(T & r_exp)
171  {
172  }
173 };
174 
175 
176 
183 template <typename exp1, typename exp2, unsigned int op>
185 {
186 
187 };
188 
189 template<typename v1_type, typename v2_type>
191 {
192  typedef v1_type type;
193 
194  template<typename exp1, typename exp2>
195  static const type & getVector(const exp1 & o1, const exp2 & o2)
196  {
197  return o1.getVector();
198  }
199 
200  template<typename exp1>
201  static const type & getVector(const exp1 & o1)
202  {
203  return o1.getVector();
204  }
205 };
206 
207 
208 template<typename v2_type>
209 struct vector_result<void,v2_type>
210 {
211  typedef v2_type type;
212 
213  template<typename exp1, typename exp2>
214  static const type & getVector(const exp1 & o1, const exp2 & o2)
215  {
216  return o2.getVector();
217  }
218 
219  template<typename exp2>
220  static const type & getVector(exp2 & o2)
221  {
222  return o2.getVector();
223  }
224 };
225 
226 template<typename NN1_type, typename NN2_type>
228 {
229  typedef NN1_type type;
230 
231  template<typename exp1, typename exp2>
232  static type * getNN(exp1 & o1, exp2 & o2)
233  {
234  return o1.getNN();
235  }
236 
237  template<typename exp1>
238  static type * getNN(exp1 & o1)
239  {
240  return o1.getNN();
241  }
242 };
243 
244 
245 template<typename NN2_type>
246 struct nn_type_result<void,NN2_type>
247 {
248  typedef NN2_type type;
249 
250  template<typename exp1, typename exp2>
251  static type * getNN(exp1 & o1, exp2 & o2)
252  {
253  return o2.getNN();
254  }
255 
256  template<typename exp2>
257  static type * getNN(exp2 & o2)
258  {
259  return o2.getNN();
260  }
261 };
262 
263 
270 template <typename exp1, typename exp2>
271 class vector_dist_expression_op<exp1,exp2,VECT_SUM>
272 {
274  const exp1 o1;
275 
277  const exp2 o2;
278 
279 public:
280 
282  typedef typename exp1::is_ker is_ker;
283 
286 
288  typedef typename nn_type_result<typename exp1::NN_type,typename exp2::NN_type>::type NN_type;
289 
291  inline vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
292  :o1(o1),o2(o2)
293  {}
294 
300  inline NN_type * getNN() const
301  {
303  }
304 
310  inline void init() const
311  {
312  o1.init();
313  o2.init();
314  }
315 
323  template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) + o2.value(vect_dist_key_dx()))>::type >
324  __device__ __host__ inline r_type value(const vect_dist_key_dx & key) const
325  {
326  return o1.value(key) + o2.value(key);
327  }
328 
329  template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
330  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
331  {
332  o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff, comp);
333  o2.template value_nz<Sys_eqs>(p_map,key,cols,coeff, comp);
334  }
335 
343  const vtype & getVector()
344  {
345  return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
346  }
347 
355  const vtype & getVector() const
356  {
357  return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
358  }
359 
367  template<typename r_type=typename std::remove_reference<decltype(o1.value(0) + o2.value(0))>::type >
368  __device__ __host__ inline r_type value(const unsigned int & key) const
369  {
370  return o1.value(key) + o2.value(key);
371  }
372 
373 };
374 
381 template <typename exp1, typename exp2>
382 class vector_dist_expression_op<exp1,exp2,VECT_SUB>
383 {
385  const exp1 o1;
386 
388  const exp2 o2;
389 
390 public:
391 
394 
395  typedef typename exp1::is_ker is_ker;
396 
398  typedef typename nn_type_result<typename exp1::NN_type,typename exp2::NN_type>::type NN_type;
399 
401  inline vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
402  :o1(o1),o2(o2)
403  {}
404 
410  inline NN_type * getNN() const
411  {
413  }
414 
415 
421  inline void init() const
422  {
423  o1.init();
424  o2.init();
425  }
426 
434  template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) - o2.value(vect_dist_key_dx()))>::type >
435  inline r_type value(const vect_dist_key_dx & key) const
436  {
437  return o1.value(key) - o2.value(key);
438  }
439 
447  template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) - o2.value(vect_dist_key_dx()))>::type >
448  __device__ __host__ inline r_type value(const unsigned int & key) const
449  {
450  return o1.value(key) - o2.value(key);
451  }
452 
461  const vtype & getVector()
462  {
463  return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
464  }
465 
473  const vtype & getVector() const
474  {
475  return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
476  }
477 
478  template<typename Sys_eqs,typename pmap_type, typename unordered_map_type, typename coeff_type>
479  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
480  {
481  o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff,comp);
482  coeff_type tmp = -coeff;
483  o2.template value_nz<Sys_eqs>(p_map,key,cols,tmp,comp);
484  }
485 };
486 
493 template <typename exp1, typename exp2>
494 class vector_dist_expression_op<exp1,exp2,VECT_MUL>
495 {
497  const exp1 o1;
498 
500  const exp2 o2;
501 
502 public:
503 
506 
507  typedef typename exp1::is_ker is_ker;
508 
510  typedef typename nn_type_result<typename exp1::NN_type,typename exp2::NN_type>::type NN_type;
511 
513  vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
514  :o1(o1),o2(o2)
515  {}
516 
522  inline void init() const
523  {
524  o1.init();
525  o2.init();
526  }
527 
535  template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) * o2.value(vect_dist_key_dx()))>::type >
536  __device__ __host__ inline r_type value(const vect_dist_key_dx & key) const
537  {
538  return o1.value(key) * o2.value(key);
539  }
540 
541  template<typename Sys_eqs,typename pmap_type, typename unordered_map_type, typename coeff_type>
542  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
543  {
544  //o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff,comp);
545  auto coeff_tmp = o1.value(key) * coeff;
546  o2.template value_nz<Sys_eqs>(p_map,key,cols,coeff_tmp,comp);
547  }
548 
556  const vtype & getVector()
557  {
558  return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
559  }
560 
568  const vtype & getVector() const
569  {
570  return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
571  }
572 
580  template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) * o2.value(vect_dist_key_dx()))>::type >
581  __device__ __host__ inline r_type value(const unsigned int & key) const
582  {
583  return o1.value(key) * o2.value(key);
584  }
585 };
586 
593 template <typename exp1, typename exp2>
594 class vector_dist_expression_op<exp1,exp2,VECT_DIV>
595 {
597  const exp1 o1;
598 
600  const exp2 o2;
601 
602 public:
603 
606 
607  typedef typename exp1::is_ker is_ker;
608 
610  typedef typename nn_type_result<typename exp1::NN_type,typename exp2::NN_type>::type NN_type;
611 
613  vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
614  :o1(o1),o2(o2)
615  {}
616 
622  inline NN_type * getNN() const
623  {
625  }
626 
627 
633  inline void init() const
634  {
635  o1.init();
636  o2.init();
637  }
638 
646  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
647  {
648  return o1.value(key) / o2.value(key);
649  }
650 
651  template<typename Sys_eqs,typename pmap_type, typename unordered_map_type, typename coeff_type>
652  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
653  {
654  std::cout << __FILE__ << ":" << __LINE__ << " You are trying to divide by an operator, this is not possible " << std::endl;
655  }
656 
664  const vtype & getVector()
665  {
666  return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
667  }
668 
676  const vtype & getVector() const
677  {
678  return first_or_second<has_vtype<exp1>::value,exp1,exp2>::getVector(o1,o2);
679  }
680 
688  template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx()) / o2.value(vect_dist_key_dx()))>::type >
689  __device__ __host__ inline r_type value(const unsigned int & key) const
690  {
691  return o1.value(key) / o2.value(key);
692  }
693 };
694 
695 
700 template <typename exp1>
701 class vector_dist_expression_op<exp1,void,VECT_SUB_UNI>
702 {
704  const exp1 o1;
705 
706 public:
707 
708 
709  typedef typename exp1::is_ker is_ker;
710 
712  typedef typename vector_result<typename exp1::vtype,void>::type vtype;
713 
715  typedef typename nn_type_result<typename exp1::NN_type,void>::type NN_type;
716 
718  vector_dist_expression_op(const exp1 & o1)
719  :o1(o1)
720  {}
721 
727  inline NN_type * getNN() const
728  {
730  }
731 
737  const vtype & getVector()
738  {
740  }
741 
743  inline void init() const
744  {
745  o1.init();
746  }
747 
755  const vtype & getVector() const
756  {
757  return o1.getVector();
758  }
759 
760 
762  template<typename r_type=typename std::remove_reference<decltype(-(o1.value(vect_dist_key_dx(0))))>::type >
763  __device__ __host__ inline r_type value(const vect_dist_key_dx & key) const
764  {
765  return -(o1.value(key));
766  }
767 
768  template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
769  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
770  {
771  coeff_type coeff_tmp = -coeff;
772  o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff_tmp, comp);
773  }
775  template<typename r_type=typename std::remove_reference<decltype(-(o1.value(vect_dist_key_dx(0))))>::type >
776  __device__ __host__ inline r_type value(const unsigned int & key) const
777  {
778  return -(o1.value(key));
779  }
780 };
781 
786 template<int impl, bool vect_ker>
788 {
789  typedef boost::mpl::int_<impl> type;
790 };
791 
792 template<>
793 struct vector_dist_expression_comp_sel<comp_host,true>
794 {
795  typedef boost::mpl::int_<-1> type;
796 };
797 
798 template<>
799 struct vector_dist_expression_comp_sel<comp_dev,false>
800 {
801  typedef boost::mpl::int_<-1> type;
802 };
803 
807 template<bool cond, unsigned int prop = 0>
809 {
810  template<bool cond_, typename v_type, typename exp_type>
811  static void compute(v_type &v,exp_type &v_exp)
813  ::compute_expr(v,v_exp);}
814 
815  template<bool cond_, unsigned int n, typename v_type, typename exp_type>
816  static void compute(v_type &v,exp_type &v_exp, int (& comp)[n])
818  ::compute_expr_slice(v,v_exp,comp);}
819 };
820 
821 template<unsigned int prp, typename vector>
823 
824 template<typename v_exp>
826 {
827  template<typename T>
828  static auto transform(T & v) -> decltype(v)
829  {
830  return v;
831  }
832 };
833 
834 template<typename T>
835 struct transform_if_temporal<vector_dist_expression<0,openfpm::vector_gpu<aggregate<T>>>>
836 {
837  template<typename T_>
838  static auto transform(T_ & v) -> decltype(v.getVector().toKernel())
839  {
840  return v.getVector().toKernel();
841  }
842 };
843 
844 
845 template<>
847 {
848  template<bool cond, typename v_type, typename exp_type>
849  static void compute(v_type &v, exp_type &v_exp)
850  { auto v_ker=v.toKernel();
851  auto v_exp_transformed = transform_if_temporal<typename std::remove_const<exp_type>::type>::transform(v_exp);
853  ::compute_expr(v_ker,v_exp_transformed);
854  }
855 
856  template<bool cond, unsigned int n, typename v_type, typename exp_type>
857  static void compute(v_type &v, exp_type &v_exp, int (& comp)[n])
858  { auto v_ker=v.toKernel();
859  auto v_exp_transformed = transform_if_temporal<typename std::remove_const<exp_type>::type>::transform(v_exp);
861  ::compute_expr_slice(v_ker,v_exp_transformed, comp);
862  }
863 
864 };
865 
866 template<typename vector, bool is_ker = has_vector_kernel<vector>::type::value>
868 {
869  typedef vector& type;
870 };
871 
872 template<typename vector>
873 struct vector_expression_transform<vector,true>
874 {
875  typedef vector type;
876 };
877 
878 template<typename vector>
880 {
881  vector v;
882 
883  v_mem_mutable(vector & v)
884  :v(v)
885  {}
886 };
887 
888 
889 
896 template<unsigned int prp, typename vector>
898 {
901 
903 
904 public:
905 
906  typedef typename has_vector_kernel<vector>::type is_ker;
907 
909  typedef vector vtype;
910 
912  typedef void NN_type;
913 
915  static const unsigned int prop = prp;
916 
917  int var_id = 0;
918 
919  void setVarId(int var_id)
920  {
921  this->var_id = var_id;
922  }
923 
926  :v(v),vdl(NULL)
927  {}
928 
931  {
932  if (vdl != NULL)
933  {vdl->remove(v.v);}
934  }
935 
941  inline void * getNN() const
942  {
943  return NULL;
944  }
945 
953  __device__ __host__ const vector & getVector() const
954  {
955  return v.v;
956  }
957 
965  __device__ __host__ vector & getVector()
966  {
967  return v.v;
968  }
969 
976  {
977  vdkl.add(v.v);
978  vdl = &vdkl;
979  }
980 
986  inline void init() const
987  {}
988 
996  __host__ __device__ inline auto value(const vect_dist_key_dx & k) const -> decltype(pos_or_propR<vector,prp>::value(v.v,k))
997  {
999  }
1000 
1008  __host__ __device__ inline auto value(const vect_dist_key_dx & k) -> decltype(pos_or_propR<vector,prp>::value(v.v,k))
1009  {
1010  return pos_or_propR<vector,prp>::value(v.v,k);
1011  }
1012 
1020  __host__ __device__ inline auto value(const unsigned int & k) const -> decltype(pos_or_propR<vector,prp>::value(v.v,k))
1021  {
1022  return pos_or_propR<vector,prp>::value(v.v,k);
1023  }
1024 
1032  __host__ __device__ inline auto value(const unsigned int & k) -> decltype(pos_or_propR<vector,prp>::value(v.v,k))
1033  {
1034  return pos_or_propR<vector,prp>::value(v.v,k);
1035  }
1036 
1037  inline auto get(const vect_dist_key_dx & key) const -> decltype(value(key))
1038  {
1039  return this->value(key);
1040  }
1041 
1049  template<unsigned int prp2> vector & operator=(const vector_dist_expression<prp2,vector> & v_exp)
1050  {
1051  if (v_exp.getVector().isSubset() == true)
1052  {
1053  std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1054  return v.v;
1055  }
1056 
1058  {
1061  ::compute_expr(v.v,v_exp);
1062  }
1063  else
1064  {
1067  ::compute_expr(v.v,v_exp);
1068  }
1069 
1070  return v.v;
1071  }
1072 
1080  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)
1081  {
1084  ::compute_expr(v.v,v_exp);
1085 
1086 
1087  return v.v;
1088  }
1089 
1097  template<typename T> vector & operator=(const vector_dist_expression<0,openfpm::vector_gpu<aggregate<T>>> & v_exp)
1098  {
1101  ::compute_expr(v.v,v_exp.getVector().toKernel());
1102 
1103  return v.v;
1104  }
1105 
1113  template<typename exp1, typename exp2, unsigned int op>
1115  {
1116  if (v_exp.getVector().isSubset() == true)
1117  {
1118  std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1119  return v.v;
1120  }
1121 
1123  {
1126  ::compute_expr(v.v,v_exp);
1127  }
1128  else
1129  {
1132  ::compute_expr(v.v,v_exp);
1133  }
1134 
1135  return v.v;
1136  }
1137 
1145  vector & operator=(double d)
1146  {
1148  {
1151  ::compute_const(v.v,d);
1152  }
1153  else
1154  {
1157  ::compute_const(v.v,d);
1158  }
1159 
1160  return v.v;
1161  }
1162 
1163 
1164  template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
1165  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
1166  {
1167  cols[p_map. template getProp<0>(key)*Sys_eqs::nvar + var_id + comp] += coeff;
1168  }
1169 
1170  inline vector_dist_expression_op<vector_dist_expression<prp,vector>,boost::mpl::int_<1>,VECT_COMP> operator[](int comp)
1171  {
1172  int comp_n[1];
1173 
1174  comp_n[0] = comp;
1175 
1176  vector_dist_expression_op<vector_dist_expression<prp,vector>,boost::mpl::int_<1>,VECT_COMP> v_exp(*this,comp_n,var_id);
1177 
1178  return v_exp;
1179  }
1180 };
1181 
1188 template<typename vector_type>
1190 {
1193  typedef typename boost::mpl::at<typename vector_type::value_type::type,boost::mpl::int_<0>>::type T;
1195  mutable vector v;
1196 
1197 public:
1198 
1199  typedef T * iterator;
1200  typedef const T * const_iterator;
1201 
1202  typedef typename has_vector_kernel<vector>::type is_ker;
1203 
1205  typedef vector vtype;
1206 
1208  typedef T value_type;
1209 
1211  typedef void NN_type;
1212 
1214  static const unsigned int prop = 0;
1215 
1216  int var_id = 0;
1217 
1218  void setVarId(int var_id)
1219  {
1220  this->var_id = var_id;
1221  }
1222 
1224  iterator begin()
1225  {
1226  if (v.size() > 0)
1227  return &v.template get<0>(0);
1228 
1229  return NULL;
1230  }
1231 
1232  const_iterator begin() const
1233  {
1234  if (v.size() > 0)
1235  return &v.template get<0>(0);
1236 
1237  return NULL;
1238  }
1239 
1240  iterator end()
1241  {
1242  if (v.size() > 0)
1243  return &v.template get<0>(v.size()-1)+1;
1244 
1245  return NULL;
1246  }
1247 
1248  const_iterator end() const
1249  {
1250  if (v.size() > 0)
1251  return &v.template get<0>(v.size()-1)+1;
1252 
1253  return NULL;
1254  }
1255 
1256  size_t size() const
1257  { return v.size(); }
1258 
1259  void resize(size_t n)
1260  {
1261  // Here
1262 
1263  v.resize(n);
1264  }
1265 
1266 /* T * begin() {
1267  return &v.template get<0>(0);
1268  }
1269 
1270  T * end() {
1271  return &v.template get<0>(v.size()-1);
1272  }*/
1273 
1274  // ... [ implement container interface ]
1275 //]
1276  //const double & operator[]( const size_t n ) const
1277  //{ return m_v[n]; }
1278 
1279  //double & operator[]( const size_t n )
1280  //{ return m_v[n]; }
1281 
1282 
1284 
1286  {}
1287 
1288  template<unsigned int prp2, typename vector2>
1290  {
1291  this->operator=(v_exp);
1292  };
1293 
1294  template<typename exp1, typename exp2, unsigned int op>
1296  {
1297  this->operator=(v_exp);
1298  }
1299 
1305  inline void * getNN() const
1306  {
1307  return NULL;
1308  }
1309 
1317  __device__ __host__ const vector & getVector() const
1318  {
1319  return v;
1320  }
1321 
1329  __device__ __host__ vector & getVector()
1330  {
1331  return v;
1332  }
1333 
1339  inline void init() const
1340  {}
1341 
1349  __host__ __device__ inline auto value(const vect_dist_key_dx & k) const -> decltype(v.template get<0>(k.getKey()))
1350  {
1351  return v.template get<0>(k.getKey());
1352  }
1353 
1354 
1362  template<unsigned int prp2, typename vector2> vector & operator=(const vector_dist_expression<prp2,vector2> & v_exp)
1363  {
1364  if (v_exp.getVector().isSubset() == true)
1365  {
1366  std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1367  return v;
1368  }
1369 
1370  v.resize(v_exp.getVector().size_local());
1371  constexpr bool cond=has_vector_kernel<vector>::type::value || std::is_same<vector,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value;
1372 
1374  {
1376  ::compute_expr(v,v_exp);
1377  }
1378  else
1379  {
1381  }
1382 
1383  return v;
1384  }
1385 
1386 
1394  template<typename exp1, typename exp2, unsigned int op>
1396  {
1397  if (v_exp.getVector().isSubset() == true)
1398  {
1399  std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1400  return v;
1401  }
1402 
1403  v.resize(v_exp.getVector().size_local());
1404  constexpr bool cond=has_vector_kernel<vector>::type::value || std::is_same<vector,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value;
1405 
1407  {
1410  }
1411  else
1412  {
1414  }
1415 
1416  return v;
1417  }
1418 
1426  vector & operator=(double d)
1427  {
1428  std::cout << __FILE__ << ":" << __LINE__ << " Error: temporal with constants is unsupported" << std::endl;
1429  }
1430 
1431 
1432  template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
1433  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
1434  {
1435  std::cout << __FILE__ << ":" << __LINE__ << " Error: use of temporal is not supported to construct equations";
1436  }
1437 
1438  inline vector_dist_expression_op<vector_dist_expression<0,vector>,boost::mpl::int_<1>,VECT_COMP> operator[](int comp)
1439  {
1440  int comp_n[1];
1441 
1442  comp_n[0] = comp;
1443 
1444  vector_dist_expression_op<vector_dist_expression<0,vector>,boost::mpl::int_<1>,VECT_COMP> v_exp(*this,comp_n,var_id);
1445 
1446  return v_exp;
1447  }
1448 };
1449 
1456 template<typename T, typename memory,template <typename> class layout_base >
1457 class vector_dist_expression<0,openfpm::vector<aggregate<T>,memory, layout_base> > : public vector_dist_expression_impl<openfpm::vector<aggregate<T>,memory, layout_base>>
1458 {
1459  typedef openfpm::vector<aggregate<T>,memory, layout_base> vector;
1461 
1462 public:
1464  {
1465  }
1466 
1467  template<unsigned int prp2, typename vector2>
1469  :base(v_exp)
1470  {
1471  }
1472 
1473  template<typename exp1, typename exp2, unsigned int op>
1475  :base(v_exp)
1476  {
1477  }
1478 
1479  template<unsigned int prp2, typename vector2> vector & operator=(const vector_dist_expression<prp2,vector2> & v_exp)
1480  {
1481  return base::operator=(v_exp);
1482  }
1483  template<typename exp1, typename exp2, unsigned int op>
1485  {
1486  return base::operator=(v_exp);
1487  }
1488 };
1489 
1496 template<typename T>
1497 class vector_dist_expression<0,openfpm::vector_gpu<aggregate<T>>> : public vector_dist_expression_impl<openfpm::vector_gpu<aggregate<T>>>
1498 {
1501 public:
1503  {
1504  }
1505 
1506  template<unsigned int prp2, typename vector2>
1508  :base(v_exp)
1509  {
1510  }
1511 
1512  template<typename exp1, typename exp2, unsigned int op>
1514  :base(v_exp)
1515  {
1516  }
1517 
1518  template<unsigned int prp2, typename vector2> vector & operator=(const vector_dist_expression<prp2,vector2> & v_exp)
1519  {
1520  return base::operator=(v_exp);
1521  }
1522 
1524  {
1525  return base::operator=(v_exp);
1526  }
1527 
1528  vector & equalGPU(const vector_dist_expression<0,openfpm::vector_gpu<aggregate<T>>> & v_exp)
1529  {
1530  return base::operator=(v_exp);
1531  }
1532 
1533  template<typename exp1, typename exp2, unsigned int op>
1535  {
1536  return base::operator=(v_exp);
1537  }
1538 
1539 
1540 };
1541 
1542 template<typename T> using texp_v = vector_dist_expression<0,openfpm::vector<aggregate<T>>>;
1544 
1545 
1546 template<typename vector, unsigned int impl>
1548 {
1549  typedef vector type;
1550 
1551  static vector & get(vector & v) {return v;};
1552 
1553  template<typename exp_type, typename vector_klist>
1554  static void register_vector(exp_type & exp_v, vector_klist & v)
1555  {
1556  }
1557 };
1558 
1559 template<typename vector>
1560 struct switcher_get_v<vector,comp_dev>
1561 {
1562  typedef decltype(std::declval<vector>().toKernel()) type;
1563 
1564  static type get(vector & v) {return v.toKernel();};
1565 
1566  template<typename exp_type, typename vector_klist>
1567  static void register_vector(exp_type & exp_v, vector_klist & v)
1568  {
1569  exp_v.set_vector_dist_ker_list(v.private_get_vector_dist_ker_list());
1570  }
1571 };
1572 
1573 /*template<unsigned int, bool is_valid>
1574 struct get_vector_dist_expression_op
1575 {
1576  template<typename exp_type>
1577  inline static auto get(exp_type & o1, const vect_dist_key_dx & key) -> decltype(o1.value(vect_dist_key_dx(0)))
1578  {
1579  return o1.value(key);
1580  }
1581 
1582  template<unsigned int prop, typename exp_type, typename vector_type>
1583  inline static void assign(exp_type & o1, vector_type & v, const vect_dist_key_dx & key)
1584  {
1585  pos_or_propL<vector_type,exp_type::prop>::value(v,key) = o1.value(key);
1586  }
1587 
1588  template<unsigned int prop, typename vector_type>
1589  inline static void assign_double(double d, vector_type & v, const vect_dist_key_dx & key)
1590  {
1591  pos_or_propL<vector_type,prop>::value(v,key) = d;
1592  }
1593 };
1594 
1595 template<>
1596 struct get_vector_dist_expression_op<1,false>
1597 {
1598  template<typename exp_type>
1599  static int get(exp_type & o1, const vect_dist_key_dx & key, const int (& comp)[1])
1600  {
1601  printf("ERROR: Slicer, the expression is incorrect, please check it\n");
1602  return 0;
1603  }
1604 
1605  template<unsigned int prop, typename exp_type, typename vector_type>
1606  inline static void assign(exp_type & o1, vector_type & v, const vect_dist_key_dx & key)
1607  {
1608  printf("ERROR: Slicer, the expression is incorrect, please check it\n");
1609  }
1610 
1611  template<unsigned int prop, typename vector_type>
1612  inline static void assign_double(double d, vector_type & v, const vect_dist_key_dx & key)
1613  {
1614  printf("ERROR: Slicer, the expression is incorrect, please check it\n");
1615  }
1616 };
1617 
1618 template<>
1619 struct get_vector_dist_expression_op<1,true>
1620 {
1621  template<typename exp_type>
1622  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])
1623  {
1624  return o1.value(key)[comp[0]];
1625  }
1626 
1627  template<unsigned int prop,typename exp_type, typename vector_type>
1628  inline static void assign(exp_type & o1, vector_type & v, const vect_dist_key_dx & key, const int (& comp)[1])
1629  {
1630  pos_or_propL<vector_type,prop>::value(v,key)[comp[0]] = o1.value(key);
1631  }
1632 
1633  template<unsigned int prop, typename vector_type>
1634  inline static void assign_double(double d, vector_type & v, const vect_dist_key_dx & key, const int (& comp)[1])
1635  {
1636  pos_or_propL<vector_type,prop>::value(v,key)[comp[0]] = d;
1637  }
1638 };
1639 
1640 template<>
1641 struct get_vector_dist_expression_op<2,true>
1642 {
1643  template<typename exp_type>
1644  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])
1645  {
1646  return o1.value(key)[comp[0]][comp[1]];
1647  }
1648 
1649  template<unsigned int prop,typename exp_type, typename vector_type>
1650  inline static void assign(exp_type & o1, vector_type & v, const vect_dist_key_dx & key, const int (& comp)[2])
1651  {
1652  pos_or_propL<vector_type,prop>::value(v,key)[comp[0]][comp[1]] = o1.value(key);
1653  }
1654 
1655  template<unsigned int prop, typename vector_type>
1656  inline static void assign_double(double d, vector_type & v, const vect_dist_key_dx & key, const int (& comp)[2])
1657  {
1658  pos_or_propL<vector_type,prop>::value(v,key)[comp[0]][comp[1]] = d;
1659  }
1660 };*/
1661 
1662 
1667 template <typename exp1,int n>
1668 class vector_dist_expression_op<exp1,boost::mpl::int_<n>,VECT_COMP>
1669 {
1671  exp1 o1;
1672 
1674  int comp[n];
1675 
1676  int var_id = 0;
1677  void setVarId(int var_id)
1678  {
1679  this->var_id = var_id;
1680  }
1681 
1682  typedef vector_dist_expression_op<exp1,boost::mpl::int_<n>,VECT_COMP> myself;
1683 
1684 public:
1685 
1686  typedef std::false_type is_ker;
1687 
1688  typedef boost::mpl::bool_<false> NN_type;
1689 
1690  typedef typename exp1::vtype vtype;
1691  typedef typename boost::mpl::at<typename vtype::value_type::type,boost::mpl::int_<0>>::type T;
1692 
1694 
1695  vector_dist_expression_op(const exp1 & o1, int (& comp)[n], int var_id)
1696  :o1(o1),var_id(var_id)
1697  {
1698  for (int i = 0 ; i < n ; i++)
1699  {this->comp[i] = comp[i];}
1700  }
1701 
1709  __device__ __host__ const vtype & getVector() const
1710  {
1711  return o1.getVector();
1712  }
1713 
1721  __device__ __host__ vtype & getVector()
1722  {
1723  return o1.getVector();
1724  }
1725 
1727  inline void init() const
1728  {
1729  o1.init();
1730  }
1731 
1733  //typedef typename boost::mpl::at<typename vtype::value_type::type,boost::mpl::int_<exp1::prop>>::type property_act;
1734  typedef typename pos_or_propL<vtype,exp1::prop>::property_act property_act;
1735 
1746  __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))
1747  {
1749  }
1750 
1761  __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))
1762  {
1764  }
1765 
1776  inline auto get(const vect_dist_key_dx & key) const -> decltype(value(key))
1777  {
1778  return this->value(key);
1779  }
1780 
1781  template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
1782  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
1783  {
1784 #ifdef SE_CLASS1
1785 
1786  if (n != 1)
1787  {
1788  std::cout << __FILE__ << ":" << __LINE__ << " Error it only work for tensore of rank 1 ... like vectors " << std::endl;
1789  }
1790 
1791 #endif
1792 
1793  o1.template value_nz<Sys_eqs>(p_map,key,cols,coeff,comp_ + var_id + comp[0]);
1794  }
1795 
1796  inline vector_dist_expression_op<exp1,boost::mpl::int_<n+1>,VECT_COMP> operator[](int comp_)
1797  {
1798  int comp_n[n+1];
1799 
1800  for (int i = 0 ; i < n ; i++)
1801  {comp_n[i] = comp[i];}
1802  comp_n[n] = comp_;
1803 
1804  vector_dist_expression_op<exp1,boost::mpl::int_<n+1>,VECT_COMP> v_exp(o1,comp_n,var_id);
1805 
1806  return v_exp;
1807  }
1808 
1816  template<typename T, typename memory> vtype & operator=(const vector_dist_expression<0,openfpm::vector<aggregate<T>,memory>> & v_exp)
1817  {
1818  v_exp.init();
1819 
1820  auto & v = getVector();
1821 /*#ifdef SE_CLASS1
1822  auto &v2=v_exp.getVector();
1823 
1824  SubsetSelector_impl<std::remove_reference<decltype(v)>::type::is_it_a_subset::value>::check(v2,v);
1825 #endif*/
1826 
1827  auto it = v.getDomainIterator();
1828 
1829  while (it.isNext())
1830  {
1831  auto key = it.get();
1832 
1833  get_vector_dist_expression_op<n,n == rank_gen<property_act>::type::value>::template assign<exp1::prop>(v_exp,v,key,comp);
1834 
1835  ++it;
1836  }
1837 
1838  return v;
1839  }
1840 
1848  template<unsigned int prp2> vtype & operator=(const vector_dist_expression<prp2,vtype> & v_exp)
1849  {
1850  v_exp.init();
1851 
1852  auto & v = getVector();
1853 #ifdef SE_CLASS1
1854  auto &v2=v_exp.getVector();
1855 
1856  SubsetSelector_impl<std::remove_reference<decltype(v)>::type::is_it_a_subset::value>::check(v2,v);
1857 #endif
1858  auto it = v.getDomainIterator();
1859 
1860  while (it.isNext())
1861  {
1862  auto key = it.get();
1863 
1864  get_vector_dist_expression_op<n,n == rank_gen<property_act>::type::value>::template assign<exp1::prop>(v_exp,v,key,comp);
1865 
1866  ++it;
1867  }
1868 
1869  return v;
1870  }
1871 
1879  template<typename exp1_, typename exp2_, unsigned int op> vtype & operator=(const vector_dist_expression_op<exp1_,exp2_,op> & v_exp)
1880  {
1881  if (v_exp.getVector().isSubset() == true)
1882  {
1883  std::cout << __FILE__ << ":" << __LINE__ << " error on the right hand side of the expression you have to use non-subset properties" << std::endl;
1884  return this->getVector();
1885  }
1886  v_exp.init();
1887  auto &v = o1.getVector();
1888  //v.resize(v_exp.getVector().size_local());
1889  constexpr bool cond=has_vector_kernel<vtype>::type::value || std::is_same<vtype,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value;
1890 
1892  {
1894  ::compute_expr_slice(v,v_exp,comp);
1895  }
1896  else
1897  {
1898  constexpr bool cond_slice = !std::is_same<vtype,openfpm::vector<aggregate<T>,CudaMemory,memory_traits_inte>>::value;
1900  }
1901 
1902 
1903  return this->getVector();
1904  }
1905 
1913  vtype & operator=(double d)
1914  {
1915  auto & v = getVector();
1916 
1917  auto it = v.getDomainIterator();
1918 
1919  while (it.isNext())
1920  {
1921  auto key = it.get();
1922 
1923  //pos_or_propL<vtype,exp1::prp>::value(v,key) = d;
1924  get_vector_dist_expression_op<n,n == rank_gen<property_act>::type::value>::template assign_double<exp1::prop>(d,v,key,comp);
1925 
1926 
1927  ++it;
1928  }
1929 
1930  return v;
1931  }
1932 };
1933 
1940 template <unsigned int prp,unsigned int impl = comp_host, typename vector>
1942 {
1945 
1947 
1948  return exp_v;
1949 }
1950 
1956 template<unsigned int prp>
1957 class vector_dist_expression<prp,double>
1958 {
1960  double d;
1961 
1962 public:
1963 
1964  typedef std::false_type is_ker;
1965 
1966  typedef void NN_type;
1967 
1969  inline vector_dist_expression(const double & d)
1970  :d(d)
1971  {}
1972 
1978  inline void init() const
1979  {}
1980 
1990  __device__ __host__ inline double value(const vect_dist_key_dx & k) const
1991  {
1992  return d;
1993  }
1994 
1995 
1996  template<typename Sys_eqs, typename pmap_type, typename unordered_map_type, typename coeff_type>
1997  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
1998  {
1999  cols[p_map. template getProp<0>(key)*Sys_eqs::nvar + comp] += coeff;
2000  }
2010  __host__ __device__ inline double value(const unsigned int & k) const
2011  {
2012  return d;
2013  }
2014 };
2015 
2016 
2022 template<unsigned int prp>
2024 {
2026  float d;
2027 
2028 public:
2029 
2030  typedef std::false_type is_ker;
2031 
2032  typedef void NN_type;
2033 
2035  inline vector_dist_expression(const float & d)
2036  :d(d)
2037  {}
2038 
2044  inline void init() const
2045  {}
2046 
2056  inline float value(const vect_dist_key_dx & k) const
2057  {
2058  return d;
2059  }
2060 
2070  __device__ __host__ inline float value(const unsigned int & k) const
2071  {
2072  return d;
2073  }
2074 };
2075 
2076 /* \brief sum two distributed vector expression
2077  *
2078  * \param va vector expression one
2079  * \param vb vector expression two
2080  *
2081  * \return an object that encapsulate the expression
2082  *
2083  */
2084 template<unsigned int p1, unsigned int p2, typename v1, typename v2>
2086 operator+(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
2087 {
2089 
2090  return exp_sum;
2091 }
2092 
2093 /* \brief sum two distributed vector expression
2094  *
2095  * \param va vector expression one
2096  * \param vb vector expression two
2097  *
2098  * \return an object that encapsulate the expression
2099  *
2100  */
2101 template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>
2104 {
2106 
2107  return exp_sum;
2108 }
2109 
2110 /* \brief sum two distributed vector expression
2111  *
2112  * \param va vector expression one
2113  * \param vb vector expression two
2114  *
2115  * \return an object that encapsulate the expression
2116  *
2117  */
2118 template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>
2121 {
2123 
2124  return exp_sum;
2125 }
2126 
2127 /* \brief sum two distributed vector expression
2128  *
2129  * \param va vector expression one
2130  * \param vb vector expression two
2131  *
2132  * \return an object that encapsulate the expression
2133  *
2134  */
2135 template<typename exp1 , typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>
2138 {
2140 
2141  return exp_sum;
2142 }
2143 
2144 /* \brief sum two distributed vector expression
2145  *
2146  * \param va vector expression one
2147  * \param vb vector expression two
2148  *
2149  * \return an object that encapsulate the expression
2150  *
2151  */
2152 template<unsigned int prp1 , typename v1>
2154 operator+(const vector_dist_expression<prp1,v1> & va, double d)
2155 {
2157 
2158  return exp_sum;
2159 }
2160 
2161 /* \brief sum two distributed vector expression
2162  *
2163  * \param va vector expression one
2164  * \param vb vector expression two
2165  *
2166  * \return an object that encapsulate the expression
2167  *
2168  */
2169 template<typename T, unsigned int prp1, typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2171 operator+(const vector_dist_expression<prp1,v1> & va, T d)
2172 {
2174 
2175  return exp_sum;
2176 }
2177 
2178 /* \brief sum two distributed vector expression
2179  *
2180  * \param va vector expression one
2181  * \param vb vector expression two
2182  *
2183  * \return an object that encapsulate the expression
2184  *
2185  */
2186 template<unsigned int prp1 , typename v1>
2188 operator+(double d, const vector_dist_expression<prp1,v1> & vb)
2189 {
2191 
2192  return exp_sum;
2193 }
2194 
2195 /* \brief sum two distributed vector expression
2196  *
2197  * \param va vector expression one
2198  * \param vb vector expression two
2199  *
2200  * \return an object that encapsulate the expression
2201  *
2202  */
2203 template<unsigned int prp1 , typename v1>
2205 operator+(float d, const vector_dist_expression<prp1,v1> & vb)
2206 {
2208 
2209  return exp_sum;
2210 }
2211 
2212 /* \brief sum two distributed vector expression
2213  *
2214  * \param va vector expression one
2215  * \param vb vector expression two
2216  *
2217  * \return an object that encapsulate the expression
2218  *
2219  */
2220 template<typename exp1 , typename exp2, unsigned int op1>
2222 operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
2223 {
2225 
2226  return exp_sum;
2227 }
2228 
2229 /* \brief sum two distributed vector expression
2230  *
2231  * \param va vector expression one
2232  * \param vb vector expression two
2233  *
2234  * \return an object that encapsulate the expression
2235  *
2236  */
2237 template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2239 operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, T d)
2240 {
2242 
2243  return exp_sum;
2244 }
2245 
2246 /* \brief subtract two distributed vector expression
2247  *
2248  * \param va vector expression one
2249  * \param vb vector expression two
2250  *
2251  * \return an object that encapsulate the expression
2252  *
2253  */
2254 template<unsigned int p1, unsigned int p2, typename v1, typename v2>
2256 operator-(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
2257 {
2259 
2260  return exp_sum;
2261 }
2262 
2263 
2264 /* \brief subtract two distributed vector expression
2265  *
2266  * \param va vector expression one
2267  * \param vb vector expression two
2268  *
2269  * \return an object that encapsulate the expression
2270  *
2271  */
2272 template<typename exp1, typename exp2, unsigned int op1, unsigned int p2, typename v2>
2275 {
2277 
2278  return exp_sum;
2279 }
2280 
2281 /* \brief minus of a distributed vector expression operator
2282  *
2283  * \param va vector expression one
2284  *
2285  * \return an object that encapsulate the expression
2286  *
2287  */
2288 template<typename exp1, typename exp2_, unsigned int op1>
2290 operator-(const vector_dist_expression_op<exp1,exp2_,op1> & va)
2291 {
2293 
2294  return exp_sum;
2295 }
2296 
2297 /* \brief minus of a distributed vector expression
2298  *
2299  * \param va vector expression one
2300  *
2301  * \return an object that encapsulate the expression
2302  *
2303  */
2304 template<unsigned int p1, typename v1>
2306 operator-(const vector_dist_expression<p1,v1> & va)
2307 {
2308  vector_dist_expression_op<vector_dist_expression<p1,v1>,void,VECT_SUB_UNI> exp_sum(va);
2309 
2310  return exp_sum;
2311 }
2312 
2313 
2314 /* \brief subtract two distributed vector expression
2315  *
2316  * \param va vector expression one
2317  * \param vb vector expression two
2318  *
2319  * \return an object that encapsulate the expression
2320  *
2321  */
2322 template<typename exp1, typename exp2, unsigned int op1, unsigned int p2, typename v2>
2325 {
2327 
2328  return exp_sum;
2329 }
2330 
2331 /* \brief subtract two distributed vector expression
2332  *
2333  * \param va vector expression one
2334  * \param vb vector expression two
2335  *
2336  * \return an object that encapsulate the expression
2337  *
2338  */
2339 template<typename exp1, typename exp2, unsigned int op1, typename exp3, typename exp4, unsigned int op2>
2342 {
2344 
2345  return exp_sum;
2346 }
2347 
2348 /* \brief subtract two distributed vector expression
2349  *
2350  * \param va vector expression one
2351  * \param vb vector expression two
2352  *
2353  * \return an object that encapsulate the expression
2354  *
2355  */
2356 template<unsigned int prp1, typename v1>
2358 operator-(const vector_dist_expression<prp1,v1> & va, double d)
2359 {
2361 
2362  return exp_sum;
2363 }
2364 
2365 /* \brief subtract two distributed vector expression
2366  *
2367  * \param va vector expression one
2368  * \param vb vector expression two
2369  *
2370  * \return an object that encapsulate the expression
2371  *
2372  */
2373 //template<unsigned int prp1, typename v1>
2374 template<typename T, unsigned int prp1,typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2376 operator-(const vector_dist_expression<prp1,v1> & va, T d)
2377 {
2379 
2380  return exp_sum;
2381 }
2382 
2383 /* \brief subtract two distributed vector expression
2384  *
2385  * \param va vector expression one
2386  * \param vb vector expression two
2387  *
2388  * \return an object that encapsulate the expression
2389  *
2390  */
2391 template<unsigned int prp1, typename v1>
2393 operator-(double d, const vector_dist_expression<prp1,v1> & vb)
2394 {
2396 
2397  return exp_sum;
2398 }
2399 
2400 /* \brief subtract two distributed vector expression
2401  *
2402  * \param va vector expression one
2403  * \param vb vector expression two
2404  *
2405  * \return an object that encapsulate the expression
2406  *
2407  */
2408 template<typename T, unsigned int prp1,typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2410 operator-(T d, const vector_dist_expression<prp1,v1> & vb)
2411 {
2413 
2414  return exp_sum;
2415 }
2416 
2417 /* \brief Multiply two distributed vector expression
2418  *
2419  * \param va vector expression one
2420  * \param vb vector expression two
2421  *
2422  * \return an object that encapsulate the expression
2423  *
2424  */
2425 template<unsigned int p2, typename v2>
2427 operator*(double d, const vector_dist_expression<p2,v2> & vb)
2428 {
2430 
2431  return exp_sum;
2432 }
2433 
2434 /* \brief Multiply two distributed vector expression
2435  *
2436  * \param va vector expression one
2437  * \param vb vector expression two
2438  *
2439  * \return an object that encapsulate the expression
2440  *
2441  */
2442 template<typename T, unsigned int p2,typename v2, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2444 operator*(T d, const vector_dist_expression<p2,v2> & vb)
2445 {
2447 
2448  return exp_sum;
2449 }
2450 
2451 /* \brief Multiply two distributed vector expression
2452  *
2453  * \param va vector expression one
2454  * \param vb vector expression two
2455  *
2456  * \return an object that encapsulate the expression
2457  *
2458  */
2459 template<unsigned int p2, typename v2>
2461 operator*(const vector_dist_expression<p2,v2> & va, double d)
2462 {
2464 
2465  return exp_sum;
2466 }
2467 
2468 /* \brief Multiply two distributed vector expression
2469  *
2470  * \param va vector expression one
2471  * \param vb vector expression two
2472  *
2473  * \return an object that encapsulate the expression
2474  *
2475  */
2476 template<typename T, unsigned int p2,typename v2, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2478 operator*(const vector_dist_expression<p2,v2> & va, T d)
2479 {
2481 
2482  return exp_sum;
2483 }
2484 
2485 /* \brief Multiply two distributed vector expression
2486  *
2487  * \param va vector expression one
2488  * \param vb vector expression two
2489  *
2490  * \return an object that encapsulate the expression
2491  *
2492  */
2493 template<unsigned int p1, typename v1,unsigned int p2, typename v2>
2495 operator*(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
2496 {
2498 
2499  return exp_sum;
2500 }
2501 
2502 /* \brief Multiply two distributed vector expression
2503  *
2504  * \param va vector expression one
2505  * \param vb vector expression two
2506  *
2507  * \return an object that encapsulate the expression
2508  *
2509  */
2510 template<unsigned int p1, typename v1, typename exp1, typename exp2, unsigned int op1>
2513 {
2515 
2516  return exp_sum;
2517 }
2518 
2519 /* \brief Multiply two distributed vector expression
2520  *
2521  * \param va vector expression one
2522  * \param vb vector expression two
2523  *
2524  * \return an object that encapsulate the expression
2525  *
2526  */
2527 template<unsigned int p1, typename v1, typename exp1, typename exp2, unsigned int op1>
2530 {
2532 
2533  return exp_sum;
2534 }
2535 
2536 /* \brief Multiply two distributed vector expression
2537  *
2538  * \param va vector expression one
2539  * \param vb vector expression two
2540  *
2541  * \return an object that encapsulate the expression
2542  *
2543  */
2544 template<typename exp1, typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>
2547 {
2549 
2550  return exp_sum;
2551 }
2552 
2553 /* \brief Multiply a distributed vector expression by a number
2554  *
2555  * \param va vector expression
2556  * \param d number
2557  *
2558  * \return an object that encapsulate the expression
2559  *
2560  */
2561 template<typename exp1 , typename exp2, unsigned int op1>
2563 operator*(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
2564 {
2566 
2567  return exp_sum;
2568 }
2569 
2570 /* \brief Multiply a distributed vector expression by a number
2571  *
2572  * \param va vector expression
2573  * \param d number
2574  *
2575  * \return an object that encapsulate the expression
2576  *
2577  */
2578 template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2580 operator*(const vector_dist_expression_op<exp1,exp2,op1> & va, T d)
2581 {
2583 
2584  return exp_sum;
2585 }
2586 
2587 /* \brief Multiply a distributed vector expression by a number
2588  *
2589  * \param d number
2590  * \param vb vector expression
2591  *
2592  * \return an object that encapsulate the expression
2593  *
2594  */
2595 template<typename exp1 , typename exp2, unsigned int op1>
2597 operator*(double d, const vector_dist_expression_op<exp1,exp2,op1> & vb)
2598 {
2600 
2601  return exp_sum;
2602 }
2603 
2604 /* \brief Multiply a distributed vector expression by a number
2605  *
2606  * \param d number
2607  * \param vb vector expression
2608  *
2609  * \return an object that encapsulate the expression
2610  *
2611  */
2612 template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2614 operator*(T d, const vector_dist_expression_op<exp1,exp2,op1> & vb)
2615 {
2617 
2618  return exp_sum;
2619 }
2620 
2621 /* \brief Divide two distributed vector expression
2622  *
2623  * \param va vector expression one
2624  * \param vb vector expression two
2625  *
2626  * \return an object that encapsulate the expression
2627  *
2628  */
2629 template<typename exp1, typename exp2, unsigned int op1>
2631 operator/(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
2632 {
2634 
2635  return exp_sum;
2636 }
2637 
2638 /* \brief Divide two distributed vector expression
2639  *
2640  * \param va vector expression one
2641  * \param vb vector expression two
2642  *
2643  * \return an object that encapsulate the expression
2644  *
2645  */
2646 template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2648 operator/(const vector_dist_expression_op<exp1,exp2,op1> & va, T d)
2649 {
2651 
2652  return exp_sum;
2653 }
2654 
2655 /* \brief Divide two distributed vector expression
2656  *
2657  * \param va vector expression one
2658  * \param vb vector expression two
2659  *
2660  * \return an object that encapsulate the expression
2661  *
2662  */
2663 template<typename exp1, typename exp2, unsigned int op1>
2665 operator/(double d, const vector_dist_expression_op<exp1,exp2,op1> & va)
2666 {
2668 
2669  return exp_sum;
2670 }
2671 
2672 /* \brief Divide two distributed vector expression
2673  *
2674  * \param va vector expression one
2675  * \param vb vector expression two
2676  *
2677  * \return an object that encapsulate the expression
2678  *
2679  */
2680 template<typename T, typename exp1 , typename exp2, unsigned int op1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2682 operator/(T d, const vector_dist_expression_op<exp1,exp2,op1> & va)
2683 {
2685 
2686  return exp_sum;
2687 }
2688 
2689 /* \brief Divide two distributed vector expression
2690  *
2691  * \param va vector expression one
2692  * \param vb vector expression two
2693  *
2694  * \return an object that encapsulate the expression
2695  *
2696  */
2697 template<unsigned int prp1, typename v1>
2699 operator/(const vector_dist_expression<prp1,v1> & va, double d)
2700 {
2702 
2703  return exp_sum;
2704 }
2705 
2706 /* \brief Divide two distributed vector expression
2707  *
2708  * \param va vector expression one
2709  * \param vb vector expression two
2710  *
2711  * \return an object that encapsulate the expression
2712  *
2713  */
2714 template<typename T, unsigned int prp1,typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2716 operator/(const vector_dist_expression<prp1,v1> & va, T d)
2717 {
2719 
2720  return exp_sum;
2721 }
2722 
2723 /* \brief Divide two distributed vector expression
2724  *
2725  * \param va vector expression one
2726  * \param vb vector expression two
2727  *
2728  * \return an object that encapsulate the expression
2729  *
2730  */
2731 template<unsigned int prp1, typename v1>
2733 operator/(double d, const vector_dist_expression<prp1,v1> & va)
2734 {
2736 
2737  return exp_sum;
2738 }
2739 
2740 /* \brief Divide two distributed vector expression
2741  *
2742  * \param va vector expression one
2743  * \param vb vector expression two
2744  *
2745  * \return an object that encapsulate the expression
2746  *
2747  */
2748 template<typename T, unsigned int prp1,typename v1, typename sfinae = typename std::enable_if<std::is_same<T,float>::value>::type >
2750 operator/(T d, const vector_dist_expression<prp1,v1> & va)
2751 {
2753 
2754  return exp_sum;
2755 }
2756 
2757 /* \brief Divide two distributed vector expression
2758  *
2759  * \param va vector expression one
2760  * \param vb vector expression two
2761  *
2762  * \return an object that encapsulate the expression
2763  *
2764  */
2765 template<unsigned int prp1, typename v1, unsigned int prp2, typename v2>
2767 operator/(const vector_dist_expression<prp1,v1> & va, const vector_dist_expression<prp2,v2> & vb)
2768 {
2770 
2771  return exp_sum;
2772 }
2773 
2774 /* \brief Divide two distributed vector expression
2775  *
2776  * \param va vector expression one
2777  * \param vb vector expression two
2778  *
2779  * \return an object that encapsulate the expression
2780  *
2781  */
2782 template<unsigned int prp1, typename v1, typename exp1,typename exp2, unsigned int op1>
2785 {
2787 
2788  return exp_sum;
2789 }
2790 
2791 /* \brief Divide two distributed vector expression
2792  *
2793  * \param va vector expression one
2794  * \param vb vector expression two
2795  *
2796  * \return an object that encapsulate the expression
2797  *
2798  */
2799 template<unsigned int prp1, typename v1, typename exp1,typename exp2, unsigned int op1>
2802 {
2804 
2805  return exp_sum;
2806 }
2807 
2808 /* \brief Divide two distributed vector expression
2809  *
2810  * \param va vector expression one
2811  * \param vb vector expression two
2812  *
2813  * \return an object that encapsulate the expression
2814  *
2815  */
2816 template<typename exp1,typename exp2, unsigned int op1, typename exp3, typename exp4, unsigned int op2>
2819 {
2821 
2822  return exp_sum;
2823 }
2824 
2825 #include "vector_dist_operators_apply_kernel.hpp"
2826 #include "vector_dist_operators_functions.hpp"
2827 #include "vector_dist_operators_extensions.hpp"
2828 #include "Operators/Vector/vector_dist_operator_assign.hpp"
2829 
2830 
2831 #endif /* OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_HPP_ */
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:204
Grid key for a distributed grid.
__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.
Main class that encapsulate a float constant.
vector_dist_expression(const float &d)
constrictor from constant value
__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.
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.
__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.
void init() const
This function must be called before value.
vector v
The temporal vector.
__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
vector & operator=(const vector_dist_expression_op< exp1, exp2, op > &v_exp)
Fill the vector property with the evaluated expression.
vector & operator=(double d)
Fill the vector property with the double.
pos_or_propL< vtype, exp1::prop >::property_act property_act
property on which this view is acting
auto get(const vect_dist_key_dx &key) const -> decltype(value(key))
Return the result of the expression.
__device__ __host__ const vtype & getVector() const
Return the vector on which is acting.
vtype & operator=(const vector_dist_expression< 0, openfpm::vector< aggregate< T >, memory >> &v_exp)
Fill the vector property with the evaluated expression.
vtype & operator=(const vector_dist_expression_op< exp1_, exp2_, op > &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.
vtype & operator=(const vector_dist_expression< prp2, vtype > &v_exp)
Fill the vector property with the evaluated expression.
__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.
first_or_second< has_vtype< exp1 >::value, exp1, exp2 >::vtype vtype
The type of the internal vector.
const vtype & getVector()
Return the vector on which is acting.
void init() const
This function must be called before value.
__device__ __host__ r_type value(const unsigned int &key) const
Evaluate the expression.
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.
nn_type_result< typename exp1::NN_type, typename exp2::NN_type >::type NN_type
NN_type.
nn_type_result< typename exp1::NN_type, typename exp2::NN_type >::type NN_type
NN_type.
void init() const
This function must be called before value.
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
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.
vector_dist_expression_op(const exp1 &o1, const exp2 &o2)
constructor from two expressions
nn_type_result< typename exp1::NN_type, typename exp2::NN_type >::type NN_type
NN_type.
void init() const
This function must be called before value.
vector_dist_expression_op(const exp1 &o1, const exp2 &o2)
Costruct a subtraction expression out of two expressions.
const vtype & getVector() const
Return the vector on which is acting.
__device__ __host__ r_type value(const unsigned int &key) const
Evaluate the expression.
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.
const vtype & getVector()
Return the vector on which is acting.
nn_type_result< typename exp1::NN_type, typename exp2::NN_type >::type NN_type
NN_type.
const vtype & getVector() const
Return the vector on which is acting.
__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.
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.
const vtype & getVector()
Return the underlying vector.
nn_type_result< typename exp1::NN_type, void >::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_result< typename exp1::vtype, void >::type vtype
return the vector type on which this expression operate
__device__ __host__ r_type value(const unsigned int &key) const
return the result of the expression
void init() const
initialize the expression tree
__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.
v_mem_mutable< typename vector_expression_transform< vector >::type > v
The vector.
vector & operator=(const vector_dist_expression_op< exp1, exp2, op > &v_exp)
Fill the vector property with the evaluated expression.
vector & operator=(const vector_dist_expression< prp2, vector > &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.
__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 & operator=(double d)
Fill the vector property with the double.
void * getNN() const
get the NN object
vector & operator=(const vector_dist_expression< 0, openfpm::vector_gpu< aggregate< T >>> &v_exp)
Fill the vector property with the evaluated expression.
__host__ __device__ auto value(const unsigned int &k) -> decltype(pos_or_propR< vector, prp >::value(v.v, k))
Evaluate the 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.
void set_vector_dist_ker_list(vector_dist_ker_list< vector > &vdkl)
set vector_dist_ker_list
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.
void add(vector_dist_ker_type &v)
Add a new vector_dist_kernel to track.
void remove(vector_dist_ker_type &v)
Remove one vector_dist_kernels entry.
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
Definition: aggregate.hpp:302
Void structure.
Definition: common.hpp:74
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:221
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)
Definition: memory_conf.hpp:84
selector for position or properties right side position
__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
like std::rank but it also work for openfpm structures like Point where it return 1
Definition: Point.hpp:721
Expression implementation computation selector.
Expression implementation computation selector.