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   (void) MyPID; // forestall "set but not used" warnings
00083 
00084   bool verbose = false;
00085   std::string filename("mhd1280b.cua");
00086 
00087   // number of global elements
00088   int blockSize = 5;
00089 
00090   CommandLineProcessor cmdp(false,true);
00091   cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
00092   cmdp.setOption("debug","quiet",&verbose,"Print messages and results.");
00093   cmdp.setOption("filename",&filename,"Filename for Harwell-Boeing test matrix.");
00094   if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
00095 #ifdef HAVE_MPI
00096     MPI_Finalize();
00097 #endif
00098     return -1;
00099   }
00100 
00101 #ifdef HAVE_COMPLEX
00102   typedef std::complex<double> ST;
00103 #elif HAVE_COMPLEX_H
00104   typedef std::complex<double> ST;
00105 #else
00106   typedef double ST;
00107   // no std::complex. quit with failure.
00108   if (verbose && MyPID==0) {
00109     std::cout << "Not compiled with std::complex support." << std::endl;
00110     if (verbose && MyPID==0) {
00111       std::cout << "End Result: TEST FAILED" << std::endl;
00112     }
00113 #ifdef HAVE_MPI
00114     MPI_Finalize();
00115 #endif
00116     return -1;
00117   }
00118 #endif
00119 
00120   // Issue several useful typedefs;
00121   typedef Belos::MultiVec<ST> MV;
00122   typedef Belos::Operator<ST> OP;
00123   typedef Belos::MultiVecTraits<ST,MV> MVT;
00124   //typedef Belos::OperatorTraits<ST,MV,OP> OPT;
00125 
00126   // Create an output manager to handle the I/O from the solver
00127   RCP<Belos::OutputManager<ST> > MyOM
00128     = rcp( new Belos::OutputManager<ST>() );
00129   if (verbose) {
00130     MyOM->setVerbosity( Belos::Warnings );
00131   }
00132 
00133 
00134 #ifndef HAVE_BELOS_TRIUTILS
00135   std::cout << "This test requires Triutils. Please configure with --enable-triutils." << std::endl;
00136 #ifdef EPETRA_MPI
00137   MPI_Finalize() ;
00138 #endif
00139   MyOM->print(Belos::Warnings,"End Result: TEST FAILED\n");
00140   return -1;
00141 #endif
00142 
00143   // Get the data from the HB file
00144   int info;
00145   int dim,dim2,nnz;
00146   double *dvals;
00147   int *colptr,*rowind;
00148   nnz = -1;
00149   info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,&colptr,&rowind,&dvals);
00150   if (info == 0 || nnz < 0) {
00151     MyOM->stream(Belos::Warnings)
00152       << "Warning reading '" << filename << "'" << std::endl
00153       << "End Result: TEST FAILED" << std::endl;
00154 #ifdef HAVE_MPI
00155     MPI_Finalize();
00156 #endif
00157     return -1;
00158   }
00159   // Convert interleaved doubles to std::complex values
00160   std::vector<ST> cvals(nnz);
00161   for (int ii=0; ii<nnz; ii++) {
00162     cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
00163   }
00164   // Build the problem matrix
00165   RCP< MyBetterOperator<ST> > A1
00166     = rcp( new MyBetterOperator<ST>(dim,colptr,nnz,rowind,&cvals[0]) );
00167 
00168 
00169   // Create a MyMultiVec for cloning
00170   std::vector<ScalarTraits<ST>::magnitudeType> v(blockSize);
00171   RCP< MyMultiVec<ST> > ivec = rcp( new MyMultiVec<ST>(dim,blockSize) );
00172   MVT::MvNorm(*ivec,v);
00173 
00174   // Create a MyOperator for testing against
00175   RCP<MyOperator<ST> > A2 = rcp( new MyOperator<ST>(dim) );
00176 
00177   // test the multivector and its adapter
00178   ierr = Belos::TestMultiVecTraits<ST,MV>(MyOM,ivec);
00179   gerr &= ierr;
00180   if (ierr) {
00181     MyOM->print(Belos::Warnings, "*** MyMultiVec<std::complex> PASSED TestMultiVecTraits()\n");
00182   }
00183   else {
00184     MyOM->print(Belos::Warnings, "*** MyMultiVec<std::complex> FAILED TestMultiVecTraits() ***\n\n");
00185   }
00186 
00187   // test the operator and its adapter
00188   ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A2);
00189   gerr &= ierr;
00190   if (ierr) {
00191     MyOM->print(Belos::Warnings,"*** MyOperator<std::complex> PASSED TestOperatorTraits()\n");
00192   }
00193   else {
00194     MyOM->print(Belos::Warnings,"*** MyOperator<std::complex> FAILED TestOperatorTraits() ***\n\n");
00195   }
00196 
00197   // test the operator and its adapter
00198   ierr = Belos::TestOperatorTraits<ST,MV,OP>(MyOM,ivec,A1);
00199   gerr &= ierr;
00200   if (ierr) {
00201     MyOM->print(Belos::Warnings,"*** MyBetterOperator<std::complex> PASSED TestOperatorTraits()\n");
00202   }
00203   else {
00204     MyOM->print(Belos::Warnings,"*** MyBetterOperator<std::complex> FAILED TestOperatorTraits() ***\n\n");
00205   }
00206 
00207 #ifdef HAVE_MPI
00208   MPI_Finalize();
00209 #endif
00210 
00211   // Clean up.
00212   free( dvals );
00213   free( colptr );
00214   free( rowind );
00215 
00216   if (gerr == false) {
00217     MyOM->print(Belos::Warnings,"End Result: TEST FAILED\n");
00218     return -1;
00219   }
00220   //
00221   // Default return value
00222   //
00223   MyOM->print(Belos::Warnings,"End Result: TEST PASSED\n");
00224   return 0;
00225 
00226 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines