10 #ifndef SACADO_FAD_KOKKOS_VIEW_SUPPORT_INCLUDES
11 #error "This file can only be included by Sacado_Fad_Kokkos_View_Support.hpp"
14 #include "Kokkos_TeuchosCommAdapters.hpp"
24 template <
typename Ordinal,
class SD,
class... SP,
class RD,
class... RP>
25 typename std::enable_if<
26 Kokkos::is_view_fad<Kokkos::View<SD, SP...>>
::value &&
27 Kokkos::is_view_fad<Kokkos::View<RD, RP...>>
::value>::type
28 reduceAll(
const Comm<Ordinal> &comm,
const EReductionType reductType,
29 const Ordinal count,
const Kokkos::View<SD, SP...> &sendBuffer,
30 const Kokkos::View<RD, RP...> &recvBuffer) {
36 typedef Kokkos::View<SD, SP...> SendViewType;
37 typedef Kokkos::View<RD, RP...> RecvViewType;
38 typedef typename SendViewType::value_type send_value_type;
39 typedef typename RecvViewType::value_type recv_value_type;
42 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
43 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
44 "The send View's rank is "
46 <<
" and the receive "
48 << RecvViewType::rank <<
".");
52 typename SendViewType::host_mirror_type hostSendBuffer =
53 Kokkos::create_mirror_view(sendBuffer);
54 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
56 localSendBuffer[
i] = hostSendBuffer(
i);
61 typename RecvViewType::host_mirror_type hostRecvBuffer =
62 Kokkos::create_mirror_view(recvBuffer);
63 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
65 localRecvBuffer[
i] = hostRecvBuffer(
i);
68 reduceAll(comm, reductType, count, localSendBuffer.getRawPtr(),
69 localRecvBuffer.getRawPtr());
73 hostRecvBuffer(
i) = localRecvBuffer[
i];
74 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
77 template <
typename Ordinal,
typename Serializer,
class SD,
class... SP,
78 class RD,
class... RP>
79 typename std::enable_if<
80 Kokkos::is_view_fad<Kokkos::View<SD, SP...>>
::value &&
81 Kokkos::is_view_fad<Kokkos::View<RD, RP...>>
::value>::type
82 reduceAll(
const Comm<Ordinal> &comm,
const Serializer &serializer,
84 const Kokkos::View<SD, SP...> &sendBuffer,
85 const Kokkos::View<RD, RP...> &recvBuffer) {
91 typedef Kokkos::View<SD, SP...> SendViewType;
92 typedef Kokkos::View<RD, RP...> RecvViewType;
93 typedef typename SendViewType::value_type send_value_type;
94 typedef typename RecvViewType::value_type recv_value_type;
97 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
98 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
99 "The send View's rank is "
100 << SendViewType::rank
101 <<
" and the receive "
103 << RecvViewType::rank <<
".");
107 typename SendViewType::host_mirror_type hostSendBuffer =
108 Kokkos::create_mirror_view(sendBuffer);
109 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
111 localSendBuffer[
i] = hostSendBuffer(
i);
116 typename RecvViewType::host_mirror_type hostRecvBuffer =
117 Kokkos::create_mirror_view(recvBuffer);
118 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
120 localRecvBuffer[
i] = hostRecvBuffer(
i);
123 reduceAll(comm, serializer, reductType, count, localSendBuffer.getRawPtr(),
124 localRecvBuffer.getRawPtr());
128 hostRecvBuffer(
i) = localRecvBuffer[
i];
129 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
132 template <
typename Ordinal,
class D,
class... P>
133 typename std::enable_if<Kokkos::is_view_fad<Kokkos::View<
D, P...>>
::value>::type
134 broadcast(
const Comm<Ordinal> &comm,
const int rootRank,
const Ordinal count,
135 const Kokkos::View<D, P...> &buffer) {
136 auto array_buffer = Sacado::as_scalar_view(buffer);
137 Ordinal array_count = count * Sacado::dimension_scalar(buffer);
138 broadcast(comm, rootRank, array_count, array_buffer);
141 template <
typename Ordinal,
typename Serializer,
class D,
class... P>
142 typename std::enable_if<Kokkos::is_view_fad<Kokkos::View<
D, P...>>
::value>::type
143 broadcast(
const Comm<Ordinal> &comm,
const Serializer &serializer,
144 const int rootRank,
const Ordinal count,
145 const Kokkos::View<D, P...> &buffer) {
146 auto array_buffer = Sacado::as_scalar_view(buffer);
147 Ordinal array_count = count * Sacado::dimension_scalar(buffer);
148 broadcast(comm, *(serializer.getValueSerializer()), rootRank, array_count,
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)