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