00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "BelosConfigDefs.hpp"
00035 #include "BelosMVOPTester.hpp"
00036 #include "Teuchos_CommandLineProcessor.hpp"
00037
00038 #ifdef HAVE_MPI
00039 #include <mpi.h>
00040 #endif
00041
00042
00043 #ifdef HAVE_BELOS_TRIUTILS
00044 #include "iohb.h"
00045 #endif
00046
00047 #include "MyMultiVec.hpp"
00048 #include "MyOperator.hpp"
00049 #include "MyBetterOperator.hpp"
00050
00051 using namespace Teuchos;
00052
00053 int main(int argc, char *argv[])
00054 {
00055 int ierr, gerr;
00056 gerr = 0;
00057
00058 #ifdef HAVE_MPI
00059
00060 MPI_Init(&argc,&argv);
00061 #endif
00062
00063
00064 int MyPID = 0;
00065 #ifdef HAVE_MPI
00066 MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
00067 #endif
00068 bool verbose = false;
00069 std::string filename("mhd1280b.cua");
00070
00071
00072 int blockSize = 5;
00073
00074 CommandLineProcessor cmdp(false,true);
00075 cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
00076 cmdp.setOption("filename",&filename,"Filename for Harwell-Boeing test matrix.");
00077 if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
00078 #ifdef HAVE_MPI
00079 MPI_Finalize();
00080 #endif
00081 return -1;
00082 }
00083
00084 #ifdef HAVE_COMPLEX
00085 typedef std::complex<double> ST;
00086 #elif HAVE_COMPLEX_H
00087 typedef ::complex<double> ST;
00088 #else
00089 typedef double ST;
00090
00091 if (verbose && MyPID==0) {
00092 cout << "Not compiled with complex support." << endl;
00093 if (verbose && MyPID==0) {
00094 cout << "End Result: TEST FAILED" << endl;
00095 }
00096 #ifdef HAVE_MPI
00097 MPI_Finalize();
00098 #endif
00099 return -1;
00100 }
00101 #endif
00102
00103
00104 typedef Belos::MultiVec<ST> MV;
00105 typedef Belos::Operator<ST> OP;
00106 typedef Belos::MultiVecTraits<ST,MV> MVT;
00107 typedef Belos::OperatorTraits<ST,MV,OP> OPT;
00108
00109
00110 RefCountPtr<Belos::OutputManager<ST> > MyOM
00111 = rcp( new Belos::OutputManager<ST>( MyPID ) );
00112 if (verbose) {
00113 }
00114
00115
00116 #ifndef HAVE_BELOS_TRIUTILS
00117 cout << "This test requires Triutils. Please configure with --enable-triutils." << endl;
00118 #ifdef HAVE_MPI
00119 MPI_Finalize() ;
00120 #endif
00121 if (verbose && MyPID==0) {
00122 cout << "End Result: TEST FAILED" << endl;
00123 }
00124 return -1;
00125 #endif
00126
00127
00128 int info;
00129 int dim,dim2,nnz;
00130 double *dvals;
00131 int *colptr,*rowind;
00132 ST *cvals;
00133 nnz = -1;
00134 info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,&colptr,&rowind,&dvals);
00135 if (info == 0 || nnz < 0) {
00136 if (MyOM->isVerbosityAndPrint( Belos::Errors )) {
00137 cout << "Error reading '" << filename << "'" << endl;
00138 cout << "End Result: TEST FAILED" << endl;
00139 }
00140 #ifdef HAVE_MPI
00141 MPI_Finalize();
00142 #endif
00143 return -1;
00144 }
00145
00146 cvals = new ST[nnz];
00147 for (int ii=0; ii<nnz; ii++) {
00148 cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
00149 }
00150
00151
00152 RefCountPtr< MyBetterOperator<ST> > A1
00153 = rcp( new MyBetterOperator<ST>(dim,colptr,nnz,rowind,cvals) );
00154
00155
00156 std::vector<ScalarTraits<ST>::magnitudeType> v(blockSize);
00157 RefCountPtr< MyMultiVec<ST> > ivec = rcp( new MyMultiVec<ST>(dim,blockSize) );
00158 MVT::MvNorm(*ivec,&v);
00159
00160
00161 RefCountPtr<MyOperator<ST> > A2 = rcp( new MyOperator<ST>(dim) );
00162
00163
00164 ierr = Belos::TestMultiVecTraits<ST,MV>(MyOM,ivec);
00165 gerr |= ierr;
00166 switch (ierr) {
00167 case Belos::Ok:
00168 if ( verbose && MyPID==0 ) {
00169 cout << "*** MyMultiVec<complex> PASSED TestMultiVecTraits()" << endl;
00170 }
00171 break;
00172 case Belos::Error:
00173 if ( verbose && MyPID==0 ) {
00174 cout << "*** MyMultiVec<complex> FAILED TestMultiVecTraits() ***"
00175 << endl << endl;
00176 }
00177 break;
00178 }
00179
00180
00181 ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A2);
00182 gerr |= ierr;
00183 switch (ierr) {
00184 case Belos::Ok:
00185 if ( verbose && MyPID==0 ) {
00186 cout << "*** MyOperator<complex> PASSED TestOperatorTraits()" << endl;
00187 }
00188 break;
00189 case Belos::Error:
00190 if ( verbose && MyPID==0 ) {
00191 cout << "*** MyOperator<complex> FAILED TestOperatorTraits() ***"
00192 << endl << endl;
00193 }
00194 break;
00195 }
00196
00197
00198 ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A1);
00199 gerr |= ierr;
00200 switch (ierr) {
00201 case Belos::Ok:
00202 if ( verbose && MyPID==0 ) {
00203 cout << "*** MyBetterOperator<complex> PASSED TestOperatorTraits()" << endl;
00204 }
00205 break;
00206 case Belos::Error:
00207 if ( verbose && MyPID==0 ) {
00208 cout << "*** MyBetterOperator<complex> FAILED TestOperatorTraits() ***"
00209 << endl << endl;
00210 }
00211 break;
00212 }
00213
00214 #ifdef HAVE_MPI
00215 MPI_Finalize();
00216 #endif
00217
00218 if (gerr) {
00219 if (verbose && MyPID==0)
00220 cout << "End Result: TEST FAILED" << endl;
00221 return -1;
00222 }
00223
00224
00225
00226 if (verbose && MyPID==0)
00227 cout << "End Result: TEST PASSED" << endl;
00228 return 0;
00229
00230 }