OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
vector_dist_operators_tests_util.hpp
1/*
2 * vector_dist_operators_tests_util.hpp
3 *
4 * Created on: May 31, 2019
5 * Author: i-bird
6 */
7
8#ifndef VECTOR_DIST_OPERATORS_TESTS_UTIL_HPP_
9#define VECTOR_DIST_OPERATORS_TESTS_UTIL_HPP_
10
11#include "Operators/Vector/vector_dist_operators.hpp"
12#include "Space/Shape/Point.hpp"
13
14constexpr int A = 0;
15constexpr int B = 1;
16constexpr int C = 2;
17
18constexpr int VA = 3;
19constexpr int VB = 4;
20constexpr int VC = 5;
21
22constexpr int TA = 6;
23
25
26
27template <unsigned int prp, unsigned int impl, typename vector>
28bool check_values(vector & v,float a)
29{
30 if (impl == comp_dev)
31 {v.template deviceToHostProp<prp>();}
32
33 bool ret = true;
34 auto it = v.getDomainIterator();
35
36 while (it.isNext())
37 {
38 ret &= v.template getProp<prp>(it.get()) == a;
39
40 ++it;
41 }
42
43 BOOST_REQUIRE_EQUAL(ret,true);
44
45 return ret;
46}
47
48template <unsigned int impl, typename vector>
49bool check_values_complex_expr(vector & vd)
50{
51 if (impl == comp_dev)
52 {vd.template deviceToHostProp<A,B,C>();}
53
54 bool ret = true;
55 auto it = vd.getDomainIterator();
56
57 while (it.isNext())
58 {
59 auto key = it.get();
60
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);
63
64 ret &= base1 == base2;
65
66 ++it;
67 }
68
69 BOOST_REQUIRE_EQUAL(ret,true);
70
71 return ret;
72}
73
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)
76{
77 if (impl == comp_dev)
78 {
79 vd.template deviceToHostProp<VA>();
80 vd.deviceToHostPos();
81 }
82
83 bool ret = true;
84 auto it = vd.getDomainIterator();
85
86 while (it.isNext())
87 {
88 auto key = it.get();
89
91
92 rtype base1 = rtype(xp) + p;
93 rtype base2 = vd.template getProp<VA>(key);
94
95 ret &= base1 == base2;
96
97 ++it;
98 }
99
100 BOOST_REQUIRE_EQUAL(ret,true);
101
102 return ret;
103}
104
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)
107{
108 if (impl == comp_dev)
109 {
110 vd.template deviceToHostProp<VA,VB>();
111 vd.deviceToHostPos();
112 }
113
114 bool ret = true;
115 auto it = vd.getDomainIterator();
116
117 while (it.isNext())
118 {
119 auto key = it.get();
120
121 Point<vector::dims,typename vector::stype> xp = vd.template getProp<VB>(key);
122
123 rtype base1 = rtype(xp) + rtype(vd.template getProp<VA>(key)) * dt;
124 rtype base2 = vd.getPos(key);
125
126 ret &= base1 == base2;
127
128 ++it;
129 }
130
131 BOOST_REQUIRE_EQUAL(ret,true);
132
133 return ret;
134}
135
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)
138{
139 if (impl == comp_dev)
140 {vd.template deviceToHostProp<A>();}
141
142 bool ret = true;
143 auto it = vd.getDomainIterator();
144
145 while (it.isNext())
146 {
147 auto key = it.get();
148
150
151 rtype base1 = rtype(xp) - p;
152 rtype base2 = vd.template getProp<A>(key);
153
154 ret &= base1 == base2;
155
156 ++it;
157 }
158
159 BOOST_REQUIRE_EQUAL(ret,true);
160
161 return ret;
162}
163
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)
166{
167 if (impl == comp_dev)
168 {vd.template deviceToHostProp<A>();}
169
170 bool ret = true;
171 auto it = vd.getDomainIterator();
172
173 while (it.isNext())
174 {
175 auto key = it.get();
176
178
179 rtype base1 = -(rtype(xp) - p);
180 rtype base2 = vd.template getProp<A>(key);
181
182 ret &= base1 == base2;
183
184 ++it;
185 }
186
187 BOOST_REQUIRE_EQUAL(ret,true);
188
189 return ret;
190}
191
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)
194{
195 if (impl == comp_dev)
196 {vd.template deviceToHostProp<A,B>();}
197
198 bool ret = true;
199 auto it = vd.getDomainIterator();
200
201 while (it.isNext())
202 {
203 auto key = it.get();
204
205 rtype base1 = -vd.template getProp<B>(key);
206 rtype base2 = vd.template getProp<A>(key);
207
208 ret &= base1 == base2;
209
210 ++it;
211 }
212
213 BOOST_REQUIRE_EQUAL(ret,true);
214
215 return ret;
216}
217
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)
220{
221 if (impl == comp_dev)
222 {vd.template deviceToHostProp<A,B>();}
223
224 bool ret = true;
225 auto it = vd.getDomainIterator();
226
227 while (it.isNext())
228 {
229 auto key = it.get();
230
231 rtype base1 = vd.template getProp<B>(key) + d;
232 rtype base2 = vd.template getProp<A>(key);
233
234 ret &= base1 == base2;
235
236 ++it;
237 }
238
239 BOOST_REQUIRE_EQUAL(ret,true);
240
241 return ret;
242}
243
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)
246{
247 if (impl == comp_dev)
248 {
249 vd1.template deviceToHostProp<A,B>();
250 vd2.template deviceToHostProp<C>();
251 }
252
253 bool ret = true;
254 auto it = vd1.getDomainIterator();
255
256 while (it.isNext())
257 {
258 auto key = it.get();
259
260 rtype base1 = vd1.template getProp<B>(key) + vd2.template getProp<C>(key);
261 rtype base2 = vd1.template getProp<A>(key);
262
263 ret &= base1 == base2;
264
265 ++it;
266 }
267
268 BOOST_REQUIRE_EQUAL(ret,true);
269
270 return ret;
271}
272
273template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
274bool check_values_sum_3(vector & vd1)
275{
276 if (impl == comp_dev)
277 {vd1.template deviceToHostProp<A,B>();}
278
279 bool ret = true;
280 auto it = vd1.getDomainIterator();
281
282 while (it.isNext())
283 {
284 auto key = it.get();
285
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);
288
289 ret &= base1 == base2;
290
291 ++it;
292 }
293
294 BOOST_REQUIRE_EQUAL(ret,true);
295
296 return ret;
297}
298
299template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
300bool check_values_sum_4(vector & vd1)
301{
302 if (impl == comp_dev)
303 {vd1.template deviceToHostProp<A,B,C>();}
304
305 bool ret = true;
306 auto it = vd1.getDomainIterator();
307
308 while (it.isNext())
309 {
310 auto key = it.get();
311
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);
314
315
316 ret &= base1 == base2;
317
318 ++it;
319 }
320
321 BOOST_REQUIRE_EQUAL(ret,true);
322
323 return ret;
324}
325
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)
328{
329 if (impl == comp_dev)
330 {vd.template deviceToHostProp<A,B>();}
331
332 bool ret = true;
333 auto it = vd.getDomainIterator();
334
335 while (it.isNext())
336 {
337 auto key = it.get();
338
339 rtype base1 = vd.template getProp<B>(key) - d;
340 rtype base2 = vd.template getProp<A>(key);
341
342 ret &= base1 == base2;
343
344 ++it;
345 }
346
347 BOOST_REQUIRE_EQUAL(ret,true);
348
349 return ret;
350}
351
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)
354{
355 if (impl == comp_dev)
356 {vd.template deviceToHostProp<A,B>();}
357
358 bool ret = true;
359 auto it = vd.getDomainIterator();
360
361 while (it.isNext())
362 {
363 auto key = it.get();
364
365 rtype base1 = d - vd.template getProp<B>(key);
366 rtype base2 = vd.template getProp<A>(key);
367
368 ret &= base1 == base2;
369
370 ++it;
371 }
372
373 BOOST_REQUIRE_EQUAL(ret,true);
374
375 return ret;
376}
377
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)
380{
381 if (impl == comp_dev)
382 {
383 vd1.template deviceToHostProp<A,C>();
384 vd2.template deviceToHostProp<B>();
385 }
386
387 bool ret = true;
388 auto it = vd1.getDomainIterator();
389
390 while (it.isNext())
391 {
392 auto key = it.get();
393
394 rtype base1 = vd1.template getProp<C>(key) - vd2.template getProp<B>(key);
395 rtype base2 = vd1.template getProp<A>(key);
396
397 ret &= base1 == base2;
398
399 ++it;
400 }
401
402 BOOST_REQUIRE_EQUAL(ret,true);
403
404 return ret;
405}
406
407template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
408bool check_values_sub_31(vector & vd1)
409{
410 if (impl == comp_dev)
411 {vd1.template deviceToHostProp<A,C>();}
412
413 bool ret = true;
414 auto it = vd1.getDomainIterator();
415
416 while (it.isNext())
417 {
418 auto key = it.get();
419
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);
422
423 ret &= base1 == base2;
424
425 ++it;
426 }
427
428 BOOST_REQUIRE_EQUAL(ret,true);
429
430 return ret;
431}
432
433
434template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
435bool check_values_sub_32(vector & vd1)
436{
437 if (impl == comp_dev)
438 {vd1.template deviceToHostProp<A,B,C>();}
439
440 bool ret = true;
441 auto it = vd1.getDomainIterator();
442
443 while (it.isNext())
444 {
445 auto key = it.get();
446
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);
449
450 ret &= base1 == base2;
451
452 ++it;
453 }
454
455 BOOST_REQUIRE_EQUAL(ret,true);
456
457 return ret;
458}
459
460template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
461bool check_values_sub_4(vector & vd1)
462{
463 if (impl == comp_dev)
464 {vd1.template deviceToHostProp<A,B,C>();}
465
466 bool ret = true;
467 auto it = vd1.getDomainIterator();
468
469 while (it.isNext())
470 {
471 auto key = it.get();
472
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);
475
476 if (impl == comp_dev)
477 {
478 ret &= (double)norm(base1 - base2) < 0.00001;
479 }
480 else
481 {
482 ret &= base1 == base2;
483 }
484
485 ++it;
486 }
487
488 BOOST_REQUIRE_EQUAL(ret,true);
489
490 return ret;
491}
492
493
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)
496{
497 if (impl == comp_dev)
498 {vd.template deviceToHostProp<A,B>();}
499
500 bool ret = true;
501 auto it = vd.getDomainIterator();
502
503 while (it.isNext())
504 {
505 auto key = it.get();
506
507 rtype base1 = vd.template getProp<B>(key) * d;
508 rtype base2 = vd.template getProp<A>(key);
509
510 ret &= base1 == base2;
511
512 ++it;
513 }
514
515 BOOST_REQUIRE_EQUAL(ret,true);
516
517 return ret;
518}
519
520
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)
523{
524 if (impl == comp_dev)
525 {
526 vd1.template deviceToHostProp<A,C>();
527 vd2.template deviceToHostProp<B>();
528 }
529
530 bool ret = true;
531 auto it = vd1.getDomainIterator();
532
533 while (it.isNext())
534 {
535 auto key = it.get();
536
537 rtype base1 = vd1.template getProp<C>(key) * vd2.template getProp<B>(key);
538 rtype base2 = vd1.template getProp<A>(key);
539
540 if (impl == comp_dev)
541 {
542 ret &= (double)norm(base1 - base2) < 0.00001;
543 }
544 else
545 {
546 ret &= base1 == base2;
547 }
548
549 ++it;
550 }
551
552 BOOST_REQUIRE_EQUAL(ret,true);
553
554 return ret;
555}
556
557template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
558bool check_values_mul_3(vector & vd1)
559{
560 if (impl == comp_dev)
561 {vd1.template deviceToHostProp<A,B,C>();}
562
563 bool ret = true;
564 auto it = vd1.getDomainIterator();
565
566 while (it.isNext())
567 {
568 auto key = it.get();
569
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);
572
573 if (impl == comp_dev)
574 {
575 ret &= (double)norm(base1 - base2) < 0.00001;
576 }
577 else
578 {
579 ret &= base1 == base2;
580 }
581
582 ++it;
583 }
584
585 BOOST_REQUIRE_EQUAL(ret,true);
586
587 return ret;
588}
589
590
591template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
592bool check_values_mul_4(vector & vd1)
593{
594 if (impl == comp_dev)
595 {vd1.template deviceToHostProp<A,B,C>();}
596
597 bool ret = true;
598 auto it = vd1.getDomainIterator();
599
600 while (it.isNext())
601 {
602 auto key = it.get();
603
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);
606
607 if (impl == comp_dev)
608 {
609 ret &= (double)norm(base1 - base2) < 0.00001;
610 }
611 else
612 {
613 ret &= base1 == base2;
614 }
615
616 ++it;
617 }
618
619 BOOST_REQUIRE_EQUAL(ret,true);
620
621 return ret;
622}
623
624
625
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)
628{
629 if (impl == comp_dev)
630 {vd.template deviceToHostProp<A,B>();}
631
632 bool ret = true;
633 auto it = vd.getDomainIterator();
634
635 while (it.isNext())
636 {
637 auto key = it.get();
638
639 rtype base1 = vd.template getProp<B>(key) / d;
640 rtype base2 = vd.template getProp<A>(key);
641
642 ret &= base1 == base2;
643
644 ++it;
645 }
646
647 BOOST_REQUIRE_EQUAL(ret,true);
648
649 return ret;
650}
651
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)
654{
655 if (impl == comp_dev)
656 {vd.template deviceToHostProp<A,B>();}
657
658 bool ret = true;
659 auto it = vd.getDomainIterator();
660
661 while (it.isNext())
662 {
663 auto key = it.get();
664
665 rtype base1 = d / vd.template getProp<B>(key);
666 rtype base2 = vd.template getProp<A>(key);
667
668 ret &= base1 == base2;
669
670 ++it;
671 }
672
673 BOOST_REQUIRE_EQUAL(ret,true);
674
675 return ret;
676}
677
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)
680{
681 if (impl == comp_dev)
682 {
683 vd1.template deviceToHostProp<A,C>();
684 vd2.template deviceToHostProp<B>();
685 }
686
687 bool ret = true;
688 auto it = vd1.getDomainIterator();
689
690 while (it.isNext())
691 {
692 auto key = it.get();
693
694 rtype base1 = vd1.template getProp<C>(key) / vd2.template getProp<B>(key);
695 rtype base2 = vd1.template getProp<A>(key);
696
697 ret &= base1 == base2;
698
699 ++it;
700 }
701
702 BOOST_REQUIRE_EQUAL(ret,true);
703
704 return ret;
705}
706
707template<unsigned int impl, unsigned int prp, typename vector>
708bool check_values_pos_exp_slicer(vector & v)
709{
710 if (impl == comp_dev)
711 {
712 v.template deviceToHostProp<prp>();
713 }
714
715 bool ret = true;
716 auto it = v.getDomainIterator();
717
718 while (it.isNext())
719 {
720 auto key = it.get();
721
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];
724
725 ret &= fabs(base1 - base2) < 1e-5;
726
727 ++it;
728 }
729
730 BOOST_REQUIRE_EQUAL(ret,true);
731
732 return ret;
733}
734
735template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
736bool check_values_div_31(vector & vd1)
737{
738 if (impl == comp_dev)
739 {vd1.template deviceToHostProp<A,B,C>();}
740
741 bool ret = true;
742 auto it = vd1.getDomainIterator();
743
744 while (it.isNext())
745 {
746 auto key = it.get();
747
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);
750
751 ret &= base1 == base2;
752
753 ++it;
754 }
755
756 BOOST_REQUIRE_EQUAL(ret,true);
757
758 return ret;
759}
760
761template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
762bool check_values_div_32(vector & vd1)
763{
764 if (impl == comp_dev)
765 {vd1.template deviceToHostProp<A,B,C>();}
766
767 bool ret = true;
768 auto it = vd1.getDomainIterator();
769
770 while (it.isNext())
771 {
772 auto key = it.get();
773
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);
776
777 ret &= base1 == base2;
778
779 ++it;
780 }
781
782 BOOST_REQUIRE_EQUAL(ret,true);
783
784 return ret;
785}
786
787
788template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C, unsigned int impl>
789bool check_values_div_4(vector & vd1)
790{
791 if (impl == comp_dev)
792 {vd1.template deviceToHostProp<A,B,C>();}
793
794 bool ret = true;
795 auto it = vd1.getDomainIterator();
796
797 while (it.isNext())
798 {
799 auto key = it.get();
800
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);
803
804 ret &= base1 == base2;
805
806 ++it;
807 }
808
809 BOOST_REQUIRE_EQUAL(ret,true);
810
811 return ret;
812}
813
814template <unsigned int impl, typename vector>
815bool check_values_scal_norm_dist(vector & vd)
816{
817 if (impl == comp_dev)
818 {vd.template deviceToHostProp<A,VB,VC>();}
819
820 bool ret = true;
821 auto it = vd.getDomainIterator();
822
823 while (it.isNext())
824 {
825 auto key = it.get();
826
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);
829
830 if (impl == comp_dev)
831 {
832 ret &= (double)norm(base1 - base2) < 0.00001;
833 }
834 else
835 {
836 ret &= base1 == base2;
837 }
838
839 ++it;
840 }
841
842 BOOST_REQUIRE_EQUAL(ret,true);
843
844 return ret;
845}
846
847template <unsigned int impl,typename vector>
848void fill_values(vector & v)
849{
850 auto it = v.getDomainIterator();
851
852 while (it.isNext())
853 {
854 auto p = it.get();
855
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;
859
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));
863
864 for (size_t k = 0 ; k < 3 ; k++)
865 {
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));
869 }
870
871 ++it;
872 }
873
874 if (impl == comp_dev)
875 {
876 v.template hostToDeviceProp<A,B,C,VA,VB,VC>();
877 v.hostToDevicePos();
878 }
879}
880
881template<unsigned int impl,typename vector_type,
882 typename vA_type,
883 typename vB_type,
884 typename vC_type,
885 typename vVA_type,
886 typename vVB_type,
887 typename vVC_type,
888 typename vPOS_type>
889void check_all_expressions_imp(vector_type & vd,
890 vA_type vA,
891 vB_type vB,
892 vC_type vC,
893 vVA_type vVA,
894 vVB_type vVB,
895 vVC_type vVC,
896 vPOS_type vPOS)
897{
898 // vector type
899 typedef vector_type vtype;
900
901 vA = 1.0;
902 vB = 2.0f;
903 vC = 3.0;
904
905 check_values<A,impl>(vd,1.0);
906 check_values<B,impl>(vd,2.0);
907 check_values<C,impl>(vd,3.0);
908
909 vA = vB;
910 check_values<A,impl>(vd,2.0);
911
912 fill_values<impl>(vd);
913
914 vA = vB + 2.0 + vB - 2.0*vC / 5.0;
915 check_values_complex_expr<impl>(vd);
916
917 // Various combination of 2 operator
918
919 vA = vB + 2.0;
920 check_values_sum<float,vtype,A,B,C,impl>(vd,2.0);
921 vA = 2.0 + vB;
922 check_values_sum<float,vtype,A,B,C,impl>(vd,2.0);
923 vA = vC + vB;
924 check_values_sum<float,vtype,A,B,C,impl>(vd,vd);
925
926 vA = vB - 2.0;
927 check_values_sub<float,vtype,A,B,C,impl>(vd,2.0);
928 vA = 2.0 - vB;
929 check_values_sub<float,vtype,A,B,C,impl>(2.0,vd);
930 vA = vC - vB;
931 check_values_sub<float,vtype,A,B,C,impl>(vd,vd);
932
933 vA = vB * 2.0;
934 check_values_mul<float,vtype,A,B,C,impl>(vd,2.0);
935 vA = 2.0 * vB;
936 check_values_mul<float,vtype,A,B,C,impl>(vd,2.0);
937 vA = vC * vB;
938 check_values_mul<float,vtype,A,B,C,impl>(vd,vd);
939
940 vA = vB / 2.0;
941 check_values_div<float,vtype,A,B,C,impl>(vd,2.0);
942 vA = 2.0 / vB;
943 check_values_div<float,vtype,A,B,C,impl>(2.0,vd);
944 vA = vC / vB;
945 check_values_div<float,vtype,A,B,C,impl>(vd,vd);
946
947 // Variuos combination 3 operator
948
949 vA = vB + (vC + vB);
950 check_values_sum_3<float,vtype,A,B,C,impl>(vd);
951 vA = (vC + vB) + vB;
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);
955
956 vA = vB - (vC + vB);
957 check_values_sub_31<float,vtype,A,B,C,impl>(vd);
958 vA = (vC + vB) - vB;
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);
962
963 vA = vB * (vC + vB);
964 check_values_mul_3<float,vtype,A,B,C,impl>(vd);
965 vA = (vC + vB) * vB;
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);
969
970 vA = vB / (vC + vB);
971 check_values_div_31<float,vtype,A,B,C,impl>(vd);
972 vA = (vC + vB) / vB;
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);
976
977 if (impl == comp_host)
978 {
979 auto test = vC + vB;
980 auto & v = test.getVector();
981 BOOST_REQUIRE_EQUAL((void *)&v,(void *)&vd);
982 }
983
984 // We try with vectors
985
986 // Various combination of 2 operator
987
988 vVA = vVB + 2.0;
989 check_values_sum<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
990 vVA = 2.0 + vVB;
991 check_values_sum<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
992 vVA = vVC + vVB;
993 check_values_sum<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,vd);
994
995 vVA = vVB - 2.0;
996 check_values_sub<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
997 vVA = 2.0 - vVB;
998 check_values_sub<VectorS<3,float>,vtype,VA,VB,VC,impl>(2.0f,vd);
999 vVA = vVC - vVB;
1000 check_values_sub<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,vd);
1001
1002 vVA = vVB * 2.0;
1003 check_values_mul<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
1004 vVA = 2.0 * vVB;
1005 check_values_mul<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
1006 vVA = vVC * vVB;
1007 check_values_mul<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,vd);
1008
1009 vVA = vVB / 2.0;
1010 check_values_div<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,2.0f);
1011 vVA = 2.0 / vVB;
1012 check_values_div<VectorS<3,float>,vtype,VA,VB,VC,impl>(2.0f,vd);
1013 vVA = vVC / vVB;
1014 check_values_div<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,vd);
1015
1016 if (impl == comp_host)
1017 {
1018 auto test = vVB / 2.0;
1019 auto & v = test.getVector();
1020 BOOST_REQUIRE_EQUAL((void *)&v,(void *)&vd);
1021 }
1022
1023 // Variuos combination 3 operator
1024
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);
1031
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);
1038
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);
1051
1052 if (impl == comp_host)
1053 {
1054 auto test = (vVC + vVB) * (vVC + vVB);
1055 auto & v = test.getVector();
1056 BOOST_REQUIRE_EQUAL((void *)&v,(void *)&vd);
1057 }
1058
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);
1065
1066 // normalization function
1067
1068 vA = vVB * vVC + norm(vVC + vVB) + openfpm::distance(vVC,vVB);
1069 check_values_scal_norm_dist<impl>(vd);
1070
1071 Point<3,float> p0({2.0,2.0,2.0});
1072 auto p0_e = getVExpr(p0);
1073
1074 vVA = vPOS + p0_e;
1075
1076 check_values_pos_sum<VectorS<3,float>,vtype,VA,VB,VC,impl>(vd,p0);
1077
1078 vVA = vPOS - p0_e;
1079 check_values_pos_sub<Point<3,float>,vtype,VA,VB,VC,impl>(vd,p0);
1080
1081 vVA = -(vPOS - p0_e);
1082 check_values_pos_sub_minus<Point<3,float>,vtype,VA,VB,VC,impl>(vd,p0);
1083
1084 vVA = -vVB;
1085 check_values_point_sub<Point<3,float>,vtype,VA,VB,VC,impl>(vd,p0);
1086
1087 if (impl == comp_host)
1088 {
1089 auto test = vPOS + p0_e;
1090 auto & v = test.getVector();
1091 BOOST_REQUIRE_EQUAL((void *)&v,(void *)&vd);
1092 }
1093
1094 // Just check it compile testing it will test the same code
1095 // as the previuous one
1096 vVC = exp(vVB);
1097 vA = norm(vPOS);
1098 vVA = vPOS + 2.0;
1099 vVA = 2.0 + vPOS;
1100 vVA = vPOS + vPOS;
1101 vVA = vPOS - 2.0f;
1102 vVA = 2.0 - vPOS;
1103 vVA = vPOS - vPOS;
1104
1105 if (impl == comp_host)
1106 {
1107 auto test = exp(vVB);
1108 auto & v = test.getVector();
1109 BOOST_REQUIRE_EQUAL((void *)&v,(void *)&vd);
1110 }
1111
1112 vVA = vPOS * 2.0;
1113 vVA = 2.0 * vPOS;
1114 vVA = vPOS * vPOS;
1115
1116 vVA = vPOS / 2.0f;
1117 vVA = 2.0f / vPOS;
1118 vVA = vPOS / vPOS;
1119
1120 // Variuos combination 3 operator
1121
1122 vVA = vPOS + (vPOS + vPOS);
1123 vVA = (vPOS + vPOS) + vPOS;
1124 vVA = (vPOS + vPOS) + (vPOS + vPOS);
1125
1126 vVA = vPOS - (vPOS + vPOS);
1127 vVA = (vPOS + vPOS) - vPOS;
1128 vVA = (vVC + vPOS) - (vPOS + vPOS);
1129
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);
1136
1137 vVA = vPOS / (vPOS + vPOS);
1138 vVA = (vPOS + vPOS) / vPOS;
1139 vVA = (vPOS + vPOS) / (vPOS + vPOS);
1140
1141 vVB = vPOS;
1142 double dt = 0.1;
1143 vPOS = vPOS + vVA * dt;
1144
1145 check_values_pos_integration<Point<3,float>,vtype,VA,VB,VC,impl>(vd,dt);
1146
1147 // Position with slicer (not tested on GPU)
1148
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);
1151}
1152
1153template<unsigned int impl>
1155{
1156 template<typename vector_type> static void check(vector_type & vd)
1157 {
1158 auto vA = getV<A>(vd);
1159 auto vB = getV<B>(vd);
1160 auto vC = getV<C>(vd);
1161
1162 auto vVA = getV<VA>(vd);
1163 auto vVB = getV<VB>(vd);
1164 auto vVC = getV<VC>(vd);
1165
1166 auto vPOS = getV<PROP_POS>(vd);
1167
1168 check_all_expressions_imp<impl>(vd,vA,vB,vC,vVA,vVB,vVC,vPOS);
1169 }
1170};
1171
1172template<>
1174{
1175 template<typename vector_type> static void check(vector_type & vd)
1176 {
1177 auto vdk = vd.toKernel();
1178
1179 auto vA = getV<A>(vdk);
1180 auto vB = getV<B>(vdk);
1181 auto vC = getV<C>(vdk);
1182
1183 auto vVA = getV<VA>(vdk);
1184 auto vVB = getV<VB>(vdk);
1185 auto vVC = getV<VC>(vdk);
1186
1187 auto vPOS = getV<PROP_POS>(vdk);
1188
1189 check_all_expressions_imp<comp_dev>(vd,vA,vB,vC,vVA,vVB,vVC,vPOS);
1190 }
1191};
1192
1193
1194template <unsigned impl, typename vector,typename Kernel, typename NN_type>
1195bool check_values_apply_kernel(vector & vd, Kernel & ker, NN_type & NN)
1196{
1197 bool ret = true;
1198
1199 if (impl == comp_dev)
1200 {
1201 vd.template deviceToHostProp<A,C,VB,VC>();
1202 vd.deviceToHostPos();
1203 }
1204
1205 auto it = vd.getDomainIterator();
1206
1207 auto it2 = vd.getDomainIterator();
1208 while (it2.isNext())
1209 {
1210 float base2 = 0.0;
1211 auto p = it2.get();
1212
1213 Point<3,float> xp = vd.getPos(p);
1214
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));
1217
1218 // For each neighborhood particle
1219 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1220
1221 while (Np.isNext())
1222 {
1223 // Neighborhood particle q
1224 auto q = Np.get();
1225
1226 if (q == p.getKey()) {++Np; continue;};
1227
1228 // position q
1229 Point<3,float> xq = vd.getPos(q);
1230
1231 float prp_y = vd.template getProp<VC>(q) * vd.template getProp<VB>(q) + norm(vd.template getProp<VB>(q));
1232
1233 base2 += ker.value(xp,xq,prp_x,prp_y);
1234
1235 ++Np;
1236 }
1237
1238 base2 += vd.template getProp<C>(p);
1239
1240 if (impl == comp_host)
1241 {ret &= base1 == base2;}
1242 else
1243 {ret &= fabs(base1 - base2) < 0.0001;}
1244
1245 ++it2;
1246 }
1247
1248 BOOST_REQUIRE_EQUAL(ret,true);
1249
1250 return ret;
1251}
1252
1253template <unsigned int impl, typename vector,typename Kernel, typename NN_type>
1254bool check_values_apply_kernel_reduce(vector & vd, Kernel & ker, NN_type & NN)
1255{
1256 bool ret = true;
1257
1258 if (impl == comp_dev)
1259 {
1260 vd.template deviceToHostProp<A,C,VB,VC>();
1261 vd.deviceToHostPos();
1262 }
1263
1264 auto it = vd.getDomainIterator();
1265
1266 float base1 = 0.0;
1267 float base2 = 0.0;
1268 float base3 = 0.0;
1269
1270 auto it2 = vd.getDomainIterator();
1271 while (it2.isNext())
1272 {
1273 auto p = it2.get();
1274
1275 Point<3,float> xp = vd.getPos(p);
1276
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));
1279
1280 // For each neighborhood particle
1281 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1282
1283 while (Np.isNext())
1284 {
1285 // Neighborhood particle q
1286 auto q = Np.get();
1287
1288 if (q == p.getKey()) {++Np; continue;};
1289
1290 // position q
1291 Point<3,float> xq = vd.getPos(q);
1292
1293 float prp_y = vd.template getProp<VC>(q) * vd.template getProp<VB>(q) + norm(vd.template getProp<VB>(q));
1294
1295 ker_accu += ker.value(xp,xq,prp_x,prp_y);
1296
1297 ++Np;
1298 }
1299
1300 base2 += ker_accu;
1301
1302 ++it2;
1303 }
1304
1305 auto it3 = vd.getDomainIterator();
1306 while (it3.isNext())
1307 {
1308 auto p = it3.get();
1309
1310 base1 = vd.template getProp<A>(p);
1311 base3 = vd.template getProp<C>(p) + base2;
1312
1313 if (impl == comp_host)
1314 {ret &= base1 == base3;}
1315 else
1316 {ret &= fabs(base1 - base3) < 0.001;}
1317
1318 ++it3;
1319 }
1320
1321 BOOST_REQUIRE_EQUAL(ret,true);
1322
1323 return ret;
1324}
1325
1326template <unsigned int impl, typename vector,typename Kernel, typename NN_type>
1327bool check_values_apply_kernel2(vector & vd, Kernel & ker, NN_type & NN)
1328{
1329 bool ret = true;
1330
1331 if (impl == comp_dev)
1332 {
1333 vd.template deviceToHostProp<VA,VB,VC>();
1334 vd.deviceToHostPos();
1335 }
1336
1337 auto it = vd.getDomainIterator();
1338
1339 // ### WIKI 13 ###
1340 //
1341 // Check that apply kernel work
1342 //
1343 auto it2 = vd.getDomainIterator();
1344 while (it2.isNext())
1345 {
1346 Point<3,float> base2 = 0.0;
1347 auto p = it2.get();
1348
1349 Point<3,float> xp = vd.getPos(p);
1350
1351 Point<3,float> base1 = vd.template getProp<VA>(p);
1352
1353 Point<3,float> prp_x = 2.0 * vd.template getProp<VC>(p) + vd.template getProp<VB>(p);
1354
1355 // For each neighborhood particle
1356 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1357
1358 while (Np.isNext())
1359 {
1360 // Neighborhood particle q
1361 auto q = Np.get();
1362
1363 if (q == p.getKey()) {++Np; continue;};
1364
1365 // position q
1366 Point<3,float> xq = vd.getPos(q);
1367
1368 Point<3,float> prp_y = 2.0 * vd.template getProp<VC>(q) + vd.template getProp<VB>(q);
1369
1370 base2 += ker.value(xp,xq,prp_x,prp_y);
1371
1372 ++Np;
1373 }
1374
1375 base2 += vd.template getProp<VC>(p);
1376
1377 if (impl == comp_host)
1378 {ret &= base1 == base2;}
1379 else
1380 {
1381 for (size_t i = 0 ; i < 3 ; i++)
1382 {ret &= fabs(base1.get(i) - base2.get(i)) < 0.0001;}
1383 }
1384
1385 ++it2;
1386 }
1387
1388 BOOST_REQUIRE_EQUAL(ret,true);
1389
1390 return ret;
1391}
1392
1393template <unsigned int impl, typename vector,typename Kernel, typename NN_type>
1394bool check_values_apply_kernel3(vector & vd, Kernel & ker, NN_type & NN)
1395{
1396 bool ret = true;
1397
1398 if (impl == comp_dev)
1399 {
1400 vd.template deviceToHostProp<VA,VC>();
1401 vd.deviceToHostPos();
1402 }
1403
1404 auto it = vd.getDomainIterator();
1405
1406 // ### WIKI 13 ###
1407 //
1408 // Check that apply kernel work
1409 //
1410 auto it2 = vd.getDomainIterator();
1411 while (it2.isNext())
1412 {
1413 Point<3,float> base2 = 0.0;
1414 auto p = it2.get();
1415
1416 Point<3,float> xp = vd.getPos(p);
1417
1418 Point<3,float> base1 = vd.template getProp<VA>(p);
1419
1420 Point<3,float> prp_x = vd.template getProp<VC>(p);
1421
1422 // For each neighborhood particle
1423 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1424
1425 while (Np.isNext())
1426 {
1427 // Neighborhood particle q
1428 auto q = Np.get();
1429
1430 if (q == p.getKey()) {++Np; continue;};
1431
1432 // position q
1433 Point<3,float> xq = vd.getPos(q);
1434
1435 Point<3,float> prp_y = vd.template getProp<VC>(q);
1436
1437 base2 += ker.value(xp,xq,prp_x,prp_y);
1438
1439 ++Np;
1440 }
1441
1442 base2 += vd.template getProp<VC>(p);
1443
1444 if (impl == comp_host)
1445 {ret &= base1 == base2;}
1446 else
1447 {
1448 for (size_t i = 0 ; i < 3 ; i++)
1449 {ret &= fabs(base1.get(i) - base2.get(i)) < 0.0001;}
1450 }
1451
1452 ++it2;
1453 }
1454
1455 BOOST_REQUIRE_EQUAL(ret,true);
1456
1457 return ret;
1458}
1459
1460template <unsigned int impl, typename vector,typename Kernel, typename NN_type>
1461bool check_values_apply_kernel2_reduce(vector & vd, Kernel & ker, NN_type & NN)
1462{
1463 bool ret = true;
1464
1465 if (impl == comp_dev)
1466 {
1467 vd.template deviceToHostProp<VA,VB,VC>();
1468 vd.deviceToHostPos();
1469 }
1470
1471 auto it = vd.getDomainIterator();
1472
1473 Point<3,float> base1 = 0.0;
1474 Point<3,float> base2 = 0.0;
1475 Point<3,float> base3 = 0.0;
1476
1477 auto it2 = vd.getDomainIterator();
1478 while (it2.isNext())
1479 {
1480 auto p = it2.get();
1481
1482 Point<3,float> xp = vd.getPos(p);
1483
1484 Point<3,float> ker_accu = 0.0;
1485 Point<3,float> prp_x = 2.0f*vd.template getProp<VC>(p) + vd.template getProp<VB>(p);
1486
1487 // For each neighborhood particle
1488 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1489
1490 while (Np.isNext())
1491 {
1492 // Neighborhood particle q
1493 auto q = Np.get();
1494
1495 if (q == p.getKey()) {++Np; continue;};
1496
1497 // position q
1498 Point<3,float> xq = vd.getPos(q);
1499 Point<3,float> prp_y = 2.0f*vd.template getProp<VC>(q) + vd.template getProp<VB>(q);
1500
1501 ker_accu += ker.value(xp,xq,prp_x,prp_y);
1502
1503 ++Np;
1504 }
1505
1506 base2 += ker_accu;
1507
1508 ++it2;
1509 }
1510
1511 auto it3 = vd.getDomainIterator();
1512 while (it3.isNext())
1513 {
1514 auto p = it3.get();
1515
1516 base1 = vd.template getProp<VA>(p);
1517 base3 = vd.template getProp<VC>(p) + base2;
1518
1519 if (impl == comp_host)
1520 {ret &= base1 == base3;}
1521 else
1522 {
1523 for (size_t i = 0 ; i < 3 ; i++)
1524 {ret &= fabs(base1.get(i) - base3.get(i)) < 0.002;}
1525
1526 if (ret == false)
1527 {
1528 int debug = 0;
1529 debug++;
1530 }
1531 }
1532
1533 ++it3;
1534 }
1535
1536 BOOST_REQUIRE_EQUAL(ret,true);
1537
1538 return ret;
1539}
1540
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)
1543{
1544 bool ret = true;
1545
1546 if (impl == comp_dev)
1547 {
1548 vd.deviceToHostPos();
1549 }
1550
1551 auto it = vd.getDomainIterator();
1552
1553 Point<2,float> base2 = 0.0;
1554
1555 auto it2 = vd.getDomainIterator();
1556 while (it2.isNext())
1557 {
1558 auto p = it2.get();
1559
1560 Point<3,float> xp = vd.getPos(p);
1561
1562 Point<2,float> ker_accu = 0.0;
1563
1564 // For each neighborhood particle
1565 auto Np = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
1566
1567 while (Np.isNext())
1568 {
1569 // Neighborhood particle q
1570 auto q = Np.get();
1571
1572 if (q == p.getKey()) {++Np; continue;};
1573
1574 // position q
1575 Point<3,float> xq = vd.getPos(q);
1576
1577 ker_accu += ker.value(xp,xq);
1578
1579 ++Np;
1580 }
1581
1582 base2 += ker_accu;
1583
1584 ++it2;
1585 }
1586
1587 if (impl == comp_host)
1588 {
1589 BOOST_REQUIRE_EQUAL(p.get(0),base2.get(0));
1590 BOOST_REQUIRE_EQUAL(p.get(1),base2.get(1));
1591 }
1592 else
1593 {
1594 BOOST_REQUIRE(fabs(p.get(0) - base2.get(0)) < 0.001);
1595 BOOST_REQUIRE(fabs(p.get(1) - base2.get(1)) < 0.001);
1596 }
1597
1598 return ret;
1599}
1600
1602
1603#ifdef CUDA_GPU
1604typedef vector_dist_ker<3,float,aggregate<float,float,float,VectorS<3,float>,VectorS<3,float>,VectorS<3,float>,float>> vector_type_ker;
1605#endif
1606
1609{
1611 float var;
1612
1615 :var(var)
1616 {}
1617
1628 __device__ __host__ inline float value(const Point<3,float> & p, const Point<3,float> & q,float pA,float pB)
1629 {
1630 float dist = norm(p-q);
1631
1632 return (pA + pB) * exp(dist * dist / var);
1633 }
1634
1645 __device__ __host__ inline Point<3,float> value(const Point<3,float> & p, const Point<3,float> & q,const Point<3,float> & pA, const Point<3,float> & pB)
1646 {
1647 float dist = norm(p-q);
1648
1649 return (pA + pB) * exp(dist * dist / var);
1650 }
1651
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)
1665 {
1666 Point<3,float> pp = vd1.getPos(p);
1667 Point<3,float> pq = vd1.getPos(q);
1668
1669 float dist = norm(pp-pq);
1670
1671 return (pA + pB) * exp(dist * dist / var);
1672 }
1673
1674#ifdef CUDA_GPU
1675
1687 __device__ inline float value(size_t p, size_t q, float pA, float pB, const vector_type_ker & vd1)
1688 {
1689 Point<3,float> pp = vd1.getPos(p);
1690 Point<3,float> pq = vd1.getPos(q);
1691
1692 float dist = norm(pp-pq);
1693
1694 return (pA + pB) * exp(dist * dist / var);
1695 }
1696
1697#endif
1698
1710 __host__ inline Point<3,float> value(size_t p, size_t q, const Point<3,float> & pA, const Point<3,float> & pB , const vector_type & vd1)
1711 {
1712 Point<3,float> pp = vd1.getPos(p);
1713 Point<3,float> pq = vd1.getPos(q);
1714
1715 float dist = norm(pp-pq);
1716
1717 return (pA + pB) * exp(dist * dist / var);
1718 }
1719
1731 template<typename vector_t>
1732 __host__ inline Point<3,float> value(size_t p, size_t q, const Point<3,float> & pA, const Point<3,float> & pB , const vector_t & vd1)
1733 {
1734 Point<3,float> pp = vd1.getPos(p);
1735 Point<3,float> pq = vd1.getPos(q);
1736
1737 float dist = norm(pp-pq);
1738
1739 return (pA + pB) * exp(dist * dist / var);
1740 }
1741
1742#ifdef CUDA_GPU
1743
1755 __device__ inline Point<3,float> value(size_t p, size_t q, const Point<3,float> & pA, const Point<3,float> & pB , const vector_type_ker & vd1)
1756 {
1757 Point<3,float> pp = vd1.getPos(p);
1758 Point<3,float> pq = vd1.getPos(q);
1759
1760 float dist = norm(pp-pq);
1761
1762 return (pA + pB) * exp(dist * dist / var);
1763 }
1764
1765#endif
1766
1775 __device__ __host__ inline Point<2,float> value(const Point<3,float> & p, const Point<3,float> & q)
1776 {
1777 float dist = norm(p-q);
1778
1779 return exp(dist * dist / var);
1780 }
1781};
1782
1783template<unsigned int impl,typename vector,
1784 typename vA_type,
1785 typename vC_type,
1786 typename vVA_type,
1787 typename vVB_type,
1788 typename vVC_type>
1789void vector_dist_op_ap_ker_impl(vector & vd, vA_type & vA,
1790 vC_type & vC,
1791 vVA_type & vVA,
1792 vVB_type & vVB,
1793 vVC_type & vVC,
1794 unsigned int opt)
1795{
1796 // we apply an exponential kernel to calculate something
1797
1798 auto cl = vd.template getCellListDev<impl>(0.05);
1799 auto cl_host = vd.template getCellListDev<comp_host>(0.05);
1800 exp_kernel ker(0.2);
1801
1802 vA = applyKernel_in(vVC * vVB + norm(vVB),vd,cl,ker) + vC;
1803 check_values_apply_kernel<impl>(vd,ker,cl_host);
1804
1805 vVA = applyKernel_in(2.0*vVC + vVB ,vd,cl,ker) + vVC;
1806 check_values_apply_kernel2<impl>(vd,ker,cl_host);
1807
1808 vA = rsum(applyKernel_in(vVC * vVB + norm(vVB),vd,cl,ker)) + vC;
1809 check_values_apply_kernel_reduce<impl>(vd,ker,cl_host);
1810
1811 vVA = rsum(applyKernel_in(2.0*vVC + vVB ,vd,cl,ker)) + vVC;
1812 check_values_apply_kernel2_reduce<impl>(vd,ker,cl_host);
1813
1814 vA = applyKernel_in_gen(vVC * vVB + norm(vVB),vd,cl,ker) + vC;
1815 check_values_apply_kernel<impl>(vd,ker,cl_host);
1816
1817 vVA = applyKernel_in_gen(2.0*vVC + vVB ,vd,cl,ker) + vVC;
1818 check_values_apply_kernel2<impl>(vd,ker,cl_host);
1819
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);
1822
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);
1825
1826 // Check it compile the code is the same
1827 vVA = applyKernel_in_gen(vVC,vd,cl,ker) + vVC;
1828 check_values_apply_kernel3<impl>(vd,ker,cl_host);
1829
1830 vVA = applyKernel_in (vVC,vd,cl,ker) + vVC;
1831 check_values_apply_kernel3<impl>(vd,ker,cl_host);
1832
1833 Point<2,float> p = rsum(applyKernel_in_sim(vd,cl,ker)).get();
1834 check_values_apply_kernel3_reduce<impl>(vd,ker,cl_host,p);
1835}
1836
1837template<typename vector,
1838 typename vA_type,
1839 typename vC_type,
1840 typename vVA_type,
1841 typename vVB_type,
1842 typename vVC_type>
1843void vector_dist_op_ap_ker_impl_sort(vector & vd, vA_type & vA,
1844 vC_type & vC,
1845 vVA_type & vVA,
1846 vVB_type & vVB,
1847 vVC_type & vVC,
1848 unsigned int opt)
1849{
1850 // we apply an exponential kernel to calculate something
1851
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);
1855 exp_kernel ker(0.2);
1856
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);
1860
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);
1864
1865/* vA = rsum(applyKernel_in_sort(vVC * vVB + norm(vVB),vd,cl,ker)) + vC;
1866 vd.template merge_sort<A>(cl_gpu);
1867 check_values_apply_kernel_reduce<comp_dev>(vd,ker,cl_host);
1868
1869 vVA = rsum(applyKernel_in_sort(2.0*vVC + vVB ,vd,cl,ker)) + vVC;
1870 vd.template merge_sort<VA>(cl_gpu);
1871 check_values_apply_kernel2_reduce<comp_dev>(vd,ker,cl_host);*/
1872
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);
1876
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);
1880
1881/* vA = rsum(applyKernel_in_gen_sort(vVC * vVB + norm(vVB),vd,cl,ker)) + vC;
1882 vd.template merge_sort<A>(cl_gpu);
1883 check_values_apply_kernel_reduce<comp_dev>(vd,ker,cl_host);
1884
1885 vVA = rsum(applyKernel_in_gen_sort(2.0*vVC + vVB ,vd,cl,ker)) + vVC;
1886 vd.template merge_sort<VA>(cl_gpu);
1887 check_values_apply_kernel2_reduce<comp_dev>(vd,ker,cl_host);*/
1888
1889 // Check it compile the code is the same
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);
1893
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);
1897
1898/* Point<2,float> p = rsum(applyKernel_in_sim_sort(vd,cl,ker)).get();
1899 check_values_apply_kernel3_reduce<comp_dev>(vd,ker,cl_host,p);*/
1900}
1901
1902template<unsigned int impl>
1904{
1905 template<typename vector_type> static void check(vector_type & vd)
1906 {
1907 // fill vd with some value
1908 fill_values<impl>(vd);
1909
1910 vd.map();
1911 vd.template ghost_get<0,1,2,3,4,5,6>();
1912
1913 auto vA = getV<A>(vd);
1914 auto vC = getV<C>(vd);
1915
1916 auto vVA = getV<VA>(vd);
1917 auto vVB = getV<VB>(vd);
1918 auto vVC = getV<VC>(vd);
1919
1920 vector_dist_op_ap_ker_impl<impl>(vd,vA,vC,vVA,vVB,vVC,NONE);
1921 }
1922};
1923
1924
1925template<>
1926struct check_all_apply_ker<comp_dev>
1927{
1928 template<typename vector_type> static void check(vector_type & vd)
1929 {
1930 auto vA = getV<A,comp_dev>(vd);
1931 auto vC = getV<C,comp_dev>(vd);
1932
1933 auto vVA = getV<VA,comp_dev>(vd);
1934 auto vVB = getV<VB,comp_dev>(vd);
1935 auto vVC = getV<VC,comp_dev>(vd);
1936
1937 // fill vd with some value
1938 fill_values<comp_dev>(vd);
1939
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>();
1943 vd.deviceToHostPos();
1944
1945 vector_dist_op_ap_ker_impl<comp_dev>(vd,vA,vC,vVA,vVB,vVC,RUN_ON_DEVICE);
1946 }
1947};
1948
1949
1951{
1952 template<typename vector_type> static void check(vector_type & vd)
1953 {
1954 auto vA = getV_sort<A>(vd);
1955 auto vC = getV_sort<C>(vd);
1956
1957 auto vVA = getV_sort<VA>(vd);
1958 auto vVB = getV_sort<VB>(vd);
1959 auto vVC = getV_sort<VC>(vd);
1960
1961 // fill vd with some value
1962 fill_values<comp_dev>(vd);
1963
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>();
1967 vd.deviceToHostPos();
1968
1969 vector_dist_op_ap_ker_impl_sort(vd,vA,vC,vVA,vVB,vVC,RUN_ON_DEVICE);
1970 }
1971};
1972
1973#endif /* VECTOR_DIST_OPERATORS_TESTS_UTIL_HPP_ */
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
__device__ __host__ T & value(size_t i)
Return the reference to the value at coordinate i.
Definition Point.hpp:419
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition Point.hpp:172
Distributed vector.
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.