12#ifdef HAVE_TPETRACORE_MPI
13# include "Teuchos_DefaultMpiComm.hpp"
15#include "Teuchos_DefaultSerialComm.hpp"
20#ifdef HAVE_TPETRACORE_MPI
21std::string getMpiErrorString (
const int errCode) {
24 char errString [MPI_MAX_ERROR_STRING+1];
25 int errStringLen = MPI_MAX_ERROR_STRING;
26 (void) MPI_Error_string (errCode, errString, &errStringLen);
31 if (errString[errStringLen-1] !=
'\0') {
32 errString[errStringLen] =
'\0';
34 return std::string (errString);
40std::shared_ptr<CommRequest>
43 return std::shared_ptr<CommRequest> (
new CommRequest());
46#ifdef HAVE_TPETRACORE_MPI
50iallreduceRaw (
const void* sendbuf,
53 MPI_Datatype mpiDatatype,
54 const Teuchos::EReductionType op,
57 MPI_Op rawOp = ::Teuchos::Details::getMpiOpForEReductionType (op);
58 MPI_Request req = MPI_REQUEST_NULL;
59 int err = MPI_SUCCESS;
60 if (sendbuf == recvbuf) {
64 err = MPI_Iallreduce (MPI_IN_PLACE, recvbuf, count, mpiDatatype,
68 err = MPI_Iallreduce (sendbuf, recvbuf, count, mpiDatatype,
71 TEUCHOS_TEST_FOR_EXCEPTION
72 (err != MPI_SUCCESS, std::runtime_error,
73 "MPI_Iallreduce failed with the following error: "
74 << getMpiErrorString (err));
80allreduceRaw (
const void* sendbuf,
83 MPI_Datatype mpiDatatype,
84 const Teuchos::EReductionType op,
87 MPI_Op rawOp = ::Teuchos::Details::getMpiOpForEReductionType (op);
88 int err = MPI_SUCCESS;
89 if (sendbuf == recvbuf) {
90 err = MPI_Allreduce (MPI_IN_PLACE, recvbuf,
91 count, mpiDatatype, rawOp, comm);
95 (void) MPI_Allreduce (
const_cast<void*
> (sendbuf), recvbuf,
96 count, mpiDatatype, rawOp, comm);
98 TEUCHOS_TEST_FOR_EXCEPTION
99 (err != MPI_SUCCESS, std::runtime_error,
100 "MPI_Allreduce failed with the following error: "
101 << getMpiErrorString (err));
108std::shared_ptr<CommRequest>
109iallreduce (
const int localValue,
111 const ::Teuchos::EReductionType op,
112 const ::Teuchos::Comm<int>& comm)
115 Kokkos::View<int*, Kokkos::HostSpace> localView(
116 Kokkos::ViewAllocateWithoutInitializing(
"localValue"), 1);
117 localView(0) = localValue;
118 Kokkos::View<int*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
119 globalView(&globalValue, 1);
120 return ::Tpetra::Details::iallreduce<decltype(localView), decltype(globalView)>(localView, globalView, op, comm);
Declaration of Tpetra::Details::iallreduce.
Nonmember function that computes a residual Computes R = B - A * X.
Namespace Tpetra contains the class and methods constituting the Tpetra library.