Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
1029.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "Teuchos_DefaultComm.hpp"
43 #include "Teuchos_CommHelpers.hpp"
44 #ifdef HAVE_TEUCHOS_MPI
46 #endif // HAVE_TEUCHOS_MPI
48 
49 
50 TEUCHOS_UNIT_TEST( Comm, Issue1029 )
51 {
52  using Teuchos::Comm;
53  using Teuchos::outArg;
54  using Teuchos::RCP;
55  using Teuchos::REDUCE_BOR;
56  using Teuchos::reduceAll;
57  using std::endl;
58 
59  RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm ();
60 
61  const int numProcs = comm->getSize ();
62  TEST_ASSERT( numProcs > 1 );
63  if (numProcs < 2) {
64  out << "This test requires at least 2 MPI processes." << endl;
65  return;
66  }
67 
68  const int myRank = comm->getRank ();
69 
70  // Use a mix of positive, negative, and zero values, so that neither
71  // min nor max would give the full picture.
72  int lclResult;
73  if (myRank == 0) {
74  lclResult = 0;
75  }
76  else if (myRank == 1) {
77  lclResult = -1;
78  }
79  else {
80  lclResult = 1;
81  }
82  int gblResult = 0; // output argument
83  reduceAll<int, int> (*comm, REDUCE_BOR, lclResult, outArg (gblResult));
84  TEST_EQUALITY( gblResult, -1 );
85 }
86 
Teuchos_DefaultComm.hpp
Teuchos::REDUCE_BOR
Bitwise OR.
Definition: Teuchos_EReductionType.hpp:76
TEST_ASSERT
#define TEST_ASSERT(v1)
Assert the given statement is true.
Definition: Teuchos_LocalTestingHelpers.hpp:71
TEST_EQUALITY
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
Definition: Teuchos_LocalTestingHelpers.hpp:87
TEUCHOS_UNIT_TEST
TEUCHOS_UNIT_TEST(Comm, Issue1029)
Definition: 1029.cpp:50
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition: Teuchos_RCPDecl.hpp:429
Teuchos_UnitTestHarness.hpp
Unit testing support.
Teuchos_DefaultMpiComm.hpp
Implementation of Teuchos wrappers for MPI.
Teuchos::reduceAll
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
Deprecated .
Definition: Teuchos_CommHelpers.hpp:377
Teuchos::DefaultComm::getComm
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
Definition: Teuchos_DefaultComm.hpp:212
Teuchos::reduceAll< int, int >
void reduceAll< int, int >(const Comm< int > &comm, const EReductionType reductType, const int count, const int sendBuffer[], int globalReducts[])
Definition: Teuchos_CommHelpers.cpp:1601
Teuchos_CommHelpers.hpp
Teuchos::Ptr::outArg
Ptr< T > outArg(T &arg)
create a non-persisting (required or optional) output argument for a function call.
Definition: Teuchos_PtrDecl.hpp:227
Teuchos::Comm
Abstract interface for distributed-memory communication.
Definition: Teuchos_Comm.hpp:85