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