cxx_main_complex.cpp

Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //
00005 //                 Belos: Block Linear Solvers Package
00006 //                 Copyright (2004) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00026 // 
00027 // ************************************************************************
00028 //@HEADER
00029 //
00030 //  This test instantiates the Belos classes using a complex scalar type
00031 //  and checks functionality.
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 // I/O for Harwell-Boeing files
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   // Initialize MPI and setup an Epetra communicator
00060   MPI_Init(&argc,&argv);
00061 #endif
00062 
00063   // PID info
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   // number of global elements
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   // no complex. quit with failure.
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   // Issue several useful typedefs;
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   // Create an output manager to handle the I/O from the solver
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   // Get the data from the HB file
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   // Convert interleaved doubles to complex values
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   // Build the problem matrix
00152   RefCountPtr< MyBetterOperator<ST> > A1
00153     = rcp( new MyBetterOperator<ST>(dim,colptr,nnz,rowind,cvals) );
00154 
00155   // Create a MyMultiVec for cloning
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   // Create a MyOperator for testing against
00161   RefCountPtr<MyOperator<ST> > A2 = rcp( new MyOperator<ST>(dim) );
00162 
00163   // test the multivector and its adapter
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   // test the operator and its adapter
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   // test the operator and its adapter
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   // Default return value
00225   //
00226   if (verbose && MyPID==0)
00227     cout << "End Result: TEST PASSED" << endl;
00228   return 0;
00229 
00230 }

Generated on Thu Sep 18 12:30:21 2008 for Belos Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1