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 ()
149 if (theMpiOp_ != MPI_OP_NULL) {
153 MPI_Op mpi_op = MPI_OP_NULL;
159 int err = MPI_Op_create (&Teuchos_MPI_reduction_op, 1, &mpi_op);
161 err != MPI_SUCCESS, std::runtime_error,
"Teuchos::createReductOp: " 162 "MPI_Op_create (for custom reduction operator) failed!");
169 int key = MPI_KEYVAL_INVALID;
170 err = MPI_Comm_create_keyval (MPI_COMM_NULL_COPY_FN, freeMpiOpCallback,
172 if (err != MPI_SUCCESS) {
176 (void) MPI_Op_free (&mpi_op);
178 true, std::runtime_error,
"Teuchos::createReductOp: " 179 "MPI_Comm_create_keyval (for custom reduction operator) failed!");
184 err = MPI_Comm_set_attr (MPI_COMM_SELF, key, &val);
185 if (err != MPI_SUCCESS) {
198 (void) MPI_Op_free (&mpi_op);
200 true, std::runtime_error,
"Teuchos::createReductOp: " 201 "MPI_Comm_set_attr (for custom reduction operator) failed!");
230 (void) MPI_Comm_free_keyval (&key);
237 setReductOp (
const Teuchos::Details::MpiReductionOpBase* reductOp)
239 if (theMpiOp_ == MPI_OP_NULL) {
242 theReductOp_ = reductOp;
250 Teuchos_MPI_reduction_op (
void* invec,
253 MPI_Datatype* datatype)
255 if (theReductOp_ != NULL) {
256 theReductOp_->reduce (invec, inoutvec, len, datatype);
265 MPI_Op setMpiReductionOp (
const MpiReductionOpBase& reductOp)
267 setReductOp (&reductOp);
269 (theMpiOp_ == MPI_OP_NULL, std::logic_error,
"Teuchos::Details::" 270 "setMpiReductionOp: Failed to create reduction MPI_Op theMpiOp_. " 271 "This should never happen. " 272 "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.
Namespace of implementation details.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
Implementation detail of Teuchos' MPI wrapper.