Debian Codegraph @

packages/anasazi/test/MVOPTester/cxx_main_complex.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Anasazi: Block Eigensolvers Package
4 //
5 // Copyright 2004 NTESS and the Anasazi contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 //
10 // This test instantiates the Anasazi classes using a complex scalar type
11 // and checks functionality.
12 //
13
14 #include "AnasaziConfigDefs.hpp"
15 #include "AnasaziBasicSort.hpp"
16 #include "AnasaziMVOPTester.hpp"
17 #include "Teuchos_CommandLineProcessor.hpp"
18 #include "AnasaziBasicOutputManager.hpp"
19
20 #ifdef HAVE_MPI
21 #include <mpi.h>
22 #endif
23
24 // I/O for Harwell-Boeing files
25 #ifdef HAVE_ANASAZI_TRIUTILS
26 #include "Trilinos_Util_iohb.h"
27 #endif
28
29 #include "MyMultiVec.hpp"
30 #include "MyOperator.hpp"
31 #include "MyBetterOperator.hpp"
32
33 using namespace Teuchos;
34
35 int main(int argc, char *argv[])
36 {
37 using std::cout;
38 using std::endl;
39 bool ierr, gerr;
40 gerr = true;
41
42 #ifdef HAVE_MPI
43 // Initialize MPI
44 MPI_Init(&argc,&argv);
45 #endif
46
47 int MyPID;
48 #ifdef HAVE_MPI
49 MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
50 #else
51 MyPID = 0;
52 #endif
53 bool verbose = false;
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 // Issue several useful typedefs;
71 typedef std::complex<double> ST;
72 typedef Anasazi::MultiVec<ST> MV;
73 typedef Anasazi::Operator<ST> OP;
74 typedef Anasazi::MultiVecTraits<ST,MV> MVT;
75 //typedef Anasazi::OperatorTraits<ST,MV,OP> OPT; // unused
76
77 // Create an output manager to handle the I/O from the solver
78 RCP<Anasazi::OutputManager<ST> > MyOM
79 = rcp( new Anasazi::BasicOutputManager<ST>() );
80 if (verbose) {
81 MyOM->setVerbosity( Anasazi::Warnings );
82 }
83
84
85 #ifndef HAVE_ANASAZI_TRIUTILS
86 cout << "This test requires Triutils. Please configure with --enable-triutils." << endl;
87 #ifdef EPETRA_MPI
88 MPI_Finalize() ;
89 #endif
90 MyOM->print(Anasazi::Warnings,"End Result: TEST FAILED\n");
91 return -1;
92 #endif
93
94 // Get the data from the HB file
95 int info;
96 int dim,dim2,nnz;
97 double *dvals;
98 int *colptr,*rowind;
99 nnz = -1;
100 info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,&colptr,&rowind,&dvals);
101 if (info == 0 || nnz < 0) {
102 MyOM->stream(Anasazi::Warnings)
103 << "Warning reading '" << filename << "'" << endl
104 << "End Result: TEST FAILED" << endl;
105 #ifdef HAVE_MPI
106 MPI_Finalize();
107 #endif
108 return -1;
109 }
110 // Convert interleaved doubles to complex values
111 std::vector<ST> cvals(nnz);
112 for (int ii=0; ii<nnz; ii++) {
113 cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
114 }
115 // Build the problem matrix
116 RCP< const MyBetterOperator<ST> > A1
117 = rcp( new MyBetterOperator<ST>(dim,colptr,nnz,rowind,&cvals[0]) );
118
119
120 // Create a MyMultiVec for cloning
121 std::vector<ScalarTraits<ST>::magnitudeType> v(blockSize);
122 RCP< MyMultiVec<ST> > ivec = rcp( new MyMultiVec<ST>(dim,blockSize) );
123 MVT::MvNorm(*ivec,v);
124
125 // Create a MyOperator for testing against
126 RCP<MyOperator<ST> > A2 = rcp( new MyOperator<ST>(dim) );
127
128 // test the multivector and its adapter
129 ierr = Anasazi::TestMultiVecTraits<ST,MV>(MyOM,ivec);
130 gerr &= ierr;
131 if (ierr) {
132 MyOM->print(Anasazi::Warnings, "*** MyMultiVec<complex> PASSED TestMultiVecTraits()\n");
133 }
134 else {
135 MyOM->print(Anasazi::Warnings, "*** MyMultiVec<complex> FAILED TestMultiVecTraits() ***\n\n");
136 }
137
138 // test the operator and its adapter
139 ierr = Anasazi::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A2);
140 gerr &= ierr;
141 if (ierr) {
142 MyOM->print(Anasazi::Warnings,"*** MyOperator<complex> PASSED TestOperatorTraits()\n");
143 }
144 else {
145 MyOM->print(Anasazi::Warnings,"*** MyOperator<complex> FAILED TestOperatorTraits() ***\n\n");
146 }
147
148 // test the operator and its adapter
149 ierr = Anasazi::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A1);
150 gerr &= ierr;
151 if (ierr) {
152 MyOM->print(Anasazi::Warnings,"*** MyBetterOperator<complex> PASSED TestOperatorTraits()\n");
153 }
154 else {
155 MyOM->print(Anasazi::Warnings,"*** MyBetterOperator<complex> FAILED TestOperatorTraits() ***\n\n");
156 }
157
158 #ifdef HAVE_MPI
159 MPI_Finalize();
160 #endif
161
162 // Clean up.
163 std::free( dvals );
164 std::free( colptr );
165 std::free( rowind );
166
167 if (gerr == false) {
168 MyOM->print(Anasazi::Warnings,"End Result: TEST FAILED\n");
169 return -1;
170 }
171 //
172 // Default return value
173 //
174 MyOM->print(Anasazi::Warnings,"End Result: TEST PASSED\n");
175 return 0;
176
177 }