Belos Package Browser (Single Doxygen Collection) Development
cxx_main_complex.cpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 //
00004 //                 Belos: Block Linear Solvers Package
00005 //                  Copyright 2004 Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ************************************************************************
00040 //@HEADER
00041 //
00042 //  This test instantiates the Belos classes using a std::complex scalar type
00043 //  and checks functionality.
00044 //
00045 
00046 #include "BelosConfigDefs.hpp"
00047 #include "BelosMVOPTester.hpp"
00048 #include "Teuchos_CommandLineProcessor.hpp"
00049 #include "BelosOutputManager.hpp"
00050 
00051 #ifdef HAVE_MPI
00052 #include <mpi.h>
00053 #endif
00054 
00055 // I/O for Harwell-Boeing files
00056 #ifdef HAVE_BELOS_TRIUTILS
00057 #include "iohb.h"
00058 #endif
00059 
00060 #include "MyMultiVec.hpp"
00061 #include "MyOperator.hpp"
00062 #include "MyBetterOperator.hpp"
00063 
00064 using namespace Teuchos;
00065 
00066 int main(int argc, char *argv[])
00067 {
00068   bool ierr, gerr;
00069   gerr = true;
00070 
00071 #ifdef HAVE_MPI
00072   // Initialize MPI and setup an Epetra communicator
00073   MPI_Init(&argc,&argv);
00074 #endif
00075 
00076   int MyPID;
00077 #ifdef HAVE_MPI
00078   MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
00079 #else 
00080   MyPID = 0;
00081 #endif
00082   bool verbose = false;
00083   std::string filename("mhd1280b.cua");
00084 
00085   // number of global elements
00086   int blockSize = 5;
00087 
00088   CommandLineProcessor cmdp(false,true);
00089   cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
00090   cmdp.setOption("debug","quiet",&verbose,"Print messages and results.");
00091   cmdp.setOption("filename",&filename,"Filename for Harwell-Boeing test matrix.");
00092   if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
00093 #ifdef HAVE_MPI
00094     MPI_Finalize();
00095 #endif
00096     return -1;
00097   }
00098 
00099 #ifdef HAVE_COMPLEX
00100   typedef std::complex<double> ST;
00101 #elif HAVE_COMPLEX_H
00102   typedef std::complex<double> ST;
00103 #else
00104   typedef double ST;
00105   // no std::complex. quit with failure.
00106   if (verbose && MyPID==0) {
00107     std::cout << "Not compiled with std::complex support." << std::endl;
00108     if (verbose && MyPID==0) {
00109       std::cout << "End Result: TEST FAILED" << std::endl;
00110     }
00111 #ifdef HAVE_MPI
00112     MPI_Finalize();
00113 #endif
00114     return -1;
00115   }
00116 #endif
00117 
00118   // Issue several useful typedefs;
00119   typedef Belos::MultiVec<ST> MV;
00120   typedef Belos::Operator<ST> OP;
00121   typedef Belos::MultiVecTraits<ST,MV> MVT;
00122   typedef Belos::OperatorTraits<ST,MV,OP> OPT;
00123 
00124   // Create an output manager to handle the I/O from the solver
00125   RCP<Belos::OutputManager<ST> > MyOM 
00126     = rcp( new Belos::OutputManager<ST>() );
00127   if (verbose) {
00128     MyOM->setVerbosity( Belos::Warnings );
00129   }
00130 
00131 
00132 #ifndef HAVE_BELOS_TRIUTILS
00133   std::cout << "This test requires Triutils. Please configure with --enable-triutils." << std::endl;
00134 #ifdef EPETRA_MPI
00135   MPI_Finalize() ;
00136 #endif
00137   MyOM->print(Belos::Warnings,"End Result: TEST FAILED\n");
00138   return -1;
00139 #endif
00140 
00141   // Get the data from the HB file
00142   int info;
00143   int dim,dim2,nnz;
00144   double *dvals;
00145   int *colptr,*rowind;
00146   nnz = -1;
00147   info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,&colptr,&rowind,&dvals);
00148   if (info == 0 || nnz < 0) {
00149     MyOM->stream(Belos::Warnings) 
00150       << "Warning reading '" << filename << "'" << std::endl
00151       << "End Result: TEST FAILED" << std::endl;
00152 #ifdef HAVE_MPI
00153     MPI_Finalize();
00154 #endif
00155     return -1;
00156   }
00157   // Convert interleaved doubles to std::complex values
00158   std::vector<ST> cvals(nnz);
00159   for (int ii=0; ii<nnz; ii++) {
00160     cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
00161   }
00162   // Build the problem matrix
00163   RCP< MyBetterOperator<ST> > A1
00164     = rcp( new MyBetterOperator<ST>(dim,colptr,nnz,rowind,&cvals[0]) );
00165 
00166 
00167   // Create a MyMultiVec for cloning
00168   std::vector<ScalarTraits<ST>::magnitudeType> v(blockSize);
00169   RCP< MyMultiVec<ST> > ivec = rcp( new MyMultiVec<ST>(dim,blockSize) );
00170   MVT::MvNorm(*ivec,v);
00171 
00172   // Create a MyOperator for testing against
00173   RCP<MyOperator<ST> > A2 = rcp( new MyOperator<ST>(dim) );
00174 
00175   // test the multivector and its adapter
00176   ierr = Belos::TestMultiVecTraits<ST,MV>(MyOM,ivec);
00177   gerr &= ierr;
00178   if (ierr) {
00179     MyOM->print(Belos::Warnings, "*** MyMultiVec<std::complex> PASSED TestMultiVecTraits()\n");
00180   }
00181   else {
00182     MyOM->print(Belos::Warnings, "*** MyMultiVec<std::complex> FAILED TestMultiVecTraits() ***\n\n");
00183   }
00184 
00185   // test the operator and its adapter
00186   ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A2);
00187   gerr &= ierr;
00188   if (ierr) {
00189     MyOM->print(Belos::Warnings,"*** MyOperator<std::complex> PASSED TestOperatorTraits()\n");
00190   }
00191   else {
00192     MyOM->print(Belos::Warnings,"*** MyOperator<std::complex> FAILED TestOperatorTraits() ***\n\n");
00193   }
00194 
00195   // test the operator and its adapter
00196   ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A1);
00197   gerr &= ierr;
00198   if (ierr) {
00199     MyOM->print(Belos::Warnings,"*** MyBetterOperator<std::complex> PASSED TestOperatorTraits()\n");
00200   }
00201   else {
00202     MyOM->print(Belos::Warnings,"*** MyBetterOperator<std::complex> FAILED TestOperatorTraits() ***\n\n");
00203   }
00204 
00205 #ifdef HAVE_MPI
00206   MPI_Finalize();
00207 #endif
00208 
00209   // Clean up.
00210   free( dvals );
00211   free( colptr );
00212   free( rowind );
00213 
00214   if (gerr == false) {
00215     MyOM->print(Belos::Warnings,"End Result: TEST FAILED\n");
00216     return -1;
00217   }
00218   //
00219   // Default return value
00220   //
00221   MyOM->print(Belos::Warnings,"End Result: TEST PASSED\n");
00222   return 0;
00223 
00224 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines