12 #ifdef HAVE_TPETRACORE_MPI
13 #include "Teuchos_DefaultMpiComm.hpp"
14 #endif // HAVE_TPETRACORE_MPI
15 #include "Teuchos_DefaultSerialComm.hpp"
20 #ifdef HAVE_TPETRACORE_MPI
21 std::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);
36 #endif // HAVE_TPETRACORE_MPI
40 std::shared_ptr<CommRequest>
42 return std::shared_ptr<CommRequest>(
new CommRequest());
45 #ifdef HAVE_TPETRACORE_MPI
49 iallreduceRaw(
const void* sendbuf,
52 MPI_Datatype mpiDatatype,
53 const Teuchos::EReductionType op,
55 MPI_Op rawOp = ::Teuchos::Details::getMpiOpForEReductionType(op);
56 MPI_Request req = MPI_REQUEST_NULL;
57 int err = MPI_SUCCESS;
58 if (sendbuf == recvbuf) {
62 err = MPI_Iallreduce(MPI_IN_PLACE, recvbuf, count, mpiDatatype,
65 err = MPI_Iallreduce(sendbuf, recvbuf, count, mpiDatatype,
68 TEUCHOS_TEST_FOR_EXCEPTION(err != MPI_SUCCESS, std::runtime_error,
69 "MPI_Iallreduce failed with the following error: "
70 << getMpiErrorString(err));
75 void allreduceRaw(
const void* sendbuf,
78 MPI_Datatype mpiDatatype,
79 const Teuchos::EReductionType op,
81 MPI_Op rawOp = ::Teuchos::Details::getMpiOpForEReductionType(op);
82 int err = MPI_SUCCESS;
83 if (sendbuf == recvbuf) {
84 err = MPI_Allreduce(MPI_IN_PLACE, recvbuf,
85 count, mpiDatatype, rawOp, comm);
88 (void)MPI_Allreduce(const_cast<void*>(sendbuf), recvbuf,
89 count, mpiDatatype, rawOp, comm);
91 TEUCHOS_TEST_FOR_EXCEPTION(err != MPI_SUCCESS, std::runtime_error,
92 "MPI_Allreduce failed with the following error: "
93 << getMpiErrorString(err));
96 #endif // HAVE_TPETRACORE_MPI
100 std::shared_ptr<CommRequest>
101 iallreduce(
const int localValue,
103 const ::Teuchos::EReductionType op,
104 const ::Teuchos::Comm<int>& comm) {
106 Kokkos::View<int*, Kokkos::HostSpace> localView(
107 Kokkos::ViewAllocateWithoutInitializing(
"localValue"), 1);
108 localView(0) = localValue;
109 Kokkos::View<int*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
110 globalView(&globalValue, 1);
111 return ::Tpetra::Details::iallreduce<decltype(localView), decltype(globalView)>(localView, globalView, op, comm);
Declaration of Tpetra::Details::iallreduce.