| 1 |
/* |
| 2 |
// @HEADER |
| 3 |
// ***************************************************************************** |
| 4 |
// Belos: Block Linear Solvers Package |
| 5 |
// |
| 6 |
// Copyright 2004-2016 NTESS and the Belos contributors. |
| 7 |
// SPDX-License-Identifier: BSD-3-Clause |
| 8 |
// ***************************************************************************** |
| 9 |
// @HEADER |
| 10 |
*/ |
| 11 |
|
| 12 |
#include <Teuchos_UnitTestHarness.hpp> |
| 13 |
#include <Tpetra_Core.hpp> |
| 14 |
#include <Tpetra_CrsMatrix.hpp> |
| 15 |
|
| 16 |
#include "BelosConfigDefs.hpp" |
| 17 |
#include "BelosMVOPTester.hpp" |
| 18 |
#include "BelosTpetraAdapter.hpp" |
| 19 |
#include "BelosOutputManager.hpp" |
| 20 |
|
| 21 |
namespace { |
| 22 |
|
| 23 |
using Teuchos::as; |
| 24 |
using Teuchos::RCP; |
| 25 |
using Teuchos::ArrayRCP; |
| 26 |
using Teuchos::rcp; |
| 27 |
using Tpetra::Map; |
| 28 |
using std::vector; |
| 29 |
using std::sort; |
| 30 |
using Teuchos::arrayViewFromVector; |
| 31 |
using Teuchos::broadcast; |
| 32 |
using Teuchos::OrdinalTraits; |
| 33 |
using Teuchos::ScalarTraits; |
| 34 |
using Teuchos::Comm; |
| 35 |
using Tpetra::MultiVector; |
| 36 |
using Tpetra::CrsMatrix; |
| 37 |
using std::endl; |
| 38 |
using Teuchos::Array; |
| 39 |
using Teuchos::ArrayView; |
| 40 |
using Teuchos::NO_TRANS; |
| 41 |
using Teuchos::TRANS; |
| 42 |
using Teuchos::CONJ_TRANS; |
| 43 |
using Belos::OutputManager; |
| 44 |
using Belos::Warnings; |
| 45 |
using Teuchos::tuple; |
| 46 |
|
| 47 |
typedef Tpetra::Map<>::node_type Node; |
| 48 |
|
| 49 |
bool testMpi = true; |
| 50 |
double errorTolSlack = 1e+1; |
| 51 |
|
| 52 |
TEUCHOS_STATIC_SETUP() |
| 53 |
{ |
| 54 |
Teuchos::CommandLineProcessor &clp = Teuchos::UnitTestRepository::getCLP(); |
| 55 |
clp.addOutputSetupOptions(true); |
| 56 |
clp.setOption( |
| 57 |
"test-mpi", "test-serial", &testMpi, |
| 58 |
"Test MPI (if available) or force test of serial. In a serial build," |
| 59 |
" this option is ignored and a serial comm is always used." ); |
| 60 |
clp.setOption( |
| 61 |
"error-tol-slack", &errorTolSlack, |
| 62 |
"Slack off of machine epsilon used to check test results" ); |
| 63 |
} |
| 64 |
|
| 65 |
RCP<const Comm<int> > getDefaultComm() |
| 66 |
{ |
| 67 |
if (testMpi) { |
| 68 |
return Tpetra::getDefaultComm(); |
| 69 |
} |
| 70 |
return rcp(new Teuchos::SerialComm<int>()); |
| 71 |
} |
| 72 |
|
| 73 |
template<class Scalar, class O1, class O2> |
| 74 |
RCP<CrsMatrix<Scalar,O1,O2,Node> > constructDiagMatrix(const RCP<const Map<O1,O2,Node> > &map) |
| 75 |
{ |
| 76 |
RCP<CrsMatrix<Scalar,O1,O2,Node> > op = rcp( new CrsMatrix<Scalar,O1,O2,Node>(map,1) ); |
| 77 |
for (size_t i=0; i<map->getLocalNumElements(); ++i) { |
| 78 |
op->insertGlobalValues(map->getGlobalElement(i),tuple(map->getGlobalElement(i)), tuple(ScalarTraits<Scalar>::one())); |
| 79 |
} |
| 80 |
op->fillComplete(); |
| 81 |
return op; |
| 82 |
} |
| 83 |
|
| 84 |
// |
| 85 |
// UNIT TESTS |
| 86 |
// |
| 87 |
|
| 88 |
//// |
| 89 |
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, MVTestDist, O1, O2, Scalar ) |
| 90 |
{ |
| 91 |
typedef Tpetra::MultiVector<Scalar,O1,O2> MV; |
| 92 |
const O2 dim = 500; |
| 93 |
const Teuchos_Ordinal numVecs = 5; |
| 94 |
// Create an output manager to handle the I/O from the solver |
| 95 |
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) ); |
| 96 |
// get a comm |
| 97 |
RCP<const Comm<int> > comm = getDefaultComm(); |
| 98 |
// create a uniform contiguous map |
| 99 |
RCP<Map<O1,O2,Node> > map = rcp( new Map<O1,O2,Node>(dim,0,comm) ); |
| 100 |
RCP<MV> mvec = rcp( new MV(map,numVecs,true) ); |
| 101 |
bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec); |
| 102 |
TEST_EQUALITY_CONST(res,true); |
| 103 |
// All procs fail if any proc fails |
| 104 |
int globalSuccess_int = -1; |
| 105 |
reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, Teuchos::outArg(globalSuccess_int) ); |
| 106 |
TEST_EQUALITY_CONST( globalSuccess_int, 0 ); |
| 107 |
} |
| 108 |
|
| 109 |
//// |
| 110 |
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, MVTestLocal, O1, O2, Scalar ) |
| 111 |
{ |
| 112 |
typedef Tpetra::MultiVector<Scalar,O1,O2> MV; |
| 113 |
const O2 dim = 500; |
| 114 |
const Teuchos_Ordinal numVecs = 5; |
| 115 |
// Create an output manager to handle the I/O from the solver |
| 116 |
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) ); |
| 117 |
// get a comm |
| 118 |
RCP<const Comm<int> > comm = getDefaultComm(); |
| 119 |
// create a uniform contiguous map |
| 120 |
RCP<Map<O1,O2,Node> > map = rcp(new Map<O1,O2,Node>(dim,0,comm,Tpetra::LocallyReplicated) ); |
| 121 |
RCP<MV> mvec = rcp( new MV(map,numVecs,true) ); |
| 122 |
bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec); |
| 123 |
TEST_EQUALITY_CONST(res,true); |
| 124 |
// All procs fail if any proc fails |
| 125 |
int globalSuccess_int = -1; |
| 126 |
reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, Teuchos::outArg(globalSuccess_int) ); |
| 127 |
TEST_EQUALITY_CONST( globalSuccess_int, 0 ); |
| 128 |
} |
| 129 |
|
| 130 |
//// |
| 131 |
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, OPTestLocal, O1, O2, Scalar ) |
| 132 |
{ |
| 133 |
typedef Tpetra::MultiVector<Scalar,O1,O2> MV; |
| 134 |
typedef Tpetra::Operator<Scalar,O1,O2> OP; |
| 135 |
const O2 dim = 500; |
| 136 |
const Teuchos_Ordinal numVecs = 5; |
| 137 |
// Create an output manager to handle the I/O from the solver |
| 138 |
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) ); |
| 139 |
// get a comm |
| 140 |
RCP<const Comm<int> > comm = getDefaultComm(); |
| 141 |
// create a uniform contiguous map |
| 142 |
RCP<Map<O1,O2,Node> > map = rcp(new Map<O1,O2,Node>(dim,0,comm,Tpetra::LocallyReplicated) ); |
| 143 |
// create a CrsMatrix |
| 144 |
RCP<OP> op = constructDiagMatrix<Scalar,O1,O2>(map); |
| 145 |
// create a multivector |
| 146 |
RCP<MV> mvec = rcp( new MV(map,numVecs,true) ); |
| 147 |
bool res = Belos::TestOperatorTraits<Scalar,MV,OP>(MyOM,mvec,op); |
| 148 |
TEST_EQUALITY_CONST(res,true); |
| 149 |
// All procs fail if any proc fails |
| 150 |
int globalSuccess_int = -1; |
| 151 |
reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, Teuchos::outArg(globalSuccess_int) ); |
| 152 |
TEST_EQUALITY_CONST( globalSuccess_int, 0 ); |
| 153 |
} |
| 154 |
|
| 155 |
//// |
| 156 |
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, OPTestDist, O1, O2, Scalar ) |
| 157 |
{ |
| 158 |
typedef Tpetra::MultiVector<Scalar,O1,O2> MV; |
| 159 |
typedef Tpetra::Operator<Scalar,O1,O2> OP; |
| 160 |
const O2 dim = 500; |
| 161 |
const Teuchos_Ordinal numVecs = 5; |
| 162 |
// Create an output manager to handle the I/O from the solver |
| 163 |
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) ); |
| 164 |
// get a comm |
| 165 |
RCP<const Comm<int> > comm = getDefaultComm(); |
| 166 |
// create a uniform contiguous map |
| 167 |
RCP<Map<O1,O2,Node> > map = rcp( new Map<O1,O2,Node>(dim,0,comm) ); |
| 168 |
// create a CrsMatrix |
| 169 |
RCP<OP> op = constructDiagMatrix<Scalar,O1,O2>(map); |
| 170 |
// create a multivector |
| 171 |
RCP<MV> mvec = rcp( new MV(map,numVecs,true) ); |
| 172 |
bool res = Belos::TestOperatorTraits<Scalar,MV,OP>(MyOM,mvec,op); |
| 173 |
TEST_EQUALITY_CONST(res,true); |
| 174 |
// All procs fail if any proc fails |
| 175 |
int globalSuccess_int = -1; |
| 176 |
reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, Teuchos::outArg(globalSuccess_int) ); |
| 177 |
TEST_EQUALITY_CONST( globalSuccess_int, 0 ); |
| 178 |
} |
| 179 |
|
| 180 |
// |
| 181 |
// INSTANTIATIONS |
| 182 |
// |
| 183 |
|
| 184 |
#define UNIT_TEST_GROUP( SCALAR, LO, GO ) \ |
| 185 |
TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, MVTestDist, LO, GO, SCALAR ) \ |
| 186 |
TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, MVTestLocal, LO, GO, SCALAR ) \ |
| 187 |
TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, OPTestDist, LO, GO, SCALAR ) \ |
| 188 |
TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, OPTestLocal, LO, GO, SCALAR ) |
| 189 |
|
| 190 |
#include "TpetraCore_ETIHelperMacros.h" |
| 191 |
|
| 192 |
TPETRA_ETI_MANGLING_TYPEDEFS() |
| 193 |
|
| 194 |
TPETRA_INSTANTIATE_SLG_NO_ORDINAL_SCALAR( UNIT_TEST_GROUP ) |
| 195 |
} |