17#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18#include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22#ifndef KOKKOS_PARALLEL_REDUCE_HPP
23#define KOKKOS_PARALLEL_REDUCE_HPP
25#include <Kokkos_ReductionIdentity.hpp>
26#include <Kokkos_View.hpp>
27#include <impl/Kokkos_FunctorAnalysis.hpp>
28#include <impl/Kokkos_Tools_Generic.hpp>
34template <
class Scalar,
class Space>
38 using reducer = Sum<Scalar, Space>;
39 using value_type = std::remove_cv_t<Scalar>;
44 result_view_type value;
45 bool references_scalar_v;
48 KOKKOS_INLINE_FUNCTION
49 Sum(value_type& value_) : value(&value_), references_scalar_v(true) {}
51 KOKKOS_INLINE_FUNCTION
52 Sum(
const result_view_type& value_)
53 : value(value_), references_scalar_v(false) {}
56 KOKKOS_INLINE_FUNCTION
57 void join(value_type& dest,
const value_type& src)
const { dest += src; }
59 KOKKOS_INLINE_FUNCTION
60 void init(value_type& val)
const {
61 val = reduction_identity<value_type>::sum();
64 KOKKOS_INLINE_FUNCTION
65 value_type& reference()
const {
return *value.data(); }
67 KOKKOS_INLINE_FUNCTION
68 result_view_type view()
const {
return value; }
70 KOKKOS_INLINE_FUNCTION
71 bool references_scalar()
const {
return references_scalar_v; }
74template <
typename Scalar,
typename... Properties>
75Sum(View<Scalar, Properties...>
const&)
76 ->Sum<Scalar,
typename View<Scalar, Properties...>::memory_space>;
78template <
class Scalar,
class Space>
82 using reducer = Prod<Scalar, Space>;
83 using value_type = std::remove_cv_t<Scalar>;
88 result_view_type value;
89 bool references_scalar_v;
92 KOKKOS_INLINE_FUNCTION
93 Prod(value_type& value_) : value(&value_), references_scalar_v(true) {}
95 KOKKOS_INLINE_FUNCTION
96 Prod(
const result_view_type& value_)
97 : value(value_), references_scalar_v(false) {}
100 KOKKOS_INLINE_FUNCTION
101 void join(value_type& dest,
const value_type& src)
const { dest *= src; }
103 KOKKOS_INLINE_FUNCTION
104 void init(value_type& val)
const {
105 val = reduction_identity<value_type>::prod();
108 KOKKOS_INLINE_FUNCTION
109 value_type& reference()
const {
return *value.data(); }
111 KOKKOS_INLINE_FUNCTION
112 result_view_type view()
const {
return value; }
114 KOKKOS_INLINE_FUNCTION
115 bool references_scalar()
const {
return references_scalar_v; }
118template <
typename Scalar,
typename... Properties>
119Prod(View<Scalar, Properties...>
const&)
120 ->Prod<Scalar,
typename View<Scalar, Properties...>::memory_space>;
122template <
class Scalar,
class Space>
126 using reducer = Min<Scalar, Space>;
127 using value_type = std::remove_cv_t<Scalar>;
132 result_view_type value;
133 bool references_scalar_v;
136 KOKKOS_INLINE_FUNCTION
137 Min(value_type& value_) : value(&value_), references_scalar_v(true) {}
139 KOKKOS_INLINE_FUNCTION
140 Min(
const result_view_type& value_)
141 : value(value_), references_scalar_v(false) {}
144 KOKKOS_INLINE_FUNCTION
145 void join(value_type& dest,
const value_type& src)
const {
146 if (src < dest) dest = src;
149 KOKKOS_INLINE_FUNCTION
150 void init(value_type& val)
const {
151 val = reduction_identity<value_type>::min();
154 KOKKOS_INLINE_FUNCTION
155 value_type& reference()
const {
return *value.data(); }
157 KOKKOS_INLINE_FUNCTION
158 result_view_type view()
const {
return value; }
160 KOKKOS_INLINE_FUNCTION
161 bool references_scalar()
const {
return references_scalar_v; }
164template <
typename Scalar,
typename... Properties>
165Min(View<Scalar, Properties...>
const&)
166 ->Min<Scalar,
typename View<Scalar, Properties...>::memory_space>;
168template <
class Scalar,
class Space>
172 using reducer = Max<Scalar, Space>;
173 using value_type = std::remove_cv_t<Scalar>;
178 result_view_type value;
179 bool references_scalar_v;
182 KOKKOS_INLINE_FUNCTION
183 Max(value_type& value_) : value(&value_), references_scalar_v(true) {}
185 KOKKOS_INLINE_FUNCTION
186 Max(
const result_view_type& value_)
187 : value(value_), references_scalar_v(false) {}
190 KOKKOS_INLINE_FUNCTION
191 void join(value_type& dest,
const value_type& src)
const {
192 if (src > dest) dest = src;
196 KOKKOS_INLINE_FUNCTION
197 void init(value_type& val)
const {
198 val = reduction_identity<value_type>::max();
201 KOKKOS_INLINE_FUNCTION
202 value_type& reference()
const {
return *value.data(); }
204 KOKKOS_INLINE_FUNCTION
205 result_view_type view()
const {
return value; }
207 KOKKOS_INLINE_FUNCTION
208 bool references_scalar()
const {
return references_scalar_v; }
211template <
typename Scalar,
typename... Properties>
212Max(View<Scalar, Properties...>
const&)
213 ->Max<Scalar,
typename View<Scalar, Properties...>::memory_space>;
215template <
class Scalar,
class Space>
219 using reducer = LAnd<Scalar, Space>;
220 using value_type = std::remove_cv_t<Scalar>;
225 result_view_type value;
226 bool references_scalar_v;
229 KOKKOS_INLINE_FUNCTION
230 LAnd(value_type& value_) : value(&value_), references_scalar_v(true) {}
232 KOKKOS_INLINE_FUNCTION
233 LAnd(
const result_view_type& value_)
234 : value(value_), references_scalar_v(false) {}
236 KOKKOS_INLINE_FUNCTION
237 void join(value_type& dest,
const value_type& src)
const {
241 KOKKOS_INLINE_FUNCTION
242 void init(value_type& val)
const {
243 val = reduction_identity<value_type>::land();
246 KOKKOS_INLINE_FUNCTION
247 value_type& reference()
const {
return *value.data(); }
249 KOKKOS_INLINE_FUNCTION
250 result_view_type view()
const {
return value; }
252 KOKKOS_INLINE_FUNCTION
253 bool references_scalar()
const {
return references_scalar_v; }
256template <
typename Scalar,
typename... Properties>
257LAnd(View<Scalar, Properties...>
const&)
258 ->LAnd<Scalar,
typename View<Scalar, Properties...>::memory_space>;
260template <
class Scalar,
class Space>
264 using reducer = LOr<Scalar, Space>;
265 using value_type = std::remove_cv_t<Scalar>;
270 result_view_type value;
271 bool references_scalar_v;
274 KOKKOS_INLINE_FUNCTION
275 LOr(value_type& value_) : value(&value_), references_scalar_v(true) {}
277 KOKKOS_INLINE_FUNCTION
278 LOr(
const result_view_type& value_)
279 : value(value_), references_scalar_v(false) {}
282 KOKKOS_INLINE_FUNCTION
283 void join(value_type& dest,
const value_type& src)
const {
287 KOKKOS_INLINE_FUNCTION
288 void init(value_type& val)
const {
289 val = reduction_identity<value_type>::lor();
292 KOKKOS_INLINE_FUNCTION
293 value_type& reference()
const {
return *value.data(); }
295 KOKKOS_INLINE_FUNCTION
296 result_view_type view()
const {
return value; }
298 KOKKOS_INLINE_FUNCTION
299 bool references_scalar()
const {
return references_scalar_v; }
302template <
typename Scalar,
typename... Properties>
303LOr(View<Scalar, Properties...>
const&)
304 ->LOr<Scalar,
typename View<Scalar, Properties...>::memory_space>;
306template <
class Scalar,
class Space>
310 using reducer = BAnd<Scalar, Space>;
311 using value_type = std::remove_cv_t<Scalar>;
316 result_view_type value;
317 bool references_scalar_v;
320 KOKKOS_INLINE_FUNCTION
321 BAnd(value_type& value_) : value(&value_), references_scalar_v(true) {}
323 KOKKOS_INLINE_FUNCTION
324 BAnd(
const result_view_type& value_)
325 : value(value_), references_scalar_v(false) {}
328 KOKKOS_INLINE_FUNCTION
329 void join(value_type& dest,
const value_type& src)
const {
333 KOKKOS_INLINE_FUNCTION
334 void init(value_type& val)
const {
335 val = reduction_identity<value_type>::band();
338 KOKKOS_INLINE_FUNCTION
339 value_type& reference()
const {
return *value.data(); }
341 KOKKOS_INLINE_FUNCTION
342 result_view_type view()
const {
return value; }
344 KOKKOS_INLINE_FUNCTION
345 bool references_scalar()
const {
return references_scalar_v; }
348template <
typename Scalar,
typename... Properties>
349BAnd(View<Scalar, Properties...>
const&)
350 ->BAnd<Scalar,
typename View<Scalar, Properties...>::memory_space>;
352template <
class Scalar,
class Space>
356 using reducer = BOr<Scalar, Space>;
357 using value_type = std::remove_cv_t<Scalar>;
362 result_view_type value;
363 bool references_scalar_v;
366 KOKKOS_INLINE_FUNCTION
367 BOr(value_type& value_) : value(&value_), references_scalar_v(true) {}
369 KOKKOS_INLINE_FUNCTION
370 BOr(
const result_view_type& value_)
371 : value(value_), references_scalar_v(false) {}
374 KOKKOS_INLINE_FUNCTION
375 void join(value_type& dest,
const value_type& src)
const {
379 KOKKOS_INLINE_FUNCTION
380 void init(value_type& val)
const {
381 val = reduction_identity<value_type>::bor();
384 KOKKOS_INLINE_FUNCTION
385 value_type& reference()
const {
return *value.data(); }
387 KOKKOS_INLINE_FUNCTION
388 result_view_type view()
const {
return value; }
390 KOKKOS_INLINE_FUNCTION
391 bool references_scalar()
const {
return references_scalar_v; }
394template <
typename Scalar,
typename... Properties>
395BOr(View<Scalar, Properties...>
const&)
396 ->BOr<Scalar,
typename View<Scalar, Properties...>::memory_space>;
398template <
class Scalar,
class Index>
403 KOKKOS_INLINE_FUNCTION
404 void operator=(
const ValLocScalar& rhs) {
410template <
class Scalar,
class Index,
class Space>
413 using scalar_type = std::remove_cv_t<Scalar>;
414 using index_type = std::remove_cv_t<Index>;
418 using reducer = MinLoc<Scalar, Index, Space>;
419 using value_type = ValLocScalar<scalar_type, index_type>;
424 result_view_type value;
425 bool references_scalar_v;
428 KOKKOS_INLINE_FUNCTION
429 MinLoc(value_type& value_) : value(&value_), references_scalar_v(true) {}
431 KOKKOS_INLINE_FUNCTION
432 MinLoc(
const result_view_type& value_)
433 : value(value_), references_scalar_v(false) {}
436 KOKKOS_INLINE_FUNCTION
437 void join(value_type& dest,
const value_type& src)
const {
438 if (src.val < dest.val) dest = src;
441 KOKKOS_INLINE_FUNCTION
442 void init(value_type& val)
const {
443 val.val = reduction_identity<scalar_type>::min();
444 val.loc = reduction_identity<index_type>::min();
447 KOKKOS_INLINE_FUNCTION
448 value_type& reference()
const {
return *value.data(); }
450 KOKKOS_INLINE_FUNCTION
451 result_view_type view()
const {
return value; }
453 KOKKOS_INLINE_FUNCTION
454 bool references_scalar()
const {
return references_scalar_v; }
457template <
typename Scalar,
typename Index,
typename... Properties>
458MinLoc(View<ValLocScalar<Scalar, Index>, Properties...>
const&)
459 ->MinLoc<Scalar, Index,
460 typename View<ValLocScalar<Scalar, Index>,
461 Properties...>::memory_space>;
463template <
class Scalar,
class Index,
class Space>
466 using scalar_type = std::remove_cv_t<Scalar>;
467 using index_type = std::remove_cv_t<Index>;
471 using reducer = MaxLoc<Scalar, Index, Space>;
472 using value_type = ValLocScalar<scalar_type, index_type>;
477 result_view_type value;
478 bool references_scalar_v;
481 KOKKOS_INLINE_FUNCTION
482 MaxLoc(value_type& value_) : value(&value_), references_scalar_v(true) {}
484 KOKKOS_INLINE_FUNCTION
485 MaxLoc(
const result_view_type& value_)
486 : value(value_), references_scalar_v(false) {}
489 KOKKOS_INLINE_FUNCTION
490 void join(value_type& dest,
const value_type& src)
const {
491 if (src.val > dest.val) dest = src;
494 KOKKOS_INLINE_FUNCTION
495 void init(value_type& val)
const {
496 val.val = reduction_identity<scalar_type>::max();
497 val.loc = reduction_identity<index_type>::min();
500 KOKKOS_INLINE_FUNCTION
501 value_type& reference()
const {
return *value.data(); }
503 KOKKOS_INLINE_FUNCTION
504 result_view_type view()
const {
return value; }
506 KOKKOS_INLINE_FUNCTION
507 bool references_scalar()
const {
return references_scalar_v; }
510template <
typename Scalar,
typename Index,
typename... Properties>
511MaxLoc(View<ValLocScalar<Scalar, Index>, Properties...>
const&)
512 ->MaxLoc<Scalar, Index,
513 typename View<ValLocScalar<Scalar, Index>,
514 Properties...>::memory_space>;
516template <
class Scalar>
518 Scalar min_val, max_val;
520 KOKKOS_INLINE_FUNCTION
521 void operator=(
const MinMaxScalar& rhs) {
522 min_val = rhs.min_val;
523 max_val = rhs.max_val;
527template <
class Scalar,
class Space>
530 using scalar_type = std::remove_cv_t<Scalar>;
534 using reducer = MinMax<Scalar, Space>;
535 using value_type = MinMaxScalar<scalar_type>;
540 result_view_type value;
541 bool references_scalar_v;
544 KOKKOS_INLINE_FUNCTION
545 MinMax(value_type& value_) : value(&value_), references_scalar_v(true) {}
547 KOKKOS_INLINE_FUNCTION
548 MinMax(
const result_view_type& value_)
549 : value(value_), references_scalar_v(false) {}
552 KOKKOS_INLINE_FUNCTION
553 void join(value_type& dest,
const value_type& src)
const {
554 if (src.min_val < dest.min_val) {
555 dest.min_val = src.min_val;
557 if (src.max_val > dest.max_val) {
558 dest.max_val = src.max_val;
562 KOKKOS_INLINE_FUNCTION
563 void init(value_type& val)
const {
564 val.max_val = reduction_identity<scalar_type>::max();
565 val.min_val = reduction_identity<scalar_type>::min();
568 KOKKOS_INLINE_FUNCTION
569 value_type& reference()
const {
return *value.data(); }
571 KOKKOS_INLINE_FUNCTION
572 result_view_type view()
const {
return value; }
574 KOKKOS_INLINE_FUNCTION
575 bool references_scalar()
const {
return references_scalar_v; }
578template <
typename Scalar,
typename... Properties>
579MinMax(View<MinMaxScalar<Scalar>, Properties...>
const&)
581 typename View<MinMaxScalar<Scalar>, Properties...>::memory_space>;
583template <
class Scalar,
class Index>
584struct MinMaxLocScalar {
585 Scalar min_val, max_val;
586 Index min_loc, max_loc;
588 KOKKOS_INLINE_FUNCTION
589 void operator=(
const MinMaxLocScalar& rhs) {
590 min_val = rhs.min_val;
591 min_loc = rhs.min_loc;
592 max_val = rhs.max_val;
593 max_loc = rhs.max_loc;
597template <
class Scalar,
class Index,
class Space>
600 using scalar_type = std::remove_cv_t<Scalar>;
601 using index_type = std::remove_cv_t<Index>;
605 using reducer = MinMaxLoc<Scalar, Index, Space>;
606 using value_type = MinMaxLocScalar<scalar_type, index_type>;
611 result_view_type value;
612 bool references_scalar_v;
615 KOKKOS_INLINE_FUNCTION
616 MinMaxLoc(value_type& value_) : value(&value_), references_scalar_v(true) {}
618 KOKKOS_INLINE_FUNCTION
619 MinMaxLoc(
const result_view_type& value_)
620 : value(value_), references_scalar_v(false) {}
623 KOKKOS_INLINE_FUNCTION
624 void join(value_type& dest,
const value_type& src)
const {
625 if (src.min_val < dest.min_val) {
626 dest.min_val = src.min_val;
627 dest.min_loc = src.min_loc;
629 if (src.max_val > dest.max_val) {
630 dest.max_val = src.max_val;
631 dest.max_loc = src.max_loc;
635 KOKKOS_INLINE_FUNCTION
636 void init(value_type& val)
const {
637 val.max_val = reduction_identity<scalar_type>::max();
638 val.min_val = reduction_identity<scalar_type>::min();
639 val.max_loc = reduction_identity<index_type>::min();
640 val.min_loc = reduction_identity<index_type>::min();
643 KOKKOS_INLINE_FUNCTION
644 value_type& reference()
const {
return *value.data(); }
646 KOKKOS_INLINE_FUNCTION
647 result_view_type view()
const {
return value; }
649 KOKKOS_INLINE_FUNCTION
650 bool references_scalar()
const {
return references_scalar_v; }
653template <
typename Scalar,
typename Index,
typename... Properties>
654MinMaxLoc(View<MinMaxLocScalar<Scalar, Index>, Properties...>
const&)
655 ->MinMaxLoc<Scalar, Index,
656 typename View<MinMaxLocScalar<Scalar, Index>,
657 Properties...>::memory_space>;
666template <
class Scalar,
class Index,
class Space>
669 using scalar_type = std::remove_cv_t<Scalar>;
670 using index_type = std::remove_cv_t<Index>;
674 using reducer = MaxFirstLoc<Scalar, Index, Space>;
675 using value_type = ::Kokkos::ValLocScalar<scalar_type, index_type>;
680 result_view_type value;
681 bool references_scalar_v;
684 KOKKOS_INLINE_FUNCTION
685 MaxFirstLoc(value_type& value_) : value(&value_), references_scalar_v(true) {}
687 KOKKOS_INLINE_FUNCTION
688 MaxFirstLoc(
const result_view_type& value_)
689 : value(value_), references_scalar_v(false) {}
692 KOKKOS_INLINE_FUNCTION
693 void join(value_type& dest,
const value_type& src)
const {
694 if (dest.val < src.val) {
696 }
else if (!(src.val < dest.val)) {
697 dest.loc = (src.loc < dest.loc) ? src.loc : dest.loc;
701 KOKKOS_INLINE_FUNCTION
702 void init(value_type& val)
const {
703 val.val = reduction_identity<scalar_type>::max();
704 val.loc = reduction_identity<index_type>::min();
707 KOKKOS_INLINE_FUNCTION
708 value_type& reference()
const {
return *value.data(); }
710 KOKKOS_INLINE_FUNCTION
711 result_view_type view()
const {
return value; }
713 KOKKOS_INLINE_FUNCTION
714 bool references_scalar()
const {
return references_scalar_v; }
717template <
typename Scalar,
typename Index,
typename... Properties>
718MaxFirstLoc(View<ValLocScalar<Scalar, Index>, Properties...>
const&)
719 ->MaxFirstLoc<Scalar, Index,
720 typename View<ValLocScalar<Scalar, Index>,
721 Properties...>::memory_space>;
727template <
class Scalar,
class Index,
class ComparatorType,
class Space>
728struct MaxFirstLocCustomComparator {
730 using scalar_type = std::remove_cv_t<Scalar>;
731 using index_type = std::remove_cv_t<Index>;
736 MaxFirstLocCustomComparator<Scalar, Index, ComparatorType, Space>;
737 using value_type = ::Kokkos::ValLocScalar<scalar_type, index_type>;
742 result_view_type value;
743 bool references_scalar_v;
744 ComparatorType m_comp;
747 KOKKOS_INLINE_FUNCTION
748 MaxFirstLocCustomComparator(value_type& value_, ComparatorType comp_)
749 : value(&value_), references_scalar_v(true), m_comp(comp_) {}
751 KOKKOS_INLINE_FUNCTION
752 MaxFirstLocCustomComparator(
const result_view_type& value_,
753 ComparatorType comp_)
754 : value(value_), references_scalar_v(false), m_comp(comp_) {}
757 KOKKOS_INLINE_FUNCTION
758 void join(value_type& dest,
const value_type& src)
const {
759 if (m_comp(dest.val, src.val)) {
761 }
else if (!m_comp(src.val, dest.val)) {
762 dest.loc = (src.loc < dest.loc) ? src.loc : dest.loc;
766 KOKKOS_INLINE_FUNCTION
767 void init(value_type& val)
const {
768 val.val = reduction_identity<scalar_type>::max();
769 val.loc = reduction_identity<index_type>::min();
772 KOKKOS_INLINE_FUNCTION
773 value_type& reference()
const {
return *value.data(); }
775 KOKKOS_INLINE_FUNCTION
776 result_view_type view()
const {
return value; }
778 KOKKOS_INLINE_FUNCTION
779 bool references_scalar()
const {
return references_scalar_v; }
782template <
typename Scalar,
typename Index,
typename ComparatorType,
783 typename... Properties>
784MaxFirstLocCustomComparator(
785 View<ValLocScalar<Scalar, Index>, Properties...>
const&, ComparatorType)
786 ->MaxFirstLocCustomComparator<Scalar, Index, ComparatorType,
787 typename View<ValLocScalar<Scalar, Index>,
788 Properties...>::memory_space>;
793template <
class Scalar,
class Index,
class Space>
796 using scalar_type = std::remove_cv_t<Scalar>;
797 using index_type = std::remove_cv_t<Index>;
801 using reducer = MinFirstLoc<Scalar, Index, Space>;
802 using value_type = ::Kokkos::ValLocScalar<scalar_type, index_type>;
807 result_view_type value;
808 bool references_scalar_v;
811 KOKKOS_INLINE_FUNCTION
812 MinFirstLoc(value_type& value_) : value(&value_), references_scalar_v(true) {}
814 KOKKOS_INLINE_FUNCTION
815 MinFirstLoc(
const result_view_type& value_)
816 : value(value_), references_scalar_v(false) {}
819 KOKKOS_INLINE_FUNCTION
820 void join(value_type& dest,
const value_type& src)
const {
821 if (src.val < dest.val) {
823 }
else if (!(dest.val < src.val)) {
824 dest.loc = (src.loc < dest.loc) ? src.loc : dest.loc;
828 KOKKOS_INLINE_FUNCTION
829 void init(value_type& val)
const {
830 val.val = reduction_identity<scalar_type>::min();
831 val.loc = reduction_identity<index_type>::min();
834 KOKKOS_INLINE_FUNCTION
835 value_type& reference()
const {
return *value.data(); }
837 KOKKOS_INLINE_FUNCTION
838 result_view_type view()
const {
return value; }
840 KOKKOS_INLINE_FUNCTION
841 bool references_scalar()
const {
return references_scalar_v; }
844template <
typename Scalar,
typename Index,
typename... Properties>
845MinFirstLoc(View<ValLocScalar<Scalar, Index>, Properties...>
const&)
846 ->MinFirstLoc<Scalar, Index,
847 typename View<ValLocScalar<Scalar, Index>,
848 Properties...>::memory_space>;
854template <
class Scalar,
class Index,
class ComparatorType,
class Space>
855struct MinFirstLocCustomComparator {
857 using scalar_type = std::remove_cv_t<Scalar>;
858 using index_type = std::remove_cv_t<Index>;
863 MinFirstLocCustomComparator<Scalar, Index, ComparatorType, Space>;
864 using value_type = ::Kokkos::ValLocScalar<scalar_type, index_type>;
869 result_view_type value;
870 bool references_scalar_v;
871 ComparatorType m_comp;
874 KOKKOS_INLINE_FUNCTION
875 MinFirstLocCustomComparator(value_type& value_, ComparatorType comp_)
876 : value(&value_), references_scalar_v(true), m_comp(comp_) {}
878 KOKKOS_INLINE_FUNCTION
879 MinFirstLocCustomComparator(
const result_view_type& value_,
880 ComparatorType comp_)
881 : value(value_), references_scalar_v(false), m_comp(comp_) {}
884 KOKKOS_INLINE_FUNCTION
885 void join(value_type& dest,
const value_type& src)
const {
886 if (m_comp(src.val, dest.val)) {
888 }
else if (!m_comp(dest.val, src.val)) {
889 dest.loc = (src.loc < dest.loc) ? src.loc : dest.loc;
893 KOKKOS_INLINE_FUNCTION
894 void init(value_type& val)
const {
895 val.val = reduction_identity<scalar_type>::min();
896 val.loc = reduction_identity<index_type>::min();
899 KOKKOS_INLINE_FUNCTION
900 value_type& reference()
const {
return *value.data(); }
902 KOKKOS_INLINE_FUNCTION
903 result_view_type view()
const {
return value; }
905 KOKKOS_INLINE_FUNCTION
906 bool references_scalar()
const {
return references_scalar_v; }
909template <
typename Scalar,
typename Index,
typename ComparatorType,
910 typename... Properties>
911MinFirstLocCustomComparator(
912 View<ValLocScalar<Scalar, Index>, Properties...>
const&, ComparatorType)
913 ->MinFirstLocCustomComparator<Scalar, Index, ComparatorType,
914 typename View<ValLocScalar<Scalar, Index>,
915 Properties...>::memory_space>;
920template <
class Scalar,
class Index,
class Space>
921struct MinMaxFirstLastLoc {
923 using scalar_type = std::remove_cv_t<Scalar>;
924 using index_type = std::remove_cv_t<Index>;
928 using reducer = MinMaxFirstLastLoc<Scalar, Index, Space>;
929 using value_type = ::Kokkos::MinMaxLocScalar<scalar_type, index_type>;
934 result_view_type value;
935 bool references_scalar_v;
938 KOKKOS_INLINE_FUNCTION
939 MinMaxFirstLastLoc(value_type& value_)
940 : value(&value_), references_scalar_v(true) {}
942 KOKKOS_INLINE_FUNCTION
943 MinMaxFirstLastLoc(
const result_view_type& value_)
944 : value(value_), references_scalar_v(false) {}
947 KOKKOS_INLINE_FUNCTION
948 void join(value_type& dest,
const value_type& src)
const {
949 if (src.min_val < dest.min_val) {
950 dest.min_val = src.min_val;
951 dest.min_loc = src.min_loc;
952 }
else if (!(dest.min_val < src.min_val)) {
953 dest.min_loc = (src.min_loc < dest.min_loc) ? src.min_loc : dest.min_loc;
956 if (dest.max_val < src.max_val) {
957 dest.max_val = src.max_val;
958 dest.max_loc = src.max_loc;
959 }
else if (!(src.max_val < dest.max_val)) {
960 dest.max_loc = (src.max_loc > dest.max_loc) ? src.max_loc : dest.max_loc;
964 KOKKOS_INLINE_FUNCTION
965 void init(value_type& val)
const {
966 val.max_val = ::Kokkos::reduction_identity<scalar_type>::max();
967 val.min_val = ::Kokkos::reduction_identity<scalar_type>::min();
968 val.max_loc = ::Kokkos::reduction_identity<index_type>::max();
969 val.min_loc = ::Kokkos::reduction_identity<index_type>::min();
972 KOKKOS_INLINE_FUNCTION
973 value_type& reference()
const {
return *value.data(); }
975 KOKKOS_INLINE_FUNCTION
976 result_view_type view()
const {
return value; }
978 KOKKOS_INLINE_FUNCTION
979 bool references_scalar()
const {
return references_scalar_v; }
982template <
typename Scalar,
typename Index,
typename... Properties>
983MinMaxFirstLastLoc(View<MinMaxLocScalar<Scalar, Index>, Properties...>
const&)
984 ->MinMaxFirstLastLoc<Scalar, Index,
985 typename View<MinMaxLocScalar<Scalar, Index>,
986 Properties...>::memory_space>;
992template <
class Scalar,
class Index,
class ComparatorType,
class Space>
993struct MinMaxFirstLastLocCustomComparator {
995 using scalar_type = std::remove_cv_t<Scalar>;
996 using index_type = std::remove_cv_t<Index>;
1001 MinMaxFirstLastLocCustomComparator<Scalar, Index, ComparatorType, Space>;
1002 using value_type = ::Kokkos::MinMaxLocScalar<scalar_type, index_type>;
1007 result_view_type value;
1008 bool references_scalar_v;
1009 ComparatorType m_comp;
1012 KOKKOS_INLINE_FUNCTION
1013 MinMaxFirstLastLocCustomComparator(value_type& value_, ComparatorType comp_)
1014 : value(&value_), references_scalar_v(true), m_comp(comp_) {}
1016 KOKKOS_INLINE_FUNCTION
1017 MinMaxFirstLastLocCustomComparator(
const result_view_type& value_,
1018 ComparatorType comp_)
1019 : value(value_), references_scalar_v(false), m_comp(comp_) {}
1022 KOKKOS_INLINE_FUNCTION
1023 void join(value_type& dest,
const value_type& src)
const {
1024 if (m_comp(src.min_val, dest.min_val)) {
1025 dest.min_val = src.min_val;
1026 dest.min_loc = src.min_loc;
1027 }
else if (!m_comp(dest.min_val, src.min_val)) {
1028 dest.min_loc = (src.min_loc < dest.min_loc) ? src.min_loc : dest.min_loc;
1031 if (m_comp(dest.max_val, src.max_val)) {
1032 dest.max_val = src.max_val;
1033 dest.max_loc = src.max_loc;
1034 }
else if (!m_comp(src.max_val, dest.max_val)) {
1035 dest.max_loc = (src.max_loc > dest.max_loc) ? src.max_loc : dest.max_loc;
1039 KOKKOS_INLINE_FUNCTION
1040 void init(value_type& val)
const {
1041 val.max_val = ::Kokkos::reduction_identity<scalar_type>::max();
1042 val.min_val = ::Kokkos::reduction_identity<scalar_type>::min();
1043 val.max_loc = ::Kokkos::reduction_identity<index_type>::max();
1044 val.min_loc = ::Kokkos::reduction_identity<index_type>::min();
1047 KOKKOS_INLINE_FUNCTION
1048 value_type& reference()
const {
return *value.data(); }
1050 KOKKOS_INLINE_FUNCTION
1051 result_view_type view()
const {
return value; }
1053 KOKKOS_INLINE_FUNCTION
1054 bool references_scalar()
const {
return references_scalar_v; }
1057template <
typename Scalar,
typename Index,
typename ComparatorType,
1058 typename... Properties>
1059MinMaxFirstLastLocCustomComparator(
1060 View<MinMaxLocScalar<Scalar, Index>, Properties...>
const&, ComparatorType)
1061 ->MinMaxFirstLastLocCustomComparator<
1062 Scalar, Index, ComparatorType,
1063 typename View<MinMaxLocScalar<Scalar, Index>,
1064 Properties...>::memory_space>;
1069template <
class Index>
1070struct FirstLocScalar {
1073 KOKKOS_INLINE_FUNCTION
1074 void operator=(
const FirstLocScalar& rhs) { min_loc_true = rhs.min_loc_true; }
1077template <
class Index,
class Space>
1080 using index_type = std::remove_cv_t<Index>;
1084 using reducer = FirstLoc<Index, Space>;
1085 using value_type = FirstLocScalar<index_type>;
1090 result_view_type value;
1091 bool references_scalar_v;
1094 KOKKOS_INLINE_FUNCTION
1095 FirstLoc(value_type& value_) : value(&value_), references_scalar_v(true) {}
1097 KOKKOS_INLINE_FUNCTION
1098 FirstLoc(
const result_view_type& value_)
1099 : value(value_), references_scalar_v(false) {}
1102 KOKKOS_INLINE_FUNCTION
1103 void join(value_type& dest,
const value_type& src)
const {
1104 dest.min_loc_true = (src.min_loc_true < dest.min_loc_true)
1106 : dest.min_loc_true;
1109 KOKKOS_INLINE_FUNCTION
1110 void init(value_type& val)
const {
1111 val.min_loc_true = ::Kokkos::reduction_identity<index_type>::min();
1114 KOKKOS_INLINE_FUNCTION
1115 value_type& reference()
const {
return *value.data(); }
1117 KOKKOS_INLINE_FUNCTION
1118 result_view_type view()
const {
return value; }
1120 KOKKOS_INLINE_FUNCTION
1121 bool references_scalar()
const {
return references_scalar_v; }
1124template <
typename Index,
typename... Properties>
1125FirstLoc(View<FirstLocScalar<Index>, Properties...>
const&)
1126 ->FirstLoc<Index,
typename View<FirstLocScalar<Index>,
1127 Properties...>::memory_space>;
1132template <
class Index>
1133struct LastLocScalar {
1136 KOKKOS_INLINE_FUNCTION
1137 void operator=(
const LastLocScalar& rhs) { max_loc_true = rhs.max_loc_true; }
1140template <
class Index,
class Space>
1143 using index_type = std::remove_cv_t<Index>;
1147 using reducer = LastLoc<Index, Space>;
1148 using value_type = LastLocScalar<index_type>;
1153 result_view_type value;
1154 bool references_scalar_v;
1157 KOKKOS_INLINE_FUNCTION
1158 LastLoc(value_type& value_) : value(&value_), references_scalar_v(true) {}
1160 KOKKOS_INLINE_FUNCTION
1161 LastLoc(
const result_view_type& value_)
1162 : value(value_), references_scalar_v(false) {}
1165 KOKKOS_INLINE_FUNCTION
1166 void join(value_type& dest,
const value_type& src)
const {
1167 dest.max_loc_true = (src.max_loc_true > dest.max_loc_true)
1169 : dest.max_loc_true;
1172 KOKKOS_INLINE_FUNCTION
1173 void init(value_type& val)
const {
1174 val.max_loc_true = ::Kokkos::reduction_identity<index_type>::max();
1177 KOKKOS_INLINE_FUNCTION
1178 value_type& reference()
const {
return *value.data(); }
1180 KOKKOS_INLINE_FUNCTION
1181 result_view_type view()
const {
return value; }
1183 KOKKOS_INLINE_FUNCTION
1184 bool references_scalar()
const {
return references_scalar_v; }
1187template <
typename Index,
typename... Properties>
1188LastLoc(View<LastLocScalar<Index>, Properties...>
const&)
1190 typename View<LastLocScalar<Index>, Properties...>::memory_space>;
1192template <
class Index>
1193struct StdIsPartScalar {
1194 Index max_loc_true, min_loc_false;
1196 KOKKOS_INLINE_FUNCTION
1197 void operator=(
const StdIsPartScalar& rhs) {
1198 min_loc_false = rhs.min_loc_false;
1199 max_loc_true = rhs.max_loc_true;
1206template <
class Index,
class Space>
1207struct StdIsPartitioned {
1209 using index_type = std::remove_cv_t<Index>;
1213 using reducer = StdIsPartitioned<Index, Space>;
1214 using value_type = StdIsPartScalar<index_type>;
1219 result_view_type value;
1220 bool references_scalar_v;
1223 KOKKOS_INLINE_FUNCTION
1224 StdIsPartitioned(value_type& value_)
1225 : value(&value_), references_scalar_v(true) {}
1227 KOKKOS_INLINE_FUNCTION
1228 StdIsPartitioned(
const result_view_type& value_)
1229 : value(value_), references_scalar_v(false) {}
1232 KOKKOS_INLINE_FUNCTION
1233 void join(value_type& dest,
const value_type& src)
const {
1234 dest.max_loc_true = (dest.max_loc_true < src.max_loc_true)
1236 : dest.max_loc_true;
1238 dest.min_loc_false = (dest.min_loc_false < src.min_loc_false)
1239 ? dest.min_loc_false
1240 : src.min_loc_false;
1243 KOKKOS_INLINE_FUNCTION
1244 void init(value_type& val)
const {
1245 val.max_loc_true = ::Kokkos::reduction_identity<index_type>::max();
1246 val.min_loc_false = ::Kokkos::reduction_identity<index_type>::min();
1249 KOKKOS_INLINE_FUNCTION
1250 value_type& reference()
const {
return *value.data(); }
1252 KOKKOS_INLINE_FUNCTION
1253 result_view_type view()
const {
return value; }
1255 KOKKOS_INLINE_FUNCTION
1256 bool references_scalar()
const {
return references_scalar_v; }
1259template <
typename Index,
typename... Properties>
1260StdIsPartitioned(View<StdIsPartScalar<Index>, Properties...>
const&)
1261 ->StdIsPartitioned<Index,
typename View<StdIsPartScalar<Index>,
1262 Properties...>::memory_space>;
1264template <
class Index>
1265struct StdPartPointScalar {
1266 Index min_loc_false;
1268 KOKKOS_INLINE_FUNCTION
1269 void operator=(
const StdPartPointScalar& rhs) {
1270 min_loc_false = rhs.min_loc_false;
1277template <
class Index,
class Space>
1278struct StdPartitionPoint {
1280 using index_type = std::remove_cv_t<Index>;
1284 using reducer = StdPartitionPoint<Index, Space>;
1285 using value_type = StdPartPointScalar<index_type>;
1290 result_view_type value;
1291 bool references_scalar_v;
1294 KOKKOS_INLINE_FUNCTION
1295 StdPartitionPoint(value_type& value_)
1296 : value(&value_), references_scalar_v(true) {}
1298 KOKKOS_INLINE_FUNCTION
1299 StdPartitionPoint(
const result_view_type& value_)
1300 : value(value_), references_scalar_v(false) {}
1303 KOKKOS_INLINE_FUNCTION
1304 void join(value_type& dest,
const value_type& src)
const {
1305 dest.min_loc_false = (dest.min_loc_false < src.min_loc_false)
1306 ? dest.min_loc_false
1307 : src.min_loc_false;
1310 KOKKOS_INLINE_FUNCTION
1311 void init(value_type& val)
const {
1312 val.min_loc_false = ::Kokkos::reduction_identity<index_type>::min();
1315 KOKKOS_INLINE_FUNCTION
1316 value_type& reference()
const {
return *value.data(); }
1318 KOKKOS_INLINE_FUNCTION
1319 result_view_type view()
const {
return value; }
1321 KOKKOS_INLINE_FUNCTION
1322 bool references_scalar()
const {
return references_scalar_v; }
1325template <
typename Index,
typename... Properties>
1326StdPartitionPoint(View<StdPartPointScalar<Index>, Properties...>
const&)
1327 ->StdPartitionPoint<Index,
typename View<StdPartPointScalar<Index>,
1328 Properties...>::memory_space>;
1334template <
class T,
class ReturnType,
class ValueTraits>
1335struct ParallelReduceReturnValue;
1337template <
class ReturnType,
class FunctorType>
1338struct ParallelReduceReturnValue<
1339 std::enable_if_t<Kokkos::is_view<ReturnType>::value>,
ReturnType,
1342 using reducer_type = InvalidType;
1344 using value_type_scalar =
typename return_type::value_type;
1345 using value_type_array =
typename return_type::value_type*
const;
1347 using value_type = std::conditional_t<return_type::rank == 0,
1348 value_type_scalar, value_type_array>;
1350 static return_type& return_value(
ReturnType& return_val,
const FunctorType&) {
1355template <
class ReturnType,
class FunctorType>
1356struct ParallelReduceReturnValue<
1357 std::enable_if_t<!Kokkos::is_view<ReturnType>::value &&
1358 (!std::is_array<ReturnType>::value &&
1359 !std::is_pointer<ReturnType>::value) &&
1360 !Kokkos::is_reducer<ReturnType>::value>,
1365 using reducer_type = InvalidType;
1367 using value_type =
typename return_type::value_type;
1369 static return_type return_value(
ReturnType& return_val,
const FunctorType&) {
1370 return return_type(&return_val);
1374template <
class ReturnType,
class FunctorType>
1375struct ParallelReduceReturnValue<
1376 std::enable_if_t<(std::is_array<ReturnType>::value ||
1377 std::is_pointer<ReturnType>::value)>,
1382 using reducer_type = InvalidType;
1384 using value_type =
typename return_type::value_type[];
1386 static return_type return_value(
ReturnType& return_val,
1387 const FunctorType& functor) {
1388 if (std::is_array<ReturnType>::value)
1389 return return_type(return_val);
1391 return return_type(return_val, functor.value_count);
1395template <
class ReturnType,
class FunctorType>
1396struct ParallelReduceReturnValue<
1397 std::enable_if_t<Kokkos::is_reducer<ReturnType>::value>,
ReturnType,
1401 using value_type =
typename return_type::value_type;
1403 static return_type return_value(
ReturnType& return_val,
const FunctorType&) {
1408template <
class T,
class ReturnType,
class FunctorType>
1409struct ParallelReducePolicyType;
1411template <
class PolicyType,
class FunctorType>
1412struct ParallelReducePolicyType<
1413 std::enable_if_t<Kokkos::is_execution_policy<PolicyType>::value>,
1414 PolicyType, FunctorType> {
1415 using policy_type = PolicyType;
1416 static PolicyType policy(
const PolicyType& policy_) {
return policy_; }
1419template <
class PolicyType,
class FunctorType>
1420struct ParallelReducePolicyType<
1421 std::enable_if_t<std::is_integral<PolicyType>::value>, PolicyType,
1423 using execution_space =
1424 typename Impl::FunctorPolicyExecutionSpace<FunctorType,
1425 void>::execution_space;
1429 static policy_type policy(
const PolicyType& policy_) {
1430 return policy_type(0, policy_);
1434template <
class FunctorType,
class ExecPolicy,
class ValueType,
1435 class ExecutionSpace>
1436struct ParallelReduceFunctorType {
1437 using functor_type = FunctorType;
1438 static const functor_type& functor(
const functor_type& functor) {
1443template <
class PolicyType,
class FunctorType,
class ReturnType>
1444struct ParallelReduceAdaptor {
1445 using return_value_adapter =
1446 Impl::ParallelReduceReturnValue<void, ReturnType, FunctorType>;
1448 static inline void execute_impl(
const std::string& label,
1449 const PolicyType& policy,
1450 const FunctorType& functor,
1454 PolicyType inner_policy = policy;
1455 Kokkos::Tools::Impl::begin_parallel_reduce<
1456 typename return_value_adapter::reducer_type>(inner_policy, functor,
1459 Kokkos::Impl::shared_allocation_tracking_disable();
1460 Impl::ParallelReduce<FunctorType, PolicyType,
1461 typename return_value_adapter::reducer_type>
1462 closure(functor, inner_policy,
1463 return_value_adapter::return_value(return_value, functor));
1464 Kokkos::Impl::shared_allocation_tracking_enable();
1467 Kokkos::Tools::Impl::end_parallel_reduce<
1468 typename return_value_adapter::reducer_type>(inner_policy, functor,
1472 static constexpr bool is_array_reduction =
1473 Impl::FunctorAnalysis<Impl::FunctorPatternInterface::REDUCE, PolicyType,
1474 FunctorType>::StaticValueSize == 0;
1476 template <
typename Dummy = ReturnType>
1477 static inline std::enable_if_t<!(is_array_reduction &&
1478 std::is_pointer<Dummy>::value)>
1479 execute(
const std::string& label,
const PolicyType& policy,
1480 const FunctorType& functor,
ReturnType& return_value) {
1481 execute_impl(label, policy, functor, return_value);
1502template <
typename T>
1503struct ReducerHasTestReferenceFunction {
1504 template <
typename E>
1505 static std::true_type test_func(
decltype(&E::references_scalar));
1506 template <
typename E>
1507 static std::false_type test_func(...);
1510 value = std::is_same<std::true_type, decltype(test_func<T>(
nullptr))>::value
1514template <
class ExecutionSpace,
class Arg>
1515constexpr std::enable_if_t<
1517 !ReducerHasTestReferenceFunction<Arg>::value &&
1518 !Kokkos::is_view<Arg>::value,
1521parallel_reduce_needs_fence(ExecutionSpace
const&, Arg
const&) {
1525template <
class ExecutionSpace,
class Reducer>
1526constexpr std::enable_if_t<
1531 ReducerHasTestReferenceFunction<Reducer>::value,
1534parallel_reduce_needs_fence(ExecutionSpace
const&, Reducer
const& reducer) {
1535 return reducer.references_scalar();
1538template <
class ExecutionSpace,
class ViewLike>
1539constexpr std::enable_if_t<
1541 Kokkos::is_view<ViewLike>::value,
1544parallel_reduce_needs_fence(ExecutionSpace
const&, ViewLike
const&) {
1548template <
class ExecutionSpace,
class... Args>
1549struct ParallelReduceFence {
1550 template <
class... ArgsDeduced>
1551 static void fence(
const ExecutionSpace& ex,
const std::string& name,
1552 ArgsDeduced&&... args) {
1553 if (Impl::parallel_reduce_needs_fence(ex, (ArgsDeduced &&) args...)) {
1601template <
class PolicyType,
class FunctorType,
class ReturnType>
1602inline std::enable_if_t<Kokkos::is_execution_policy<PolicyType>::value &&
1603 !(Kokkos::is_view<ReturnType>::value ||
1604 Kokkos::is_reducer<ReturnType>::value ||
1605 std::is_pointer<ReturnType>::value)>
1606parallel_reduce(
const std::string& label,
const PolicyType& policy,
1607 const FunctorType& functor,
ReturnType& return_value) {
1609 !std::is_const<ReturnType>::value,
1610 "A const reduction result type is only allowed for a View, pointer or "
1611 "reducer return type!");
1613 Impl::ParallelReduceAdaptor<PolicyType, FunctorType, ReturnType>::execute(
1614 label, policy, functor, return_value);
1615 Impl::ParallelReduceFence<typename PolicyType::execution_space, ReturnType>::
1618 "Kokkos::parallel_reduce: fence due to result being value, not view",
1622template <
class PolicyType,
class FunctorType,
class ReturnType>
1623inline std::enable_if_t<Kokkos::is_execution_policy<PolicyType>::value &&
1624 !(Kokkos::is_view<ReturnType>::value ||
1625 Kokkos::is_reducer<ReturnType>::value ||
1626 std::is_pointer<ReturnType>::value)>
1627parallel_reduce(
const PolicyType& policy,
const FunctorType& functor,
1630 !std::is_const<ReturnType>::value,
1631 "A const reduction result type is only allowed for a View, pointer or "
1632 "reducer return type!");
1634 Impl::ParallelReduceAdaptor<PolicyType, FunctorType, ReturnType>::execute(
1635 "", policy, functor, return_value);
1636 Impl::ParallelReduceFence<typename PolicyType::execution_space, ReturnType>::
1639 "Kokkos::parallel_reduce: fence due to result being value, not view",
1643template <
class FunctorType,
class ReturnType>
1644inline std::enable_if_t<!(Kokkos::is_view<ReturnType>::value ||
1645 Kokkos::is_reducer<ReturnType>::value ||
1646 std::is_pointer<ReturnType>::value)>
1647parallel_reduce(
const size_t& policy,
const FunctorType& functor,
1650 !std::is_const<ReturnType>::value,
1651 "A const reduction result type is only allowed for a View, pointer or "
1652 "reducer return type!");
1655 typename Impl::ParallelReducePolicyType<void, size_t,
1656 FunctorType>::policy_type;
1658 Impl::ParallelReduceAdaptor<policy_type, FunctorType, ReturnType>::execute(
1659 "", policy_type(0, policy), functor, return_value);
1660 Impl::ParallelReduceFence<typename policy_type::execution_space, ReturnType>::
1662 typename policy_type::execution_space(),
1663 "Kokkos::parallel_reduce: fence due to result being value, not view",
1667template <
class FunctorType,
class ReturnType>
1668inline std::enable_if_t<!(Kokkos::is_view<ReturnType>::value ||
1669 Kokkos::is_reducer<ReturnType>::value ||
1670 std::is_pointer<ReturnType>::value)>
1671parallel_reduce(
const std::string& label,
const size_t& policy,
1672 const FunctorType& functor,
ReturnType& return_value) {
1674 !std::is_const<ReturnType>::value,
1675 "A const reduction result type is only allowed for a View, pointer or "
1676 "reducer return type!");
1679 typename Impl::ParallelReducePolicyType<void, size_t,
1680 FunctorType>::policy_type;
1681 Impl::ParallelReduceAdaptor<policy_type, FunctorType, ReturnType>::execute(
1682 label, policy_type(0, policy), functor, return_value);
1683 Impl::ParallelReduceFence<typename policy_type::execution_space, ReturnType>::
1685 typename policy_type::execution_space(),
1686 "Kokkos::parallel_reduce: fence due to result being value, not view",
1692template <
class PolicyType,
class FunctorType,
class ReturnType>
1693inline std::enable_if_t<Kokkos::is_execution_policy<PolicyType>::value &&
1694 (Kokkos::is_view<ReturnType>::value ||
1695 Kokkos::is_reducer<ReturnType>::value ||
1696 std::is_pointer<ReturnType>::value)>
1697parallel_reduce(
const std::string& label,
const PolicyType& policy,
1698 const FunctorType& functor,
const ReturnType& return_value) {
1700 Impl::ParallelReduceAdaptor<PolicyType, FunctorType, ReturnType>::execute(
1701 label, policy, functor, return_value_impl);
1702 Impl::ParallelReduceFence<typename PolicyType::execution_space, ReturnType>::
1705 "Kokkos::parallel_reduce: fence due to result being value, not view",
1709template <
class PolicyType,
class FunctorType,
class ReturnType>
1710inline std::enable_if_t<Kokkos::is_execution_policy<PolicyType>::value &&
1711 (Kokkos::is_view<ReturnType>::value ||
1712 Kokkos::is_reducer<ReturnType>::value ||
1713 std::is_pointer<ReturnType>::value)>
1714parallel_reduce(
const PolicyType& policy,
const FunctorType& functor,
1717 Impl::ParallelReduceAdaptor<PolicyType, FunctorType, ReturnType>::execute(
1718 "", policy, functor, return_value_impl);
1719 Impl::ParallelReduceFence<typename PolicyType::execution_space, ReturnType>::
1722 "Kokkos::parallel_reduce: fence due to result being value, not view",
1726template <
class FunctorType,
class ReturnType>
1727inline std::enable_if_t<Kokkos::is_view<ReturnType>::value ||
1728 Kokkos::is_reducer<ReturnType>::value ||
1729 std::is_pointer<ReturnType>::value>
1730parallel_reduce(
const size_t& policy,
const FunctorType& functor,
1733 typename Impl::ParallelReducePolicyType<void, size_t,
1734 FunctorType>::policy_type;
1736 Impl::ParallelReduceAdaptor<policy_type, FunctorType, ReturnType>::execute(
1737 "", policy_type(0, policy), functor, return_value_impl);
1738 Impl::ParallelReduceFence<typename policy_type::execution_space, ReturnType>::
1740 typename policy_type::execution_space(),
1741 "Kokkos::parallel_reduce: fence due to result being value, not view",
1745template <
class FunctorType,
class ReturnType>
1746inline std::enable_if_t<Kokkos::is_view<ReturnType>::value ||
1747 Kokkos::is_reducer<ReturnType>::value ||
1748 std::is_pointer<ReturnType>::value>
1749parallel_reduce(
const std::string& label,
const size_t& policy,
1750 const FunctorType& functor,
const ReturnType& return_value) {
1752 typename Impl::ParallelReducePolicyType<void, size_t,
1753 FunctorType>::policy_type;
1755 Impl::ParallelReduceAdaptor<policy_type, FunctorType, ReturnType>::execute(
1756 label, policy_type(0, policy), functor, return_value_impl);
1757 Impl::ParallelReduceFence<typename policy_type::execution_space, ReturnType>::
1759 typename policy_type::execution_space(),
1760 "Kokkos::parallel_reduce: fence due to result being value, not view",
1766template <
class PolicyType,
class FunctorType>
1767inline void parallel_reduce(
1768 const std::string& label,
const PolicyType& policy,
1769 const FunctorType& functor,
1770 std::enable_if_t<Kokkos::is_execution_policy<PolicyType>::value>* =
1772 using FunctorAnalysis =
1773 Impl::FunctorAnalysis<Impl::FunctorPatternInterface::REDUCE, PolicyType,
1775 using value_type = std::conditional_t<(FunctorAnalysis::StaticValueSize != 0),
1776 typename FunctorAnalysis::value_type,
1777 typename FunctorAnalysis::pointer_type>;
1780 FunctorAnalysis::has_final_member_function,
1781 "Calling parallel_reduce without either return value or final function.");
1783 using result_view_type =
1785 result_view_type result_view;
1787 Impl::ParallelReduceAdaptor<PolicyType, FunctorType,
1788 result_view_type>::execute(label, policy, functor,
1792template <
class PolicyType,
class FunctorType>
1793inline void parallel_reduce(
1794 const PolicyType& policy,
const FunctorType& functor,
1795 std::enable_if_t<Kokkos::is_execution_policy<PolicyType>::value>* =
1797 using FunctorAnalysis =
1798 Impl::FunctorAnalysis<Impl::FunctorPatternInterface::REDUCE, PolicyType,
1800 using value_type = std::conditional_t<(FunctorAnalysis::StaticValueSize != 0),
1801 typename FunctorAnalysis::value_type,
1802 typename FunctorAnalysis::pointer_type>;
1805 FunctorAnalysis::has_final_member_function,
1806 "Calling parallel_reduce without either return value or final function.");
1808 using result_view_type =
1810 result_view_type result_view;
1812 Impl::ParallelReduceAdaptor<PolicyType, FunctorType,
1813 result_view_type>::execute(
"", policy, functor,
1817template <
class FunctorType>
1818inline void parallel_reduce(
const size_t& policy,
const FunctorType& functor) {
1820 typename Impl::ParallelReducePolicyType<void, size_t,
1821 FunctorType>::policy_type;
1822 using FunctorAnalysis =
1823 Impl::FunctorAnalysis<Impl::FunctorPatternInterface::REDUCE, policy_type,
1825 using value_type = std::conditional_t<(FunctorAnalysis::StaticValueSize != 0),
1826 typename FunctorAnalysis::value_type,
1827 typename FunctorAnalysis::pointer_type>;
1830 FunctorAnalysis::has_final_member_function,
1831 "Calling parallel_reduce without either return value or final function.");
1833 using result_view_type =
1835 result_view_type result_view;
1837 Impl::ParallelReduceAdaptor<policy_type, FunctorType,
1838 result_view_type>::execute(
"",
1839 policy_type(0, policy),
1840 functor, result_view);
1843template <
class FunctorType>
1844inline void parallel_reduce(
const std::string& label,
const size_t& policy,
1845 const FunctorType& functor) {
1847 typename Impl::ParallelReducePolicyType<void, size_t,
1848 FunctorType>::policy_type;
1849 using FunctorAnalysis =
1850 Impl::FunctorAnalysis<Impl::FunctorPatternInterface::REDUCE, policy_type,
1852 using value_type = std::conditional_t<(FunctorAnalysis::StaticValueSize != 0),
1853 typename FunctorAnalysis::value_type,
1854 typename FunctorAnalysis::pointer_type>;
1857 FunctorAnalysis::has_final_member_function,
1858 "Calling parallel_reduce without either return value or final function.");
1860 using result_view_type =
1862 result_view_type result_view;
1864 Impl::ParallelReduceAdaptor<policy_type, FunctorType,
1865 result_view_type>::execute(label,
1866 policy_type(0, policy),
1867 functor, result_view);
Memory management for host memory.
Execution policy for work over a range of an integral type.
View to an array of data.