48 #ifdef HAVE_TEUCHOS_MPI
51 #endif // HAVE_TEUCHOS_MPI
56 #ifdef HAVE_TEUCHOS_MPI
58 getRawMpiCommFromTeuchosComm (const ::Teuchos::Comm<int>& comm)
60 using ::Teuchos::Comm;
61 using ::Teuchos::MpiComm;
64 const Comm<int>* commPtr = &comm;
65 const MpiComm<int>* mpiCommPtr =
dynamic_cast<const MpiComm<int>*
> (commPtr);
66 if (mpiCommPtr == NULL) {
70 using ::Teuchos::OpaqueWrapper;
72 RCP<const OpaqueWrapper<MPI_Comm> > wrapper = mpiCommPtr->getRawMpiComm ();
73 if (wrapper.is_null ()) {
81 #endif // HAVE_TEUCHOS_MPI
86 using Teuchos::outArg;
92 out <<
"Test Teuchos::reduceAll with both intracomms and intercomms" << endl;
96 const int numProcs = comm->getSize ();
99 out <<
"This test requires > 1 processes in the input communicator "
100 "in order to be meaningful." << endl;
104 typedef int reduce_type;
105 reduce_type inputVal = 3;
106 reduce_type outputVal = 0;
107 const reduce_type expectedOutputVal = inputVal * numProcs;
110 reduceAll<int, reduce_type> (*comm,
REDUCE_SUM, inputVal,
outArg (outputVal));
113 #ifdef HAVE_TEUCHOS_MPI
114 MPI_Comm rawMpiComm = getRawMpiCommFromTeuchosComm (*comm);
117 (void) MPI_Comm_test_inter (rawMpiComm, &isInter);
119 out <<
"Input communicator is an intercomm; "
120 "no point in continuing (not safe to exercise MPI_IN_PLACE)." << endl;
123 out <<
"Input communicator is NOT an intercomm; "
124 "we may safely exercise MPI_IN_PLACE." << endl;
129 reduceAll<int, reduce_type> (*comm,
REDUCE_SUM, inputVal,
outArg (inputVal));
136 int lclSuccess = success ? 1 : 0;
138 const int err = MPI_Allreduce (&lclSuccess, &gblSuccess, 1, MPI_INT, MPI_MIN, rawMpiComm);
140 (err != MPI_SUCCESS, std::logic_error,
"MPI_Allreduce failed!");
141 success = (gblSuccess == 1);
143 #endif // HAVE_TEUCHOS_MPI
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
Implementation of Teuchos wrappers for MPI.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
Deprecated .
Abstract interface for distributed-memory communication.
Smart reference counting pointer class for automatic garbage collection.
Ptr< T > outArg(T &arg)
create a non-persisting (required or optional) output argument for a function call.