14 # define CALL_API MPIAPI
47 Teuchos_MPI_reduction_op (
void* invec,
void* inoutvec,
48 int* len, MPI_Datatype* datatype);
62 MPI_Op theMpiOp_ = MPI_OP_NULL;
69 const Teuchos::Details::MpiReductionOpBase* theReductOp_ = NULL;
73 freeMpiOp (MPI_Op* op)
79 int err = MPI_SUCCESS;
81 err = MPI_Op_free (op);
82 if (err == MPI_SUCCESS) {
97 freeMpiOpCallback (MPI_Comm,
int,
void*,
void*)
101 if (theMpiOp_ == MPI_OP_NULL) {
104 return freeMpiOp (&theMpiOp_);
112 void createReductOp ()
119 if (theMpiOp_ != MPI_OP_NULL) {
123 MPI_Op mpi_op = MPI_OP_NULL;
129 int err = MPI_Op_create (&Teuchos_MPI_reduction_op, 1, &mpi_op);
131 err != MPI_SUCCESS, std::runtime_error,
"Teuchos::createReductOp: "
132 "MPI_Op_create (for custom reduction operator) failed!");
139 int key = MPI_KEYVAL_INVALID;
140 err = MPI_Comm_create_keyval (MPI_COMM_NULL_COPY_FN, freeMpiOpCallback,
142 if (err != MPI_SUCCESS) {
146 (void) MPI_Op_free (&mpi_op);
148 true, std::runtime_error,
"Teuchos::createReductOp: "
149 "MPI_Comm_create_keyval (for custom reduction operator) failed!");
154 err = MPI_Comm_set_attr (MPI_COMM_SELF, key, &val);
155 if (err != MPI_SUCCESS) {
168 (void) MPI_Op_free (&mpi_op);
170 true, std::runtime_error,
"Teuchos::createReductOp: "
171 "MPI_Comm_set_attr (for custom reduction operator) failed!");
200 (void) MPI_Comm_free_keyval (&key);
205 #else // MPI_VERSION < 2
206 # 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."
207 #endif // MPI_VERSION >= 2
211 setReductOp (
const Teuchos::Details::MpiReductionOpBase* reductOp)
213 if (theMpiOp_ == MPI_OP_NULL) {
216 theReductOp_ = reductOp;
224 Teuchos_MPI_reduction_op (
void* invec,
227 MPI_Datatype* datatype)
229 if (theReductOp_ != NULL) {
230 theReductOp_->reduce (invec, inoutvec, len, datatype);
239 MPI_Op setMpiReductionOp (
const MpiReductionOpBase& reductOp)
241 setReductOp (&reductOp);
243 (theMpiOp_ == MPI_OP_NULL, std::logic_error,
"Teuchos::Details::"
244 "setMpiReductionOp: Failed to create reduction MPI_Op theMpiOp_. "
245 "This should never happen. "
246 "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.