Belos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxx_main_complex.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Belos: Block Linear Solvers Package
4 //
5 // Copyright 2004-2016 NTESS and the Belos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 //
10 // This test instantiates the Belos classes using a std::complex scalar type
11 // and checks functionality.
12 //
13 
14 #include "BelosConfigDefs.hpp"
15 #include "BelosMVOPTester.hpp"
18 #include "BelosOutputManager.hpp"
19 
20 #ifdef HAVE_MPI
21 #include <mpi.h>
22 #endif
23 
24 // I/O for Harwell-Boeing files
25 #include "Tpetra_Util_iohb.h"
26 
27 #include "MyMultiVec.hpp"
28 #include "MyOperator.hpp"
29 #include "MyBetterOperator.hpp"
30 
31 using namespace Teuchos;
32 
33 int main(int argc, char *argv[])
34 {
35  bool ierr, gerr;
36  gerr = true;
37 
38 #ifdef HAVE_MPI
39  // Initialize MPI and setup an Epetra communicator
40  MPI_Init(&argc,&argv);
41 #endif
42 
43  bool success = false;
44  bool verbose = false;
45  try {
46  int MyPID;
47 #ifdef HAVE_MPI
48  MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
49 #else
50  MyPID = 0;
51 #endif
52  (void) MyPID; // forestall "set but not used" warnings
53 
54  std::string filename("mhd1280b.cua");
55 
56  // number of global elements
57  int blockSize = 5;
58 
59  CommandLineProcessor cmdp(false,true);
60  cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
61  cmdp.setOption("debug","quiet",&verbose,"Print messages and results.");
62  cmdp.setOption("filename",&filename,"Filename for Harwell-Boeing test matrix.");
63  if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
64 #ifdef HAVE_MPI
65  MPI_Finalize();
66 #endif
67  return -1;
68  }
69 
70  typedef std::complex<double> ST;
71 
72  // Issue several useful typedefs;
73  typedef Belos::MultiVec<ST> MV;
74  typedef Belos::Operator<ST> OP;
75  typedef Belos::MultiVecTraits<ST,MV> MVT;
76  //typedef Belos::OperatorTraits<ST,MV,OP> OPT;
77 
78  // Create an output manager to handle the I/O from the solver
80  = rcp( new Belos::OutputManager<ST>() );
81  if (verbose) {
82  MyOM->setVerbosity( Belos::Warnings );
83  }
84 
85  // Get the data from the HB file
86  int info;
87  int dim,dim2,nnz;
88  double *dvals;
89  int *colptr,*rowind;
90  nnz = -1;
91  info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,&colptr,&rowind,&dvals);
92  if (info == 0 || nnz < 0) {
93  MyOM->stream(Belos::Warnings)
94  << "Warning reading '" << filename << "'" << std::endl
95  << "End Result: TEST FAILED" << std::endl;
96 #ifdef HAVE_MPI
97  MPI_Finalize();
98 #endif
99  return -1;
100  }
101  // Convert interleaved doubles to std::complex values
102  std::vector<ST> cvals(nnz);
103  for (int ii=0; ii<nnz; ii++) {
104  cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
105  }
106  // Build the problem matrix
108  = rcp( new MyBetterOperator<ST>(dim,colptr,nnz,rowind,&cvals[0]) );
109 
110 
111  // Create a MyMultiVec for cloning
112  std::vector<ScalarTraits<ST>::magnitudeType> v(blockSize);
113  RCP< MyMultiVec<ST> > ivec = rcp( new MyMultiVec<ST>(dim,blockSize) );
114  MVT::MvNorm(*ivec,v);
115 
116  // Create a MyOperator for testing against
117  RCP<MyOperator<ST> > A2 = rcp( new MyOperator<ST>(dim) );
118 
119  // test the multivector and its adapter
120  ierr = Belos::TestMultiVecTraits<ST,MV>(MyOM,ivec);
121  gerr &= ierr;
122  if (ierr) {
123  MyOM->print(Belos::Warnings, "*** MyMultiVec<std::complex> PASSED TestMultiVecTraits()\n");
124  }
125  else {
126  MyOM->print(Belos::Warnings, "*** MyMultiVec<std::complex> FAILED TestMultiVecTraits() ***\n\n");
127  }
128 
129  // test the operator and its adapter
130  ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A2);
131  gerr &= ierr;
132  if (ierr) {
133  MyOM->print(Belos::Warnings,"*** MyOperator<std::complex> PASSED TestOperatorTraits()\n");
134  }
135  else {
136  MyOM->print(Belos::Warnings,"*** MyOperator<std::complex> FAILED TestOperatorTraits() ***\n\n");
137  }
138 
139  // test the operator and its adapter
140  ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A1);
141  gerr &= ierr;
142  if (ierr) {
143  MyOM->print(Belos::Warnings,"*** MyBetterOperator<std::complex> PASSED TestOperatorTraits()\n");
144  }
145  else {
146  MyOM->print(Belos::Warnings,"*** MyBetterOperator<std::complex> FAILED TestOperatorTraits() ***\n\n");
147  }
148 
149  // Clean up.
150  free( dvals );
151  free( colptr );
152  free( rowind );
153 
154  success = gerr;
155  if (success) {
156  MyOM->print(Belos::Warnings,"End Result: TEST PASSED\n");
157  } else {
158  MyOM->print(Belos::Warnings,"End Result: TEST FAILED\n");
159  }
160  }
161  TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
162 
163 #ifdef HAVE_MPI
164  MPI_Finalize();
165 #endif
166 
167  return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
168 }
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which manages the output and verbosity of the Belos solvers.
int main(int argc, char *argv[])
Traits class which defines basic operations on multivectors.
Simple example of a user&#39;s defined Belos::MultiVec class.
Definition: MyMultiVec.hpp:33
std::string filename
Alternative run-time polymorphic interface for operators.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Test routines for MultiVecTraits and OperatorTraits conformity.
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
Simple example of a user&#39;s defined Belos::Operator class.
Definition: MyOperator.hpp:33
Interface for multivectors used by Belos&#39; linear solvers.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Simple example of a user&#39;s defined Belos::Operator class.