44 #ifdef HAVE_TPETRACORE_MPI
45 # include "Teuchos_DefaultMpiComm.hpp"
46 #endif // HAVE_TPETRACORE_MPI
47 #include "Teuchos_DefaultSerialComm.hpp"
52 #ifdef HAVE_TPETRACORE_MPI
53 std::string getMpiErrorString (
const int errCode) {
56 char errString [MPI_MAX_ERROR_STRING+1];
57 int errStringLen = MPI_MAX_ERROR_STRING;
58 (void) MPI_Error_string (errCode, errString, &errStringLen);
63 if (errString[errStringLen-1] !=
'\0') {
64 errString[errStringLen] =
'\0';
66 return std::string (errString);
68 #endif // HAVE_TPETRACORE_MPI
72 std::shared_ptr<CommRequest>
75 return std::shared_ptr<CommRequest> (
new CommRequest());
78 #ifdef HAVE_TPETRACORE_MPI
82 iallreduceRaw (
const void* sendbuf,
85 MPI_Datatype mpiDatatype,
86 const Teuchos::EReductionType op,
89 MPI_Op rawOp = ::Teuchos::Details::getMpiOpForEReductionType (op);
90 MPI_Request req = MPI_REQUEST_NULL;
91 int err = MPI_SUCCESS;
92 if (sendbuf == recvbuf) {
96 err = MPI_Iallreduce (MPI_IN_PLACE, recvbuf, count, mpiDatatype,
100 err = MPI_Iallreduce (sendbuf, recvbuf, count, mpiDatatype,
103 TEUCHOS_TEST_FOR_EXCEPTION
104 (err != MPI_SUCCESS, std::runtime_error,
105 "MPI_Iallreduce failed with the following error: "
106 << getMpiErrorString (err));
112 allreduceRaw (
const void* sendbuf,
115 MPI_Datatype mpiDatatype,
116 const Teuchos::EReductionType op,
119 MPI_Op rawOp = ::Teuchos::Details::getMpiOpForEReductionType (op);
120 int err = MPI_SUCCESS;
121 if (sendbuf == recvbuf) {
122 err = MPI_Allreduce (MPI_IN_PLACE, recvbuf,
123 count, mpiDatatype, rawOp, comm);
127 (void) MPI_Allreduce (const_cast<void*> (sendbuf), recvbuf,
128 count, mpiDatatype, rawOp, comm);
130 TEUCHOS_TEST_FOR_EXCEPTION
131 (err != MPI_SUCCESS, std::runtime_error,
132 "MPI_Allreduce failed with the following error: "
133 << getMpiErrorString (err));
136 #endif // HAVE_TPETRACORE_MPI
140 std::shared_ptr<CommRequest>
141 iallreduce (
const int localValue,
143 const ::Teuchos::EReductionType op,
144 const ::Teuchos::Comm<int>& comm)
147 Kokkos::View<int*, Kokkos::HostSpace> localView(
148 Kokkos::ViewAllocateWithoutInitializing(
"localValue"), 1);
149 localView(0) = localValue;
150 Kokkos::View<int*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
151 globalView(&globalValue, 1);
152 return ::Tpetra::Details::iallreduce<decltype(localView), decltype(globalView)>(localView, globalView, op, comm);
Declaration of Tpetra::Details::iallreduce.