46 # define CALL_API MPIAPI
79 Teuchos_MPI_reduction_op (
void* invec,
void* inoutvec,
80 int* len, MPI_Datatype* datatype);
94 MPI_Op theMpiOp_ = MPI_OP_NULL;
101 const Teuchos::Details::MpiReductionOpBase* theReductOp_ = NULL;
105 freeMpiOp (MPI_Op* op)
111 int err = MPI_SUCCESS;
113 err = MPI_Op_free (op);
114 if (err == MPI_SUCCESS) {
129 freeMpiOpCallback (MPI_Comm,
int,
void*,
void*)
133 if (theMpiOp_ == MPI_OP_NULL) {
136 return freeMpiOp (&theMpiOp_);
144 void createReductOp ()
151 if (theMpiOp_ != MPI_OP_NULL) {
155 MPI_Op mpi_op = MPI_OP_NULL;
161 int err = MPI_Op_create (&Teuchos_MPI_reduction_op, 1, &mpi_op);
163 err != MPI_SUCCESS, std::runtime_error,
"Teuchos::createReductOp: "
164 "MPI_Op_create (for custom reduction operator) failed!");
171 int key = MPI_KEYVAL_INVALID;
172 err = MPI_Comm_create_keyval (MPI_COMM_NULL_COPY_FN, freeMpiOpCallback,
174 if (err != MPI_SUCCESS) {
178 (void) MPI_Op_free (&mpi_op);
180 true, std::runtime_error,
"Teuchos::createReductOp: "
181 "MPI_Comm_create_keyval (for custom reduction operator) failed!");
186 err = MPI_Comm_set_attr (MPI_COMM_SELF, key, &val);
187 if (err != MPI_SUCCESS) {
200 (void) MPI_Op_free (&mpi_op);
202 true, std::runtime_error,
"Teuchos::createReductOp: "
203 "MPI_Comm_set_attr (for custom reduction operator) failed!");
232 (void) MPI_Comm_free_keyval (&key);
237 #else // MPI_VERSION < 2
238 # error "Sorry, you need an MPI implementation that supports at least MPI 2.0 in order to build this code. MPI 2.0 came out in 1997. I wrote this comment in 2017. If you really _really_ want MPI 1.x support, please file a GitHub issue for this feature request at github.com/trilinos/trilinos/issues with an expression of its priority and we will get to it as soon as we can."
239 #endif // MPI_VERSION >= 2
243 setReductOp (
const Teuchos::Details::MpiReductionOpBase* reductOp)
245 if (theMpiOp_ == MPI_OP_NULL) {
248 theReductOp_ = reductOp;
256 Teuchos_MPI_reduction_op (
void* invec,
259 MPI_Datatype* datatype)
261 if (theReductOp_ != NULL) {
262 theReductOp_->reduce (invec, inoutvec, len, datatype);
271 MPI_Op setMpiReductionOp (
const MpiReductionOpBase& reductOp)
273 setReductOp (&reductOp);
275 (theMpiOp_ == MPI_OP_NULL, std::logic_error,
"Teuchos::Details::"
276 "setMpiReductionOp: Failed to create reduction MPI_Op theMpiOp_. "
277 "This should never happen. "
278 "Please report this bug to the Teuchos developers.");
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Implementation detail of Teuchos' MPI wrapper.