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 std::complex scalar type
00031 //  and checks functionality.
00032 //
00033 
00034 #include "BelosConfigDefs.hpp"
00035 #include "BelosMVOPTester.hpp"
00036 #include "Teuchos_CommandLineProcessor.hpp"
00037 #include "BelosOutputManager.hpp"
00038 
00039 #ifdef HAVE_MPI
00040 #include <mpi.h>
00041 #endif
00042 
00043 // I/O for Harwell-Boeing files
00044 #ifdef HAVE_BELOS_TRIUTILS
00045 #include "iohb.h"
00046 #endif
00047 
00048 #include "MyMultiVec.hpp"
00049 #include "MyOperator.hpp"
00050 #include "MyBetterOperator.hpp"
00051 
00052 using namespace Teuchos;
00053 
00054 int main(int argc, char *argv[])
00055 {
00056   bool ierr, gerr;
00057   gerr = true;
00058 
00059 #ifdef HAVE_MPI
00060   // Initialize MPI and setup an Epetra communicator
00061   MPI_Init(&argc,&argv);
00062 #endif
00063 
00064   int MyPID;
00065 #ifdef HAVE_MPI
00066   MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
00067 #else 
00068   MyPID = 0;
00069 #endif
00070   bool verbose = false;
00071   std::string filename("mhd1280b.cua");
00072 
00073   // number of global elements
00074   int blockSize = 5;
00075 
00076   CommandLineProcessor cmdp(false,true);
00077   cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
00078   cmdp.setOption("debug","quiet",&verbose,"Print messages and results.");
00079   cmdp.setOption("filename",&filename,"Filename for Harwell-Boeing test matrix.");
00080   if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
00081 #ifdef HAVE_MPI
00082     MPI_Finalize();
00083 #endif
00084     return -1;
00085   }
00086 
00087 #ifdef HAVE_COMPLEX
00088   typedef std::complex<double> ST;
00089 #elif HAVE_COMPLEX_H
00090   typedef std::complex<double> ST;
00091 #else
00092   typedef double ST;
00093   // no std::complex. quit with failure.
00094   if (verbose && MyPID==0) {
00095     std::cout << "Not compiled with std::complex support." << std::endl;
00096     if (verbose && MyPID==0) {
00097       std::cout << "End Result: TEST FAILED" << std::endl;
00098     }
00099 #ifdef HAVE_MPI
00100     MPI_Finalize();
00101 #endif
00102     return -1;
00103   }
00104 #endif
00105 
00106   // Issue several useful typedefs;
00107   typedef Belos::MultiVec<ST> MV;
00108   typedef Belos::Operator<ST> OP;
00109   typedef Belos::MultiVecTraits<ST,MV> MVT;
00110   typedef Belos::OperatorTraits<ST,MV,OP> OPT;
00111 
00112   // Create an output manager to handle the I/O from the solver
00113   RCP<Belos::OutputManager<ST> > MyOM 
00114     = rcp( new Belos::OutputManager<ST>() );
00115   if (verbose) {
00116     MyOM->setVerbosity( Belos::Warnings );
00117   }
00118 
00119 
00120 #ifndef HAVE_BELOS_TRIUTILS
00121   std::cout << "This test requires Triutils. Please configure with --enable-triutils." << std::endl;
00122 #ifdef EPETRA_MPI
00123   MPI_Finalize() ;
00124 #endif
00125   MyOM->print(Belos::Warnings,"End Result: TEST FAILED\n");
00126   return -1;
00127 #endif
00128 
00129   // Get the data from the HB file
00130   int info;
00131   int dim,dim2,nnz;
00132   double *dvals;
00133   int *colptr,*rowind;
00134   nnz = -1;
00135   info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,&colptr,&rowind,&dvals);
00136   if (info == 0 || nnz < 0) {
00137     MyOM->stream(Belos::Warnings) 
00138       << "Warning reading '" << filename << "'" << std::endl
00139       << "End Result: TEST FAILED" << std::endl;
00140 #ifdef HAVE_MPI
00141     MPI_Finalize();
00142 #endif
00143     return -1;
00144   }
00145   // Convert interleaved doubles to std::complex values
00146   std::vector<ST> cvals(nnz);
00147   for (int ii=0; ii<nnz; ii++) {
00148     cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
00149   }
00150   // Build the problem matrix
00151   RCP< MyBetterOperator<ST> > A1
00152     = rcp( new MyBetterOperator<ST>(dim,colptr,nnz,rowind,&cvals[0]) );
00153 
00154 
00155   // Create a MyMultiVec for cloning
00156   std::vector<ScalarTraits<ST>::magnitudeType> v(blockSize);
00157   RCP< MyMultiVec<ST> > ivec = rcp( new MyMultiVec<ST>(dim,blockSize) );
00158   MVT::MvNorm(*ivec,v);
00159 
00160   // Create a MyOperator for testing against
00161   RCP<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   if (ierr) {
00167     MyOM->print(Belos::Warnings, "*** MyMultiVec<std::complex> PASSED TestMultiVecTraits()\n");
00168   }
00169   else {
00170     MyOM->print(Belos::Warnings, "*** MyMultiVec<std::complex> FAILED TestMultiVecTraits() ***\n\n");
00171   }
00172 
00173   // test the operator and its adapter
00174   ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A2);
00175   gerr &= ierr;
00176   if (ierr) {
00177     MyOM->print(Belos::Warnings,"*** MyOperator<std::complex> PASSED TestOperatorTraits()\n");
00178   }
00179   else {
00180     MyOM->print(Belos::Warnings,"*** MyOperator<std::complex> FAILED TestOperatorTraits() ***\n\n");
00181   }
00182 
00183   // test the operator and its adapter
00184   ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A1);
00185   gerr &= ierr;
00186   if (ierr) {
00187     MyOM->print(Belos::Warnings,"*** MyBetterOperator<std::complex> PASSED TestOperatorTraits()\n");
00188   }
00189   else {
00190     MyOM->print(Belos::Warnings,"*** MyBetterOperator<std::complex> FAILED TestOperatorTraits() ***\n\n");
00191   }
00192 
00193 #ifdef HAVE_MPI
00194   MPI_Finalize();
00195 #endif
00196 
00197   // Clean up.
00198   free( dvals );
00199   free( colptr );
00200   free( rowind );
00201 
00202   if (gerr == false) {
00203     MyOM->print(Belos::Warnings,"End Result: TEST FAILED\n");
00204     return -1;
00205   }
00206   //
00207   // Default return value
00208   //
00209   MyOM->print(Belos::Warnings,"End Result: TEST PASSED\n");
00210   return 0;
00211 
00212 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:05:15 2011 for Belos Package Browser (Single Doxygen Collection) by  doxygen 1.6.3