Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
1029.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Teuchos_DefaultComm.hpp"
11 #include "Teuchos_CommHelpers.hpp"
12 #ifdef HAVE_TEUCHOS_MPI
14 #endif // HAVE_TEUCHOS_MPI
16 
17 
18 TEUCHOS_UNIT_TEST( Comm, Issue1029 )
19 {
20  using Teuchos::Comm;
21  using Teuchos::outArg;
22  using Teuchos::RCP;
23  using Teuchos::REDUCE_BOR;
24  using Teuchos::reduceAll;
25  using std::endl;
26 
27  RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm ();
28 
29  const int numProcs = comm->getSize ();
30  TEST_ASSERT( numProcs > 1 );
31  if (numProcs < 2) {
32  out << "This test requires at least 2 MPI processes." << endl;
33  return;
34  }
35 
36  const int myRank = comm->getRank ();
37 
38  // Use a mix of positive, negative, and zero values, so that neither
39  // min nor max would give the full picture.
40  int lclResult;
41  if (myRank == 0) {
42  lclResult = 0;
43  }
44  else if (myRank == 1) {
45  lclResult = -1;
46  }
47  else {
48  lclResult = 1;
49  }
50  int gblResult = 0; // output argument
51  reduceAll<int, int> (*comm, REDUCE_BOR, lclResult, outArg (gblResult));
52  TEST_EQUALITY( gblResult, -1 );
53 }
54 
#define TEST_ASSERT(v1)
Assert the given statement is true.
#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.
Unit testing support.
Implementation of Teuchos wrappers for MPI.
void reduceAll< int, int >(const Comm< int > &comm, const EReductionType reductType, const int count, const int sendBuffer[], int globalReducts[])
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.