2
// ************************************************************************
5
// Belos: Block Linear Solvers Package
6
// Copyright (2004) Sandia Corporation
8
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9
// license for use of this work by or on behalf of the U.S. Government.
11
// This library is free software; you can redistribute it and/or modify
12
// it under the terms of the GNU Lesser General Public License as
13
// published by the Free Software Foundation; either version 2.1 of the
14
// License, or (at your option) any later version.
16
// This library is distributed in the hope that it will be useful, but
17
// WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
// Lesser General Public License for more details.
21
// You should have received a copy of the GNU Lesser General Public
22
// License along with this library; if not, write to the Free Software
23
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
27
// ************************************************************************
30
// This test instantiates the Belos classes using a std::complex scalar type
31
// and checks functionality.
34
1
#include <Teuchos_UnitTestHarness.hpp>
35
2
#include <Tpetra_DefaultPlatform.hpp>
36
3
#include <Tpetra_CrsMatrix.hpp>
95
43
"Slack off of machine epsilon used to check test results" );
98
template<class Ordinal>
99
RCP<const Platform<Ordinal> > getDefaultPlatform()
46
RCP<const Comm<int> > getDefaultComm()
48
RCP<const Comm<int> > ret;
102
return DefaultPlatform<Ordinal>::getPlatform();
104
return rcp(new Tpetra::SerialPlatform<Ordinal>());
50
ret = DefaultPlatform::getDefaultPlatform().getComm();
53
ret = rcp(new Teuchos::SerialComm<int>());
107
template<class Ordinal, class Scalar>
108
RCP<CrsMatrix<Ordinal,Scalar> > constructTriDiagMatrix(const Map<Ordinal> &map)
58
template<class Scalar, class LO, class GO>
59
RCP<CrsMatrix<Scalar,LO,GO> > constructDiagMatrix(const RCP<const Map<LO,GO> > &map)
110
RCP<CrsMatrix<Ordinal,Scalar> > op = rcp( new CrsMatrix<Ordinal,Scalar>(map) );
61
// create identity matrix
62
RCP<CrsMatrix<Scalar,LO,GO> > op = rcp( new CrsMatrix<Scalar,LO,GO>(map,1) );
63
for (size_t lid=0; lid < map->getNodeNumElements(); ++lid) {
64
op->insertGlobalValues(map->getGlobalElement(lid),tuple(map->getGlobalElement(lid)), tuple(ScalarTraits<Scalar>::one()));
111
66
op->fillComplete();
120
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( MultiVector, MVTestDist, Ordinal, Scalar )
122
typedef Tpetra::MultiVector<Ordinal,Scalar> MV;
123
const Ordinal dim = 500;
124
const Ordinal numVecs = 5;
125
const Ordinal ZERO = OrdinalTraits<Ordinal>::zero();
126
// Create an output manager to handle the I/O from the solver
127
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) );
129
const Platform<Ordinal> & platform = *(getDefaultPlatform<Ordinal>());
131
RCP<Comm<Ordinal> > comm = platform.createComm();
132
// create a uniform contiguous map
133
Map<Ordinal> map(dim,ZERO,platform);
134
RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
135
bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec);
136
TEST_EQUALITY_CONST(res,true);
137
// All procs fail if any proc fails
138
int globalSuccess_int = -1;
139
reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, &globalSuccess_int );
140
TEST_EQUALITY_CONST( globalSuccess_int, 0 );
144
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( MultiVector, MVTestLocal, Ordinal, Scalar )
146
typedef Tpetra::MultiVector<Ordinal,Scalar> MV;
147
const Ordinal dim = 500;
148
const Ordinal numVecs = 5;
149
const Ordinal ZERO = OrdinalTraits<Ordinal>::zero();
150
// Create an output manager to handle the I/O from the solver
151
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) );
153
const Platform<Ordinal> & platform = *(getDefaultPlatform<Ordinal>());
155
RCP<Comm<Ordinal> > comm = platform.createComm();
156
// create a uniform contiguous map
157
Map<Ordinal> map(dim,ZERO,platform,true);
158
RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
159
bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec);
160
TEST_EQUALITY_CONST(res,true);
161
// All procs fail if any proc fails
162
int globalSuccess_int = -1;
163
reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, &globalSuccess_int );
164
TEST_EQUALITY_CONST( globalSuccess_int, 0 );
168
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( MultiVector, OPTestLocal, Ordinal, Scalar )
170
typedef Tpetra::MultiVector<Ordinal,Scalar> MV;
171
typedef Tpetra::Operator<Ordinal,Scalar> OP;
172
// const Ordinal dim = 500;
173
const Ordinal dim = 10;
174
const Ordinal numVecs = 5;
175
const Ordinal ZERO = OrdinalTraits<Ordinal>::zero();
176
// Create an output manager to handle the I/O from the solver
177
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) );
179
const Platform<Ordinal> & platform = *(getDefaultPlatform<Ordinal>());
181
RCP<Comm<Ordinal> > comm = platform.createComm();
75
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, MVTestDist, LO, GO, Scalar )
77
typedef MultiVector<Scalar,LO,GO> MV;
78
const global_size_t dim = 500;
79
const size_t numVecs = 5;
80
// Create an output manager to handle the I/O from the solver
81
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcpFromRef(out)) );
83
RCP<const Comm<int> > comm = getDefaultComm();
84
// create a uniform contiguous map
85
RCP<const Map<LO,GO> > map = rcp( new Map<LO,GO>(dim,static_cast<GO>(0),comm) );
86
RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
87
bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec);
88
TEST_EQUALITY_CONST(res,true);
89
// All procs fail if any proc fails
90
int globalSuccess_int = -1;
91
reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, &globalSuccess_int );
92
TEST_EQUALITY_CONST( globalSuccess_int, 0 );
96
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, MVTestLocal, LO, GO, Scalar )
98
typedef MultiVector<Scalar,LO,GO> MV;
99
const global_size_t dim = 500;
100
const size_t numVecs = 5;
101
// Create an output manager to handle the I/O from the solver
102
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcpFromRef(out)) );
104
RCP<const Comm<int> > comm = getDefaultComm();
105
// create a uniform contiguous map
106
RCP<const Map<LO,GO> > map = rcp(new Map<LO,GO>(dim,static_cast<GO>(0),comm,LocallyReplicated) );
107
RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
108
bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec);
109
TEST_EQUALITY_CONST(res,true);
110
// All procs fail if any proc fails
111
int globalSuccess_int = -1;
112
reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, &globalSuccess_int );
113
TEST_EQUALITY_CONST( globalSuccess_int, 0 );
117
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, OPTestLocal, LO, GO, Scalar )
119
typedef MultiVector<Scalar,LO,GO> MV;
120
typedef Operator<Scalar,LO,GO> OP;
121
const global_size_t dim = 500;
122
const size_t numVecs = 5;
123
// Create an output manager to handle the I/O from the solver
124
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcpFromRef(out)) );
126
RCP<const Comm<int> > comm = getDefaultComm();
182
127
// create a uniform contiguous map (local)
183
Map<Ordinal> map(dim,ZERO,platform,true);
128
RCP<const Map<LO,GO> > map = rcp( new Map<LO,GO>(dim,static_cast<GO>(0),comm,LocallyReplicated) );
184
129
// create a CrsMatrix
185
RCP<OP> op = constructTriDiagMatrix<Ordinal,Scalar>(map);
130
RCP<OP> op = constructDiagMatrix<Scalar,LO,GO>(map);
186
131
// create a multivector
187
132
RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
188
133
bool res = Belos::TestOperatorTraits<Scalar,MV,OP>(MyOM,mvec,op);
197
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( MultiVector, OPTestDist, Ordinal, Scalar )
142
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, OPTestDist, LO, GO, Scalar )
199
typedef Tpetra::MultiVector<Ordinal,Scalar> MV;
200
typedef Tpetra::Operator<Ordinal,Scalar> OP;
201
// const Ordinal dim = 500;
202
const Ordinal dim = 10;
203
const Ordinal numVecs = 5;
204
const Ordinal ZERO = OrdinalTraits<Ordinal>::zero();
144
typedef MultiVector<Scalar,LO,GO> MV;
145
typedef Operator<Scalar,LO,GO> OP;
146
const global_size_t dim = 500;
147
const size_t numVecs = 5;
205
148
// Create an output manager to handle the I/O from the solver
206
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) );
208
const Platform<Ordinal> & platform = *(getDefaultPlatform<Ordinal>());
210
RCP<Comm<Ordinal> > comm = platform.createComm();
149
RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcpFromRef(out)) );
151
RCP<const Comm<int> > comm = getDefaultComm();
211
152
// create a uniform contiguous map
212
Map<Ordinal> map(dim,ZERO,platform);
153
RCP<const Map<LO,GO> > map = rcp( new Map<LO,GO>(dim,static_cast<GO>(0),comm) );
213
154
// create a CrsMatrix
214
RCP<OP> op = constructTriDiagMatrix<Ordinal,Scalar>(map);
155
RCP<OP> op = constructDiagMatrix<Scalar,LO,GO>(map);
215
156
// create a multivector
216
157
RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
217
158
bool res = Belos::TestOperatorTraits<Scalar,MV,OP>(MyOM,mvec,op);
229
170
#ifdef HAVE_TEUCHOS_COMPLEX
230
# define UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(ORDINAL)\
171
# define UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(LO, GO)\
231
172
typedef std::complex<float> ComplexFloat; \
232
UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, ComplexFloat)
233
# define UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(ORDINAL)\
173
UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, ComplexFloat)
174
# define UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(LO, GO)\
234
175
typedef std::complex<double> ComplexDouble; \
235
UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, ComplexDouble)
176
UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, ComplexDouble)
237
# define UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(ORDINAL)
238
# define UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(ORDINAL)
178
# define UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(LO, GO)
179
# define UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(LO, GO)
241
182
// Uncomment this for really fast development cycles but make sure to comment
242
183
// it back again before checking in so that we can test all the types.
243
#define FAST_DEVELOPMENT_UNIT_TEST_BUILD
245
#define UNIT_TEST_GROUP_ORDINAL_SCALAR( ORDINAL, SCALAR ) \
246
TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( MultiVector, MVTestDist, ORDINAL, SCALAR ) \
247
TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( MultiVector, MVTestLocal, ORDINAL, SCALAR ) \
248
TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( MultiVector, OPTestDist, ORDINAL, SCALAR ) \
249
TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( MultiVector, OPTestLocal, ORDINAL, SCALAR )
184
// #define FAST_DEVELOPMENT_UNIT_TEST_BUILD
186
#define UNIT_TEST_GROUP_ORDINAL_SCALAR( LO, GO, SCALAR ) \
187
TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, MVTestDist, LO, GO, SCALAR ) \
188
TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, MVTestLocal, LO, GO, SCALAR ) \
189
TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, OPTestDist, LO, GO, SCALAR ) \
190
TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, OPTestLocal, LO, GO, SCALAR )
192
#define UNIT_TEST_GROUP_ORDINAL( ORDINAL ) \
193
UNIT_TEST_GROUP_ORDINAL_ORDINAL( ORDINAL, ORDINAL )
251
195
# ifdef FAST_DEVELOPMENT_UNIT_TEST_BUILD
252
# define UNIT_TEST_GROUP_ORDINAL( ORDINAL ) \
253
/*UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(ORDINAL)*/ \
254
UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, double)
196
# define UNIT_TEST_GROUP_ORDINAL_ORDINAL( LO, GO ) \
197
UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(LO, GO) \
198
UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, double)
255
200
UNIT_TEST_GROUP_ORDINAL(int)
256
201
# else // not FAST_DEVELOPMENT_UNIT_TEST_BUILD
258
# define UNIT_TEST_GROUP_ORDINAL( ORDINAL ) \
259
UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, char) \
260
UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, int) \
261
UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, float) \
262
UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, double) \
263
UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(ORDINAL) \
264
UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(ORDINAL)
265
UNIT_TEST_GROUP_ORDINAL(int)
203
# define UNIT_TEST_GROUP_ORDINAL_ORDINAL( LO, GO ) \
204
UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, float) \
205
UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, double) \
206
UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(LO, GO) \
207
UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(LO, GO)
267
209
typedef short int ShortInt;
268
210
UNIT_TEST_GROUP_ORDINAL(ShortInt)
212
UNIT_TEST_GROUP_ORDINAL(int)
269
214
typedef long int LongInt;
270
UNIT_TEST_GROUP_ORDINAL(LongInt)
215
UNIT_TEST_GROUP_ORDINAL_ORDINAL( int, LongInt )
271
216
# ifdef HAVE_TEUCHOS_LONG_LONG_INT
272
217
typedef long long int LongLongInt;
273
UNIT_TEST_GROUP_ORDINAL(LongLongInt)
218
UNIT_TEST_GROUP_ORDINAL_ORDINAL( int,LongLongInt)
276
221
# endif // FAST_DEVELOPMENT_UNIT_TEST_BUILD