Belos Package Browser (Single Doxygen Collection)
Development
Toggle main menu visibility
Loading...
Searching...
No Matches
test
MVOPTester
cxx_main_complex.cpp
Go to the documentation of this file.
1
//@HEADER
2
// ************************************************************************
3
//
4
// Belos: Block Linear Solvers Package
5
// Copyright 2004 Sandia Corporation
6
//
7
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8
// the U.S. Government retains certain rights in this software.
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
// This test instantiates the Belos classes using a std::complex scalar type
43
// and checks functionality.
44
//
45
46
#include "
BelosConfigDefs.hpp
"
47
#include "
BelosMVOPTester.hpp
"
48
#include "Teuchos_CommandLineProcessor.hpp"
49
#include "Teuchos_StandardCatchMacros.hpp"
50
#include "
BelosOutputManager.hpp
"
51
52
#ifdef HAVE_MPI
53
#include <mpi.h>
54
#endif
55
56
// I/O for Harwell-Boeing files
57
#ifdef HAVE_BELOS_TRIUTILS
58
#include "Trilinos_Util_iohb.h"
59
#endif
60
61
#include "
MyMultiVec.hpp
"
62
#include "
MyOperator.hpp
"
63
#include "
MyBetterOperator.hpp
"
64
65
using namespace
Teuchos;
66
67
int
main
(
int
argc,
char
*argv[])
68
{
69
bool
ierr, gerr;
70
gerr =
true
;
71
72
#ifdef HAVE_MPI
73
// Initialize MPI and setup an Epetra communicator
74
MPI_Init(&argc,&argv);
75
#endif
76
77
bool
success =
false
;
78
bool
verbose =
false
;
79
try
{
80
int
MyPID;
81
#ifdef HAVE_MPI
82
MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
83
#else
84
MyPID = 0;
85
#endif
86
(void) MyPID;
// forestall "set but not used" warnings
87
88
std::string filename(
"mhd1280b.cua"
);
89
90
// number of global elements
91
int
blockSize = 5;
92
93
CommandLineProcessor cmdp(
false
,
true
);
94
cmdp.setOption(
"verbose"
,
"quiet"
,&verbose,
"Print messages and results."
);
95
cmdp.setOption(
"debug"
,
"quiet"
,&verbose,
"Print messages and results."
);
96
cmdp.setOption(
"filename"
,&filename,
"Filename for Harwell-Boeing test matrix."
);
97
if
(cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
98
#ifdef HAVE_MPI
99
MPI_Finalize();
100
#endif
101
return
-1;
102
}
103
104
typedef
std::complex<double> ST;
105
106
// Issue several useful typedefs;
107
typedef
Belos::MultiVec<ST>
MV;
108
typedef
Belos::Operator<ST>
OP;
109
typedef
Belos::MultiVecTraits<ST,MV>
MVT;
110
//typedef Belos::OperatorTraits<ST,MV,OP> OPT;
111
112
// Create an output manager to handle the I/O from the solver
113
RCP<Belos::OutputManager<ST> > MyOM
114
= rcp(
new
Belos::OutputManager<ST>
() );
115
if
(verbose) {
116
MyOM->setVerbosity(
Belos::Warnings
);
117
}
118
119
#ifndef HAVE_BELOS_TRIUTILS
120
std::cout <<
"This test requires Triutils. Please configure with --enable-triutils."
<< std::endl;
121
#ifdef EPETRA_MPI
122
MPI_Finalize() ;
123
#endif
124
MyOM->print(
Belos::Warnings
,
"End Result: TEST FAILED\n"
);
125
return
-1;
126
#endif
127
128
// Get the data from the HB file
129
int
info;
130
int
dim,dim2,nnz;
131
double
*dvals;
132
int
*colptr,*rowind;
133
nnz = -1;
134
info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,&colptr,&rowind,&dvals);
135
if
(info == 0 || nnz < 0) {
136
MyOM->stream(
Belos::Warnings
)
137
<<
"Warning reading '"
<< filename <<
"'"
<< std::endl
138
<<
"End Result: TEST FAILED"
<< std::endl;
139
#ifdef HAVE_MPI
140
MPI_Finalize();
141
#endif
142
return
-1;
143
}
144
// Convert interleaved doubles to std::complex values
145
std::vector<ST> cvals(nnz);
146
for
(
int
ii=0; ii<nnz; ii++) {
147
cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
148
}
149
// Build the problem matrix
150
RCP< MyBetterOperator<ST> > A1
151
= rcp(
new
MyBetterOperator<ST>
(dim,colptr,nnz,rowind,&cvals[0]) );
152
153
154
// Create a MyMultiVec for cloning
155
std::vector<ScalarTraits<ST>::magnitudeType> v(blockSize);
156
RCP< MyMultiVec<ST> > ivec = rcp(
new
MyMultiVec<ST>
(dim,blockSize) );
157
MVT::MvNorm(*ivec,v);
158
159
// Create a MyOperator for testing against
160
RCP<MyOperator<ST> > A2 = rcp(
new
MyOperator<ST>
(dim) );
161
162
// test the multivector and its adapter
163
ierr =
Belos::TestMultiVecTraits<ST,MV>
(MyOM,ivec);
164
gerr &= ierr;
165
if
(ierr) {
166
MyOM->print(
Belos::Warnings
,
"*** MyMultiVec<std::complex> PASSED TestMultiVecTraits()\n"
);
167
}
168
else
{
169
MyOM->print(
Belos::Warnings
,
"*** MyMultiVec<std::complex> FAILED TestMultiVecTraits() ***\n\n"
);
170
}
171
172
// test the operator and its adapter
173
ierr =
Belos::TestOperatorTraits<ST,MV,OP>
(MyOM,ivec,A2);
174
gerr &= ierr;
175
if
(ierr) {
176
MyOM->print(
Belos::Warnings
,
"*** MyOperator<std::complex> PASSED TestOperatorTraits()\n"
);
177
}
178
else
{
179
MyOM->print(
Belos::Warnings
,
"*** MyOperator<std::complex> FAILED TestOperatorTraits() ***\n\n"
);
180
}
181
182
// test the operator and its adapter
183
ierr =
Belos::TestOperatorTraits<ST,MV,OP>
(MyOM,ivec,A1);
184
gerr &= ierr;
185
if
(ierr) {
186
MyOM->print(
Belos::Warnings
,
"*** MyBetterOperator<std::complex> PASSED TestOperatorTraits()\n"
);
187
}
188
else
{
189
MyOM->print(
Belos::Warnings
,
"*** MyBetterOperator<std::complex> FAILED TestOperatorTraits() ***\n\n"
);
190
}
191
192
// Clean up.
193
free( dvals );
194
free( colptr );
195
free( rowind );
196
197
success = gerr;
198
if
(success) {
199
MyOM->print(
Belos::Warnings
,
"End Result: TEST PASSED\n"
);
200
}
else
{
201
MyOM->print(
Belos::Warnings
,
"End Result: TEST FAILED\n"
);
202
}
203
}
204
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
205
206
#ifdef HAVE_MPI
207
MPI_Finalize();
208
#endif
209
210
return
( success ? EXIT_SUCCESS : EXIT_FAILURE );
211
}
BelosConfigDefs.hpp
Belos header file which uses auto-configuration information to include necessary C++ headers.
BelosMVOPTester.hpp
Test routines for MultiVecTraits and OperatorTraits conformity.
BelosOutputManager.hpp
Class which manages the output and verbosity of the Belos solvers.
MyBetterOperator.hpp
MyMultiVec.hpp
MyOperator.hpp
Belos::MultiVecTraits
Traits class which defines basic operations on multivectors.
Definition
BelosMultiVecTraits.hpp:129
Belos::MultiVec
Interface for multivectors used by Belos' linear solvers.
Definition
BelosMultiVec.hpp:91
Belos::Operator
Alternative run-time polymorphic interface for operators.
Definition
BelosOperator.hpp:80
Belos::OutputManager
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Definition
BelosOutputManager.hpp:73
MyBetterOperator
Simple example of a user's defined Belos::Operator class.
Definition
MyBetterOperator.hpp:67
MyMultiVec
Simple example of a user's defined Belos::MultiVec class.
Definition
MyMultiVec.hpp:66
MyOperator
Simple example of a user's defined Belos::Operator class.
Definition
MyOperator.hpp:66
main
int main(int argc, char *argv[])
Definition
cxx_main_complex.cpp:67
Belos::Warnings
@ Warnings
Definition
BelosTypes.hpp:256
Belos::TestOperatorTraits
bool TestOperatorTraits(const Teuchos::RCP< OutputManager< ScalarType > > &om, const Teuchos::RCP< const MV > &A, const Teuchos::RCP< const OP > &M)
Test correctness of OperatorTraits specialization and its operator implementation.
Definition
BelosMVOPTester.hpp:1454
Belos::TestMultiVecTraits
bool TestMultiVecTraits(const Teuchos::RCP< OutputManager< ScalarType > > &om, const Teuchos::RCP< const MV > &A)
Test correctness of a MultiVecTraits specialization and multivector implementation.
Definition
BelosMVOPTester.hpp:86
Generated by
1.17.0