Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
GlobalMPISession_UnitTests.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
43#include "Teuchos_Array.hpp"
44
45#ifdef HAVE_MPI
46# include "mpi.h"
47#endif
48
50
51#ifdef HAVE_TEUCHOSCORE_KOKKOSCORE
52# include <string>
53// NOTE (mfh 18 Apr 2016) KokkosCore requires C++11, so we may include
54// type_traits here. Please do not include it unconditionally,
55// because TeuchosCore does NOT require C++11.
56# include <type_traits>
57#endif // HAVE_TEUCHOSCORE_KOKKOSCORE
58
59//
60// Unit tests for GlobalMPISession
61//
62// NOTE: Becuase this class is used to implement the parallel reduction
63// feature of the unit test harness, we can't use that feature here and we
64// have to do the global reductions across processes ourselves.
65//
66
67
68namespace Teuchos {
69
70
81
82
100
101
103 out << "*** Just make sure the basic barrier does not hang or something.\n";
106}
107
108
115
116
118{
121 {
123 ECHO(allInts.resize(numProcs-1));
124 TEST_THROW(GlobalMPISession::allGather(procRank+1, allInts()), std::out_of_range);
125 ECHO(allInts.resize(numProcs+1));
126 TEST_THROW(GlobalMPISession::allGather(procRank+1, allInts()), std::out_of_range);
127 }
128 {
130 for (int k = 0; k < numProcs; ++k) {
131 allInts_expected[k] = k+1;
132 }
136 }
137}
138
139
140#ifdef HAVE_TEUCHOSCORE_KOKKOSCORE
141// Check whether GlobalMPISession's constructor (called in the unit
142// test harness, not in this file) correctly saved a copy of the
143// command-line arguments. Command-line arguments _should_ be
144// propagated to all MPI processes.
145//
146//
147TEUCHOS_UNIT_TEST( GlobalMPISession, getArgv )
148{
149 auto argvCopy = GlobalMPISession::getArgv ();
150 const auto numArgs = argvCopy.size ();
151 static_assert (std::is_integral<std::decay<decltype (numArgs)>::type>::value,
152 "The return type of getArgv has a size() method, "
153 "but it does not return an integer.");
154 if (numArgs > 0) {
155 // This tests that argvCopy has an operator[](int) const.
156 const auto arg0 = argvCopy[0];
157 static_assert (std::is_convertible<std::decay<decltype (arg0)>::type,
158 std::string>::value,
159 "The return type of getArgv must have an operator[](int) "
160 "that returns a type convertible to std::string.");
161 }
162}
163#endif // HAVE_TEUCHOSCORE_KOKKOSCORE
164
165
166} // namespace Teuchos
167
168
169
Templated array class derived from the STL std::vector.
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails).
#define ECHO(statement)
Echo the given statement before it is executed.
Unit testing support.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Initialize, finalize, and query the global MPI session.
static int sum(int localVal)
Sum a set of integers across processes.
static void barrier()
Call MPI_Barrier() on MPI_COMM_WORLD.
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
static int getNProc()
The number of processes in MPI_COMM_WORLD.
static bool mpiIsInitialized()
Return whether MPI was initialized.
static bool mpiIsFinalized()
Return whether MPI was already finalized.
static void allGather(int localVal, const ArrayView< int > &allVals)
Global all-to-all of a set of integers across processes.
Concrete serial communicator subclass.
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
void globalReduceSuccess(bool &success, FancyOStream &out)