8#ifndef VECTOR_DIST_OPERATORS_TESTS_UTIL_HPP_
9#define VECTOR_DIST_OPERATORS_TESTS_UTIL_HPP_
11#include "Operators/Vector/vector_dist_operators.hpp"
12#include "Space/Shape/Point.hpp"
27template <
unsigned int prp,
unsigned int impl,
typename vector>
28bool check_values(vector & v,
float a)
31 {v.template deviceToHostProp<prp>();}
34 auto it = v.getDomainIterator();
38 ret &= v.template getProp<prp>(it.get()) == a;
43 BOOST_REQUIRE_EQUAL(ret,
true);
48template <
unsigned int impl,
typename vector>
49bool check_values_complex_expr(vector & vd)
52 {vd.template deviceToHostProp<A,B,C>();}
55 auto it = vd.getDomainIterator();
61 float base1 = vd.template getProp<B>(key) + 2.0 + vd.template getProp<B>(key) - 2.0*vd.template getProp<C>(key) / 5.0;
62 float base2 = vd.template getProp<A>(key);
64 ret &= base1 == base2;
69 BOOST_REQUIRE_EQUAL(ret,
true);
74template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
75bool check_values_pos_sum(vector & vd,
const rtype & p)
79 vd.template deviceToHostProp<VA>();
84 auto it = vd.getDomainIterator();
92 rtype base1 = rtype(xp) + p;
93 rtype base2 = vd.template getProp<VA>(key);
95 ret &= base1 == base2;
100 BOOST_REQUIRE_EQUAL(ret,
true);
105template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
106bool check_values_pos_integration(vector & vd,
double dt)
108 if (impl == comp_dev)
110 vd.template deviceToHostProp<VA,VB>();
111 vd.deviceToHostPos();
115 auto it = vd.getDomainIterator();
123 rtype base1 = rtype(xp) + rtype(vd.template getProp<VA>(key)) * dt;
124 rtype base2 = vd.getPos(key);
126 ret &= base1 == base2;
131 BOOST_REQUIRE_EQUAL(ret,
true);
136template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
137bool check_values_pos_sub(vector & vd,
const rtype & p)
139 if (impl == comp_dev)
140 {vd.template deviceToHostProp<A>();}
143 auto it = vd.getDomainIterator();
151 rtype base1 = rtype(xp) - p;
152 rtype base2 = vd.template getProp<A>(key);
154 ret &= base1 == base2;
159 BOOST_REQUIRE_EQUAL(ret,
true);
164template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
165bool check_values_pos_sub_minus(vector & vd,
const rtype & p)
167 if (impl == comp_dev)
168 {vd.template deviceToHostProp<A>();}
171 auto it = vd.getDomainIterator();
179 rtype base1 = -(rtype(xp) - p);
180 rtype base2 = vd.template getProp<A>(key);
182 ret &= base1 == base2;
187 BOOST_REQUIRE_EQUAL(ret,
true);
192template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
193bool check_values_point_sub(vector & vd,
const rtype & p)
195 if (impl == comp_dev)
196 {vd.template deviceToHostProp<A,B>();}
199 auto it = vd.getDomainIterator();
205 rtype base1 = -vd.template getProp<B>(key);
206 rtype base2 = vd.template getProp<A>(key);
208 ret &= base1 == base2;
213 BOOST_REQUIRE_EQUAL(ret,
true);
218template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
219bool check_values_sum(vector & vd,
double d)
221 if (impl == comp_dev)
222 {vd.template deviceToHostProp<A,B>();}
225 auto it = vd.getDomainIterator();
231 rtype base1 = vd.template getProp<B>(key) + d;
232 rtype base2 = vd.template getProp<A>(key);
234 ret &= base1 == base2;
239 BOOST_REQUIRE_EQUAL(ret,
true);
244template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
245bool check_values_sum(vector & vd1, vector & vd2)
247 if (impl == comp_dev)
249 vd1.template deviceToHostProp<A,B>();
250 vd2.template deviceToHostProp<C>();
254 auto it = vd1.getDomainIterator();
260 rtype base1 = vd1.template getProp<B>(key) + vd2.template getProp<C>(key);
261 rtype base2 = vd1.template getProp<A>(key);
263 ret &= base1 == base2;
268 BOOST_REQUIRE_EQUAL(ret,
true);
273template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
274bool check_values_sum_3(vector & vd1)
276 if (impl == comp_dev)
277 {vd1.template deviceToHostProp<A,B>();}
280 auto it = vd1.getDomainIterator();
286 rtype base1 = vd1.template getProp<B>(key) + vd1.template getProp<C>(key) + vd1.template getProp<B>(key);
287 rtype base2 = vd1.template getProp<A>(key);
289 ret &= base1 == base2;
294 BOOST_REQUIRE_EQUAL(ret,
true);
299template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
300bool check_values_sum_4(vector & vd1)
302 if (impl == comp_dev)
303 {vd1.template deviceToHostProp<A,B,C>();}
306 auto it = vd1.getDomainIterator();
312 rtype base1 = (vd1.template getProp<B>(key) + vd1.template getProp<C>(key)) + (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
313 rtype base2 = vd1.template getProp<A>(key);
316 ret &= base1 == base2;
321 BOOST_REQUIRE_EQUAL(ret,
true);
326template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
327bool check_values_sub(vector & vd,
double d)
329 if (impl == comp_dev)
330 {vd.template deviceToHostProp<A,B>();}
333 auto it = vd.getDomainIterator();
339 rtype base1 = vd.template getProp<B>(key) - d;
340 rtype base2 = vd.template getProp<A>(key);
342 ret &= base1 == base2;
347 BOOST_REQUIRE_EQUAL(ret,
true);
352template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
353bool check_values_sub(
double d, vector & vd)
355 if (impl == comp_dev)
356 {vd.template deviceToHostProp<A,B>();}
359 auto it = vd.getDomainIterator();
365 rtype base1 = d - vd.template getProp<B>(key);
366 rtype base2 = vd.template getProp<A>(key);
368 ret &= base1 == base2;
373 BOOST_REQUIRE_EQUAL(ret,
true);
378template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
379bool check_values_sub(vector & vd1, vector & vd2)
381 if (impl == comp_dev)
383 vd1.template deviceToHostProp<A,C>();
384 vd2.template deviceToHostProp<B>();
388 auto it = vd1.getDomainIterator();
394 rtype base1 = vd1.template getProp<C>(key) - vd2.template getProp<B>(key);
395 rtype base2 = vd1.template getProp<A>(key);
397 ret &= base1 == base2;
402 BOOST_REQUIRE_EQUAL(ret,
true);
407template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
408bool check_values_sub_31(vector & vd1)
410 if (impl == comp_dev)
411 {vd1.template deviceToHostProp<A,C>();}
414 auto it = vd1.getDomainIterator();
420 rtype base1 = vd1.template getProp<B>(key) - (vd1.template getProp<C>(key) + vd1.template getProp<B>(key));
421 rtype base2 = vd1.template getProp<A>(key);
423 ret &= base1 == base2;
428 BOOST_REQUIRE_EQUAL(ret,
true);
434template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
435bool check_values_sub_32(vector & vd1)
437 if (impl == comp_dev)
438 {vd1.template deviceToHostProp<A,B,C>();}
441 auto it = vd1.getDomainIterator();
447 rtype base1 = (vd1.template getProp<C>(key) + vd1.template getProp<B>(key)) - vd1.template getProp<B>(key);
448 rtype base2 = vd1.template getProp<A>(key);
450 ret &= base1 == base2;
455 BOOST_REQUIRE_EQUAL(ret,
true);
460template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
461bool check_values_sub_4(vector & vd1)
463 if (impl == comp_dev)
464 {vd1.template deviceToHostProp<A,B,C>();}
467 auto it = vd1.getDomainIterator();
473 rtype base1 = (vd1.template getProp<C>(key) + vd1.template getProp<B>(key)) - (vd1.template getProp<C>(key) + vd1.template getProp<B>(key));
474 rtype base2 = vd1.template getProp<A>(key);
476 if (impl == comp_dev)
478 ret &= (double)norm(base1 - base2) < 0.00001;
482 ret &= base1 == base2;
488 BOOST_REQUIRE_EQUAL(ret,
true);
494template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
495bool check_values_mul(vector & vd,
double d)
497 if (impl == comp_dev)
498 {vd.template deviceToHostProp<A,B>();}
501 auto it = vd.getDomainIterator();
507 rtype base1 = vd.template getProp<B>(key) * d;
508 rtype base2 = vd.template getProp<A>(key);
510 ret &= base1 == base2;
515 BOOST_REQUIRE_EQUAL(ret,
true);
521template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
522bool check_values_mul(vector & vd1, vector & vd2)
524 if (impl == comp_dev)
526 vd1.template deviceToHostProp<A,C>();
527 vd2.template deviceToHostProp<B>();
531 auto it = vd1.getDomainIterator();
537 rtype base1 = vd1.template getProp<C>(key) * vd2.template getProp<B>(key);
538 rtype base2 = vd1.template getProp<A>(key);
540 if (impl == comp_dev)
542 ret &= (double)norm(base1 - base2) < 0.00001;
546 ret &= base1 == base2;
552 BOOST_REQUIRE_EQUAL(ret,
true);
557template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
558bool check_values_mul_3(vector & vd1)
560 if (impl == comp_dev)
561 {vd1.template deviceToHostProp<A,B,C>();}
564 auto it = vd1.getDomainIterator();
570 rtype base1 = vd1.template getProp<B>(key) * (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
571 rtype base2 = vd1.template getProp<A>(key);
573 if (impl == comp_dev)
575 ret &= (double)norm(base1 - base2) < 0.00001;
579 ret &= base1 == base2;
585 BOOST_REQUIRE_EQUAL(ret,
true);
591template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
592bool check_values_mul_4(vector & vd1)
594 if (impl == comp_dev)
595 {vd1.template deviceToHostProp<A,B,C>();}
598 auto it = vd1.getDomainIterator();
604 rtype base1 = (vd1.template getProp<B>(key) + vd1.template getProp<C>(key)) * (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
605 rtype base2 = vd1.template getProp<A>(key);
607 if (impl == comp_dev)
609 ret &= (double)norm(base1 - base2) < 0.00001;
613 ret &= base1 == base2;
619 BOOST_REQUIRE_EQUAL(ret,
true);
626template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
627bool check_values_div(vector & vd,
double d)
629 if (impl == comp_dev)
630 {vd.template deviceToHostProp<A,B>();}
633 auto it = vd.getDomainIterator();
639 rtype base1 = vd.template getProp<B>(key) / d;
640 rtype base2 = vd.template getProp<A>(key);
642 ret &= base1 == base2;
647 BOOST_REQUIRE_EQUAL(ret,
true);
652template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
653bool check_values_div(
double d, vector & vd)
655 if (impl == comp_dev)
656 {vd.template deviceToHostProp<A,B>();}
659 auto it = vd.getDomainIterator();
665 rtype base1 = d / vd.template getProp<B>(key);
666 rtype base2 = vd.template getProp<A>(key);
668 ret &= base1 == base2;
673 BOOST_REQUIRE_EQUAL(ret,
true);
678template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
679bool check_values_div(vector & vd1, vector & vd2)
681 if (impl == comp_dev)
683 vd1.template deviceToHostProp<A,C>();
684 vd2.template deviceToHostProp<B>();
688 auto it = vd1.getDomainIterator();
694 rtype base1 = vd1.template getProp<C>(key) / vd2.template getProp<B>(key);
695 rtype base2 = vd1.template getProp<A>(key);
697 ret &= base1 == base2;
702 BOOST_REQUIRE_EQUAL(ret,
true);
707template<
unsigned int impl,
unsigned int prp,
typename vector>
708bool check_values_pos_exp_slicer(vector & v)
710 if (impl == comp_dev)
712 v.template deviceToHostProp<prp>();
716 auto it = v.getDomainIterator();
722 typename vector::stype base1 = -v.getPos(key)[1]*exp(-10.0*(v.getPos(key)[0]*v.getPos(key)[0]+v.getPos(key)[1]*v.getPos(key)[1]));
723 typename vector::stype base2 = v.template getProp<prp>(key)[0];
725 ret &= fabs(base1 - base2) < 1e-5;
730 BOOST_REQUIRE_EQUAL(ret,
true);
735template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
736bool check_values_div_31(vector & vd1)
738 if (impl == comp_dev)
739 {vd1.template deviceToHostProp<A,B,C>();}
742 auto it = vd1.getDomainIterator();
748 rtype base1 = vd1.template getProp<B>(key) / (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
749 rtype base2 = vd1.template getProp<A>(key);
751 ret &= base1 == base2;
756 BOOST_REQUIRE_EQUAL(ret,
true);
761template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
762bool check_values_div_32(vector & vd1)
764 if (impl == comp_dev)
765 {vd1.template deviceToHostProp<A,B,C>();}
768 auto it = vd1.getDomainIterator();
774 rtype base1 = (vd1.template getProp<C>(key) + vd1.template getProp<B>(key)) / vd1.template getProp<B>(key);
775 rtype base2 = vd1.template getProp<A>(key);
777 ret &= base1 == base2;
782 BOOST_REQUIRE_EQUAL(ret,
true);
788template <
typename rtype,
typename vector,
unsigned int A,
unsigned int B,
unsigned int C,
unsigned int impl>
789bool check_values_div_4(vector & vd1)
791 if (impl == comp_dev)
792 {vd1.template deviceToHostProp<A,B,C>();}
795 auto it = vd1.getDomainIterator();
801 rtype base1 = (vd1.template getProp<B>(key) + vd1.template getProp<C>(key)) / (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
802 rtype base2 = vd1.template getProp<A>(key);
804 ret &= base1 == base2;
809 BOOST_REQUIRE_EQUAL(ret,
true);
814template <
unsigned int impl,
typename vector>
815bool check_values_scal_norm_dist(vector & vd)
817 if (impl == comp_dev)
818 {vd.template deviceToHostProp<A,VB,VC>();}
821 auto it = vd.getDomainIterator();
827 float base1 = vd.template getProp<VB>(key) * vd.template getProp<VC>(key) + norm(vd.template getProp<VC>(key) + vd.template getProp<VB>(key)) + distance(vd.template getProp<VC>(key),vd.template getProp<VB>(key));
828 float base2 = vd.template getProp<A>(key);
830 if (impl == comp_dev)
832 ret &= (double)norm(base1 - base2) < 0.00001;
836 ret &= base1 == base2;
842 BOOST_REQUIRE_EQUAL(ret,
true);
847template <
unsigned int impl,
typename vector>
848void fill_values(vector & v)
850 auto it = v.getDomainIterator();
856 v.getPos(p)[0] = (float)rand() / (float)RAND_MAX;
857 v.getPos(p)[1] = (float)rand() / (float)RAND_MAX;
858 v.getPos(p)[2] = (float)rand() / (float)RAND_MAX;
860 v.template getProp<A>(p) = fabs(sin(p.getKey()+1.0));
861 v.template getProp<B>(p) = fabs(sin(2.0*p.getKey()+3.0));
862 v.template getProp<C>(p) = fabs(sin(3.0*p.getKey()+18.0));
864 for (
size_t k = 0 ; k < 3 ; k++)
866 v.template getProp<VA>(p)[k] = fabs(sin(p.getKey()+1.0+k));
867 v.template getProp<VB>(p)[k] = fabs(sin(2.0*p.getKey()+1.0+3.0));
868 v.template getProp<VC>(p)[k] = fabs(sin(3.0*p.getKey()+1.0+k));
874 if (impl == comp_dev)
876 v.template hostToDeviceProp<A,B,C,VA,VB,VC>();
905 check_values<A,impl>(vd,1.0);
906 check_values<B,impl>(vd,2.0);
907 check_values<C,impl>(vd,3.0);
910 check_values<A,impl>(vd,2.0);
912 fill_values<impl>(vd);
914 vA = vB + 2.0 + vB - 2.0*vC / 5.0;
915 check_values_complex_expr<impl>(vd);
920 check_values_sum<float,vtype,A,B,C,impl>(vd,2.0);
922 check_values_sum<float,vtype,A,B,C,impl>(vd,2.0);
924 check_values_sum<float,vtype,A,B,C,impl>(vd,vd);
927 check_values_sub<float,vtype,A,B,C,impl>(vd,2.0);
929 check_values_sub<float,vtype,A,B,C,impl>(2.0,vd);
931 check_values_sub<float,vtype,A,B,C,impl>(vd,vd);
934 check_values_mul<float,vtype,A,B,C,impl>(vd,2.0);
936 check_values_mul<float,vtype,A,B,C,impl>(vd,2.0);
938 check_values_mul<float,vtype,A,B,C,impl>(vd,vd);
941 check_values_div<float,vtype,A,B,C,impl>(vd,2.0);
943 check_values_div<float,vtype,A,B,C,impl>(2.0,vd);
945 check_values_div<float,vtype,A,B,C,impl>(vd,vd);
950 check_values_sum_3<float,vtype,A,B,C,impl>(vd);
952 check_values_sum_3<float,vtype,A,B,C,impl>(vd);
953 vA = (vC + vB) + (vC + vB);
954 check_values_sum_4<float,vtype,A,B,C,impl>(vd);
957 check_values_sub_31<float,vtype,A,B,C,impl>(vd);
959 check_values_sub_32<float,vtype,A,B,C,impl>(vd);
960 vA = (vC + vB) - (vC + vB);
961 check_values_sub_4<float,vtype,A,B,C,impl>(vd);
964 check_values_mul_3<float,vtype,A,B,C,impl>(vd);
966 check_values_mul_3<float,vtype,A,B,C,impl>(vd);
967 vA = (vC + vB) * (vC + vB);
968 check_values_mul_4<float,vtype,A,B,C,impl>(vd);
971 check_values_div_31<float,vtype,A,B,C,impl>(vd);
973 check_values_div_32<float,vtype,A,B,C,impl>(vd);
974 vA = (vC + vB) / (vC + vB);
975 check_values_div_4<float,vtype,A,B,C,impl>(vd);
977 if (impl == comp_host)
980 auto & v = test.getVector();
981 BOOST_REQUIRE_EQUAL((
void *)&v,(
void *)&vd);
989 check_values_sum<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
991 check_values_sum<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
993 check_values_sum<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,vd);
996 check_values_sub<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
998 check_values_sub<VectorS<3,float>,vtype,VA,VB,VC,impl>(2.0f,vd);
1000 check_values_sub<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,vd);
1003 check_values_mul<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
1005 check_values_mul<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
1007 check_values_mul<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,vd);
1010 check_values_div<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
1012 check_values_div<VectorS<3,float>,vtype,VA,VB,VC,impl>(2.0f,vd);
1014 check_values_div<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,vd);
1016 if (impl == comp_host)
1018 auto test = vVB / 2.0;
1019 auto & v = test.getVector();
1020 BOOST_REQUIRE_EQUAL((
void *)&v,(
void *)&vd);
1025 vVA = vVB + (vVC + vVB);
1026 check_values_sum_3<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1027 vVA = (vVC + vVB) + vVB;
1028 check_values_sum_3<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1029 vVA = (vVC + vVB) + (vVC + vVB);
1030 check_values_sum_4<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1032 vVA = vVB - (vVC + vVB);
1033 check_values_sub_31<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1034 vVA = (vVC + vVB) - vVB;
1035 check_values_sub_32<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1036 vVA = (vVC + vVB) - (vVC + vVB);
1037 check_values_sub_4<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1039 vVA = vVB * (vVC + vVB);
1040 check_values_mul_3<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1041 vVA = (vVC + vVB) * vVB;
1042 check_values_mul_3<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1043 vVA = (vVC + vVB) * (vVC + vVB);
1044 check_values_mul_4<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1045 vA = vVB * (vVC + vVB);
1046 check_values_mul_3<float,vtype,A,VB,VC,impl>(vd);
1047 vA = (vVC + vVB) * vVB;
1048 check_values_mul_3<float,vtype,A,VB,VC,impl>(vd);
1049 vA = (vVC + vVB) * (vVC + vVB);
1050 check_values_mul_4<float,vtype,A,VB,VC,impl>(vd);
1052 if (impl == comp_host)
1054 auto test = (vVC + vVB) * (vVC + vVB);
1055 auto & v = test.getVector();
1056 BOOST_REQUIRE_EQUAL((
void *)&v,(
void *)&vd);
1059 vVA = vVB / (vVC + vVB);
1060 check_values_div_31<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1061 vVA = (vVC + vVB) / vVB;
1062 check_values_div_32<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1063 vVA = (vVC + vVB) / (vVC + vVB);
1064 check_values_div_4<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd);
1069 check_values_scal_norm_dist<impl>(vd);
1072 auto p0_e = getVExpr(p0);
1076 check_values_pos_sum<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,p0);
1079 check_values_pos_sub<Point<3,float>,vtype,VA,VB,VC,impl>(vd,p0);
1081 vVA = -(vPOS - p0_e);
1082 check_values_pos_sub_minus<Point<3,float>,vtype,VA,VB,VC,impl>(vd,p0);
1085 check_values_point_sub<Point<3,float>,vtype,VA,VB,VC,impl>(vd,p0);
1087 if (impl == comp_host)
1089 auto test = vPOS + p0_e;
1090 auto & v = test.getVector();
1091 BOOST_REQUIRE_EQUAL((
void *)&v,(
void *)&vd);
1105 if (impl == comp_host)
1107 auto test = exp(vVB);
1108 auto & v = test.getVector();
1109 BOOST_REQUIRE_EQUAL((
void *)&v,(
void *)&vd);
1122 vVA = vPOS + (vPOS + vPOS);
1123 vVA = (vPOS + vPOS) + vPOS;
1124 vVA = (vPOS + vPOS) + (vPOS + vPOS);
1126 vVA = vPOS - (vPOS + vPOS);
1127 vVA = (vPOS + vPOS) - vPOS;
1128 vVA = (vVC + vPOS) - (vPOS + vPOS);
1130 vVA = vPOS * (vPOS + vPOS);
1131 vVA = (vPOS + vPOS) * vPOS;
1132 vVA = (vPOS + vPOS) * (vPOS + vPOS);
1133 vA = vPOS * (vPOS + vPOS);
1134 vA = (vPOS + vPOS) * vPOS;
1135 vA = (vPOS + vPOS) * (vPOS + vPOS);
1137 vVA = vPOS / (vPOS + vPOS);
1138 vVA = (vPOS + vPOS) / vPOS;
1139 vVA = (vPOS + vPOS) / (vPOS + vPOS);
1143 vPOS = vPOS + vVA * dt;
1145 check_values_pos_integration<Point<3,float>,vtype,VA,VB,VC,impl>(vd,dt);
1149 vVA[0]=-vPOS[1]*exp(-10.0*(vPOS[0]*vPOS[0]+vPOS[1]*vPOS[1]));
1150 check_values_pos_exp_slicer<impl,VA>(vd);
1153template<
unsigned int impl>
1156 template<
typename vector_type>
static void check(
vector_type & vd)
1158 auto vA = getV<A>(vd);
1159 auto vB = getV<B>(vd);
1160 auto vC = getV<C>(vd);
1162 auto vVA = getV<VA>(vd);
1163 auto vVB = getV<VB>(vd);
1164 auto vVC = getV<VC>(vd);
1166 auto vPOS = getV<PROP_POS>(vd);
1168 check_all_expressions_imp<impl>(vd,vA,vB,vC,vVA,vVB,vVC,vPOS);
1175 template<
typename vector_type>
static void check(
vector_type & vd)
1177 auto vdk = vd.toKernel();
1179 auto vA = getV<A>(vdk);
1180 auto vB = getV<B>(vdk);
1181 auto vC = getV<C>(vdk);
1183 auto vVA = getV<VA>(vdk);
1184 auto vVB = getV<VB>(vdk);
1185 auto vVC = getV<VC>(vdk);
1187 auto vPOS = getV<PROP_POS>(vdk);
1189 check_all_expressions_imp<comp_dev>(vd,vA,vB,vC,vVA,vVB,vVC,vPOS);
1194template <
unsigned impl,
typename vector,
typename Kernel,
typename NN_type>
1195bool check_values_apply_kernel(vector & vd, Kernel & ker, NN_type & NN)
1199 if (impl == comp_dev)
1201 vd.template deviceToHostProp<A,C,VB,VC>();
1202 vd.deviceToHostPos();
1205 auto it = vd.getDomainIterator();
1207 auto it2 = vd.getDomainIterator();
1208 while (it2.isNext())
1215 float base1 = vd.template getProp<A>(p);
1216 float prp_x = vd.template getProp<VC>(p) * vd.template getProp<VB>(p) + norm(vd.template getProp<VB>(p));
1219 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1226 if (q == p.getKey()) {++Np;
continue;};
1231 float prp_y = vd.template getProp<VC>(q) * vd.template getProp<VB>(q) + norm(vd.template getProp<VB>(q));
1233 base2 += ker.value(xp,xq,prp_x,prp_y);
1238 base2 += vd.template getProp<C>(p);
1240 if (impl == comp_host)
1241 {ret &= base1 == base2;}
1243 {ret &= fabs(base1 - base2) < 0.0001;}
1248 BOOST_REQUIRE_EQUAL(ret,
true);
1253template <
unsigned int impl,
typename vector,
typename Kernel,
typename NN_type>
1254bool check_values_apply_kernel_reduce(vector & vd, Kernel & ker, NN_type & NN)
1258 if (impl == comp_dev)
1260 vd.template deviceToHostProp<A,C,VB,VC>();
1261 vd.deviceToHostPos();
1264 auto it = vd.getDomainIterator();
1270 auto it2 = vd.getDomainIterator();
1271 while (it2.isNext())
1277 float ker_accu = 0.0;
1278 float prp_x = vd.template getProp<VC>(p) * vd.template getProp<VB>(p) + norm(vd.template getProp<VB>(p));
1281 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1288 if (q == p.getKey()) {++Np;
continue;};
1293 float prp_y = vd.template getProp<VC>(q) * vd.template getProp<VB>(q) + norm(vd.template getProp<VB>(q));
1295 ker_accu += ker.value(xp,xq,prp_x,prp_y);
1305 auto it3 = vd.getDomainIterator();
1306 while (it3.isNext())
1310 base1 = vd.template getProp<A>(p);
1311 base3 = vd.template getProp<C>(p) + base2;
1313 if (impl == comp_host)
1314 {ret &= base1 == base3;}
1316 {ret &= fabs(base1 - base3) < 0.001;}
1321 BOOST_REQUIRE_EQUAL(ret,
true);
1326template <
unsigned int impl,
typename vector,
typename Kernel,
typename NN_type>
1327bool check_values_apply_kernel2(vector & vd, Kernel & ker, NN_type & NN)
1331 if (impl == comp_dev)
1333 vd.template deviceToHostProp<VA,VB,VC>();
1334 vd.deviceToHostPos();
1337 auto it = vd.getDomainIterator();
1343 auto it2 = vd.getDomainIterator();
1344 while (it2.isNext())
1353 Point<3,float> prp_x = 2.0 * vd.template getProp<VC>(p) + vd.template getProp<VB>(p);
1356 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1363 if (q == p.getKey()) {++Np;
continue;};
1368 Point<3,float> prp_y = 2.0 * vd.template getProp<VC>(q) + vd.template getProp<VB>(q);
1370 base2 += ker.
value(xp,xq,prp_x,prp_y);
1375 base2 += vd.template getProp<VC>(p);
1377 if (impl == comp_host)
1378 {ret &= base1 == base2;}
1381 for (
size_t i = 0 ; i < 3 ; i++)
1382 {ret &= fabs(base1.
get(i) - base2.
get(i)) < 0.0001;}
1388 BOOST_REQUIRE_EQUAL(ret,
true);
1393template <
unsigned int impl,
typename vector,
typename Kernel,
typename NN_type>
1394bool check_values_apply_kernel3(vector & vd, Kernel & ker, NN_type & NN)
1398 if (impl == comp_dev)
1400 vd.template deviceToHostProp<VA,VC>();
1401 vd.deviceToHostPos();
1404 auto it = vd.getDomainIterator();
1410 auto it2 = vd.getDomainIterator();
1411 while (it2.isNext())
1423 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1430 if (q == p.getKey()) {++Np;
continue;};
1437 base2 += ker.
value(xp,xq,prp_x,prp_y);
1442 base2 += vd.template getProp<VC>(p);
1444 if (impl == comp_host)
1445 {ret &= base1 == base2;}
1448 for (
size_t i = 0 ; i < 3 ; i++)
1449 {ret &= fabs(base1.
get(i) - base2.
get(i)) < 0.0001;}
1455 BOOST_REQUIRE_EQUAL(ret,
true);
1460template <
unsigned int impl,
typename vector,
typename Kernel,
typename NN_type>
1461bool check_values_apply_kernel2_reduce(vector & vd, Kernel & ker, NN_type & NN)
1465 if (impl == comp_dev)
1467 vd.template deviceToHostProp<VA,VB,VC>();
1468 vd.deviceToHostPos();
1471 auto it = vd.getDomainIterator();
1477 auto it2 = vd.getDomainIterator();
1478 while (it2.isNext())
1485 Point<3,float> prp_x = 2.0f*vd.template getProp<VC>(p) + vd.template getProp<VB>(p);
1488 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1495 if (q == p.getKey()) {++Np;
continue;};
1499 Point<3,float> prp_y = 2.0f*vd.template getProp<VC>(q) + vd.template getProp<VB>(q);
1501 ker_accu += ker.
value(xp,xq,prp_x,prp_y);
1511 auto it3 = vd.getDomainIterator();
1512 while (it3.isNext())
1516 base1 = vd.template getProp<VA>(p);
1517 base3 = vd.template getProp<VC>(p) + base2;
1519 if (impl == comp_host)
1520 {ret &= base1 == base3;}
1523 for (
size_t i = 0 ; i < 3 ; i++)
1524 {ret &= fabs(base1.
get(i) - base3.
get(i)) < 0.002;}
1536 BOOST_REQUIRE_EQUAL(ret,
true);
1541template <
unsigned int impl,
typename vector,
typename Kernel,
typename NN_type>
1542bool check_values_apply_kernel3_reduce(vector & vd, Kernel & ker, NN_type & NN,
const Point<2,float> & p)
1546 if (impl == comp_dev)
1548 vd.deviceToHostPos();
1551 auto it = vd.getDomainIterator();
1555 auto it2 = vd.getDomainIterator();
1556 while (it2.isNext())
1565 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1572 if (q == p.getKey()) {++Np;
continue;};
1577 ker_accu += ker.
value(xp,xq);
1587 if (impl == comp_host)
1589 BOOST_REQUIRE_EQUAL(p.
get(0),base2.
get(0));
1590 BOOST_REQUIRE_EQUAL(p.
get(1),base2.
get(1));
1594 BOOST_REQUIRE(fabs(p.
get(0) - base2.
get(0)) < 0.001);
1595 BOOST_REQUIRE(fabs(p.
get(1) - base2.
get(1)) < 0.001);
1601typedef vector_dist<3,float,aggregate<float,float,float,VectorS<3,float>,
VectorS<3,float>,
VectorS<3,float>,
float>>
vector_type;
1604typedef vector_dist_ker<3,float,aggregate<float,float,float,VectorS<3,float>,
VectorS<3,float>,
VectorS<3,float>,
float>> vector_type_ker;
1630 float dist = norm(p-q);
1632 return (pA + pB) * exp(dist * dist /
var);
1647 float dist = norm(p-q);
1649 return (pA + pB) * exp(dist * dist /
var);
1663 template<
typename vector_t>
1664 __host__ __device__
inline float value(
size_t p,
size_t q,
float pA,
float pB,
const vector_t & vd1)
1669 float dist = norm(pp-pq);
1671 return (pA + pB) * exp(dist * dist /
var);
1687 __device__
inline float value(
size_t p,
size_t q,
float pA,
float pB,
const vector_type_ker & vd1)
1692 float dist = norm(pp-pq);
1694 return (pA + pB) * exp(dist * dist /
var);
1715 float dist = norm(pp-pq);
1717 return (pA + pB) * exp(dist * dist /
var);
1731 template<
typename vector_t>
1737 float dist = norm(pp-pq);
1739 return (pA + pB) * exp(dist * dist /
var);
1760 float dist = norm(pp-pq);
1762 return (pA + pB) * exp(dist * dist /
var);
1777 float dist = norm(p-q);
1779 return exp(dist * dist /
var);
1783template<
unsigned int impl,
typename vector,
1789void vector_dist_op_ap_ker_impl(vector & vd, vA_type & vA,
1798 auto cl = vd.template getCellListDev<impl>(0.05);
1799 auto cl_host = vd.template getCellListDev<comp_host>(0.05);
1802 vA = applyKernel_in(vVC * vVB + norm(vVB),vd,cl,ker) + vC;
1803 check_values_apply_kernel<impl>(vd,ker,cl_host);
1805 vVA = applyKernel_in(2.0*vVC + vVB ,vd,cl,ker) + vVC;
1806 check_values_apply_kernel2<impl>(vd,ker,cl_host);
1808 vA = rsum(applyKernel_in(vVC * vVB + norm(vVB),vd,cl,ker)) + vC;
1809 check_values_apply_kernel_reduce<impl>(vd,ker,cl_host);
1811 vVA = rsum(applyKernel_in(2.0*vVC + vVB ,vd,cl,ker)) + vVC;
1812 check_values_apply_kernel2_reduce<impl>(vd,ker,cl_host);
1814 vA = applyKernel_in_gen(vVC * vVB + norm(vVB),vd,cl,ker) + vC;
1815 check_values_apply_kernel<impl>(vd,ker,cl_host);
1817 vVA = applyKernel_in_gen(2.0*vVC + vVB ,vd,cl,ker) + vVC;
1818 check_values_apply_kernel2<impl>(vd,ker,cl_host);
1820 vA = rsum(applyKernel_in_gen(vVC * vVB + norm(vVB),vd,cl,ker)) + vC;
1821 check_values_apply_kernel_reduce<impl>(vd,ker,cl_host);
1823 vVA = rsum(applyKernel_in_gen(2.0*vVC + vVB ,vd,cl,ker)) + vVC;
1824 check_values_apply_kernel2_reduce<impl>(vd,ker,cl_host);
1827 vVA = applyKernel_in_gen(vVC,vd,cl,ker) + vVC;
1828 check_values_apply_kernel3<impl>(vd,ker,cl_host);
1830 vVA = applyKernel_in (vVC,vd,cl,ker) + vVC;
1831 check_values_apply_kernel3<impl>(vd,ker,cl_host);
1834 check_values_apply_kernel3_reduce<impl>(vd,ker,cl_host,p);
1837template<
typename vector,
1843void vector_dist_op_ap_ker_impl_sort(vector & vd, vA_type & vA,
1852 auto cl_gpu = vd.getCellListGPU(0.05);
1853 auto cl = cl_gpu.toKernel();
1854 auto cl_host = vd.template getCellListDev<comp_host>(0.05);
1857 vA = applyKernel_in_sort(vVC * vVB + norm(vVB),vd,cl,ker) + vC;
1858 vd.template merge_sort<A>(cl_gpu);
1859 check_values_apply_kernel<comp_dev>(vd,ker,cl_host);
1861 vVA = applyKernel_in_sort(2.0*vVC + vVB ,vd,cl,ker) + vVC;
1862 vd.template merge_sort<VA>(cl_gpu);
1863 check_values_apply_kernel2<comp_dev>(vd,ker,cl_host);
1873 vA = applyKernel_in_gen_sort(vVC * vVB + norm(vVB),vd,cl,ker) + vC;
1874 vd.template merge_sort<A>(cl_gpu);
1875 check_values_apply_kernel<comp_dev>(vd,ker,cl_host);
1877 vVA = applyKernel_in_gen_sort(2.0*vVC + vVB ,vd,cl,ker) + vVC;
1878 vd.template merge_sort<VA>(cl_gpu);
1879 check_values_apply_kernel2<comp_dev>(vd,ker,cl_host);
1890 vVA = applyKernel_in_gen_sort(vVC,vd,cl,ker) + vVC;
1891 vd.template merge_sort<VA>(cl_gpu);
1892 check_values_apply_kernel3<comp_dev>(vd,ker,cl_host);
1894 vVA = applyKernel_in_sort(vVC,vd,cl,ker) + vVC;
1895 vd.template merge_sort<VA>(cl_gpu);
1896 check_values_apply_kernel3<comp_dev>(vd,ker,cl_host);
1902template<
unsigned int impl>
1905 template<
typename vector_type>
static void check(
vector_type & vd)
1908 fill_values<impl>(vd);
1911 vd.template ghost_get<0,1,2,3,4,5,6>();
1913 auto vA = getV<A>(vd);
1914 auto vC = getV<C>(vd);
1916 auto vVA = getV<VA>(vd);
1917 auto vVB = getV<VB>(vd);
1918 auto vVC = getV<VC>(vd);
1920 vector_dist_op_ap_ker_impl<impl>(vd,vA,vC,vVA,vVB,vVC,NONE);
1928 template<
typename vector_type>
static void check(
vector_type & vd)
1930 auto vA = getV<A,comp_dev>(vd);
1931 auto vC = getV<C,comp_dev>(vd);
1933 auto vVA = getV<VA,comp_dev>(vd);
1934 auto vVB = getV<VB,comp_dev>(vd);
1935 auto vVC = getV<VC,comp_dev>(vd);
1938 fill_values<comp_dev>(vd);
1940 vd.
map(RUN_ON_DEVICE);
1941 vd.template ghost_get<0,1,2,3,4,5,6>(RUN_ON_DEVICE);
1942 vd.template deviceToHostProp<0,1,2,3,4,5,6>();
1945 vector_dist_op_ap_ker_impl<comp_dev>(vd,vA,vC,vVA,vVB,vVC,RUN_ON_DEVICE);
1952 template<
typename vector_type>
static void check(
vector_type & vd)
1954 auto vA = getV_sort<A>(vd);
1955 auto vC = getV_sort<C>(vd);
1957 auto vVA = getV_sort<VA>(vd);
1958 auto vVB = getV_sort<VB>(vd);
1959 auto vVC = getV_sort<VC>(vd);
1962 fill_values<comp_dev>(vd);
1964 vd.
map(RUN_ON_DEVICE);
1965 vd.template ghost_get<0,1,2,3,4,5,6>(RUN_ON_DEVICE);
1966 vd.template deviceToHostProp<0,1,2,3,4,5,6>();
1969 vector_dist_op_ap_ker_impl_sort(vd,vA,vC,vVA,vVB,vVC,RUN_ON_DEVICE);
This class implement the point shape in an N-dimensional space.
__device__ __host__ T & value(size_t i)
Return the reference to the value at coordinate i.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
void deviceToHostPos()
Move the memory from the device to host memory.
auto getPos(vect_dist_key_dx vec_key) -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
void map(size_t opt=NONE)
It move all the particles that does not belong to the local processor to the respective processor.
auto distance(T exp1, P exp2) -> decltype(norm(exp1 - exp2))
General distance formula.
__device__ __host__ Point< 2, float > value(const Point< 3, float > &p, const Point< 3, float > &q)
Result of the exponential kernel.
__host__ __device__ float value(size_t p, size_t q, float pA, float pB, const vector_t &vd1)
Result of the exponential kernel.
float var
variance of the exponential kernel
__host__ Point< 3, float > value(size_t p, size_t q, const Point< 3, float > &pA, const Point< 3, float > &pB, const vector_t &vd1)
Result of the exponential kernel.
exp_kernel(float var)
Exponential kernel giving variance.
__host__ Point< 3, float > value(size_t p, size_t q, const Point< 3, float > &pA, const Point< 3, float > &pB, const vector_type &vd1)
Result of the exponential kernel.
__device__ __host__ Point< 3, float > value(const Point< 3, float > &p, const Point< 3, float > &q, const Point< 3, float > &pA, const Point< 3, float > &pB)
Result of the exponential kernel.
__device__ __host__ float value(const Point< 3, float > &p, const Point< 3, float > &q, float pA, float pB)
Result of the exponential kernel.