16 #ifdef HAVE_TEUCHOS_MPI
19 #endif // HAVE_TEUCHOS_MPI
24 #ifdef HAVE_TEUCHOS_MPI
26 getRawMpiCommFromTeuchosComm (const ::Teuchos::Comm<int>& comm)
28 using ::Teuchos::Comm;
29 using ::Teuchos::MpiComm;
32 const Comm<int>* commPtr = &comm;
33 const MpiComm<int>* mpiCommPtr =
dynamic_cast<const MpiComm<int>*
> (commPtr);
34 if (mpiCommPtr == NULL) {
38 using ::Teuchos::OpaqueWrapper;
40 RCP<const OpaqueWrapper<MPI_Comm> > wrapper = mpiCommPtr->getRawMpiComm ();
41 if (wrapper.is_null ()) {
49 #endif // HAVE_TEUCHOS_MPI
54 using Teuchos::outArg;
55 using Teuchos::reduceAll;
60 out <<
"Test Teuchos::reduceAll with both intracomms and intercomms" << endl;
64 const int numProcs = comm->getSize ();
67 out <<
"This test requires > 1 processes in the input communicator "
68 "in order to be meaningful." << endl;
72 typedef int reduce_type;
73 reduce_type inputVal = 3;
74 reduce_type outputVal = 0;
75 const reduce_type expectedOutputVal = inputVal * numProcs;
78 reduceAll<int, reduce_type> (*comm,
REDUCE_SUM, inputVal,
outArg (outputVal));
81 #ifdef HAVE_TEUCHOS_MPI
82 MPI_Comm rawMpiComm = getRawMpiCommFromTeuchosComm (*comm);
85 (void) MPI_Comm_test_inter (rawMpiComm, &isInter);
87 out <<
"Input communicator is an intercomm; "
88 "no point in continuing (not safe to exercise MPI_IN_PLACE)." << endl;
91 out <<
"Input communicator is NOT an intercomm; "
92 "we may safely exercise MPI_IN_PLACE." << endl;
97 reduceAll<int, reduce_type> (*comm,
REDUCE_SUM, inputVal,
outArg (inputVal));
104 int lclSuccess = success ? 1 : 0;
106 const int err = MPI_Allreduce (&lclSuccess, &gblSuccess, 1, MPI_INT, MPI_MIN, rawMpiComm);
108 (err != MPI_SUCCESS, std::logic_error,
"MPI_Allreduce failed!");
109 success = (gblSuccess == 1);
111 #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.
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.