test_single_stratimikos_solver.cpp

The bottom of this page shows a simple test program for how the Thyra::DefaultRealLinearSolverBuilder class is used to take a parameter list (e.g. read from a file) and use it to build Thyra::LinearOpWithSolveFactory and Thyra::PreconditionerFactoryBase objects.

The arguments that the testing program driver that calls this example are:

Echoing the command-line:

./test_single_stratimikos_solver_driver.exe --echo-command-line --help 

Usage: ./test_single_stratimikos_solver_driver.exe [options]
  options:
  --help                         Prints this help message
  --pause-for-debugging          Pauses for user input to allow attaching a debugger
  --echo-command-line            Echo the command-line but continue as normal
  --input-file           string  Input file [Required].
                                 (default: --input-file="")
  --extra-params         string  Extra parameters overriding the parameters read in from --input-file
                                 (default: --extra-params="")

DETAILED DOCUMENTATION:

Testing program for Trilinos (and non-Trilinos) linear solvers access through Thyra.

Teuchos::GlobalMPISession::GlobalMPISession(): started serial run

Sample output looks like:

Echoing the command-line:

./test_single_stratimikos_solver_driver.exe --echo-command-line --input-file=FourByFour.belos.ifpack.xml 

Teuchos::GlobalMPISession::GlobalMPISession(): started serial run

Reading parameters from XML file "FourByFour.belos.ifpack.xml" ...

Echoing input parameters ...
 Matrix File : string = FourByFour.mtx
 Linear Solver Builder -> 
   Linear Solver Type : string = Belos
   Preconditioner Type : string = Ifpack
 LinearOpTester -> 
   [empty list]
 LinearOpWithSolveTester -> 
   [empty list]

Validating top-level input parameters ...

Reading in an epetra matrix A from the file 'FourByFour.mtx' ...

Creating a Thyra::DefaultRealLinearSolverBuilder object ...

Valid parameters for DefaultRealLinearSolverBuilder ...
 Linear Solver Type : string = Amesos
 Preconditioner Type : string = ML
 Linear Solver Types -> 
   Amesos -> 
     Refactorization Policy : string = RepivotOnRefactorization
     Solver Type : string = Klu
     Throw on Preconditioner Input : bool = 1
     Amesos Settings -> 
       AddToDiag : double = 0
       AddZeroToDiag : bool = 0
       ComputeTrueResidual : bool = 0
       ComputeVectorNorms : bool = 0
       DebugLevel : int = 0
       MatrixProperty : string = general
       MaxProcs : int = -1
       NoDestroy : bool = 0
       OutputLevel : int = 1
       PrintTiming : bool = 0
       RcondThreshold : double = 1e-12
       Redistribute : bool = 0
       Refactorize : bool = 0
       Reindex : int = 0
       ScaleMethod : int = 0
       TrustMe : bool = 0
       Lapack -> 
         [empty list]
       Mumps -> 
         [empty list]
       Pardiso -> 
         [empty list]
       Scalapack -> 
         [empty list]
       Superludist -> 
         [empty list]
   AztecOO -> 
     Output Every RHS : bool = 0
     Adjoint Solve -> 
       Max Iterations : int = 400
       Tolerance : double = 1e-06
       AztecOO Settings -> 
         Aztec Preconditioner : string = ilu
         Aztec Solver : string = GMRES
         Convergence Test : string = r0
         Drop Tolerance : double = 0
         Fill Factor : double = 1
         Graph Fill : int = 0
         Ill-Conditioning Threshold : double = 1e+11
         Orthogonalization : string = Classical
         Output Frequency : int = 0
         Overlap : int = 0
         Polynomial Order : int = 3
         RCM Reordering : string = Disabled
         Size of Krylov Subspace : int = 300
         Steps : int = 3
     Forward Solve -> 
       Max Iterations : int = 400
       Tolerance : double = 1e-06
       AztecOO Settings -> 
         Aztec Preconditioner : string = ilu
         Aztec Solver : string = GMRES
         Convergence Test : string = r0
         Drop Tolerance : double = 0
         Fill Factor : double = 1
         Graph Fill : int = 0
         Ill-Conditioning Threshold : double = 1e+11
         Orthogonalization : string = Classical
         Output Frequency : int = 0
         Overlap : int = 0
         Polynomial Order : int = 3
         RCM Reordering : string = Disabled
         Size of Krylov Subspace : int = 300
         Steps : int = 3
 Preconditioner Types -> 
   Ifpack -> 
     Overlap : int = 0
     Prec Type : string = ILU
     Ifpack Settings -> 
       amesos: solver type : string = Amesos_Klu
       fact: absolute threshold : double = 0
       fact: drop tolerance : double = 0
       fact: ict level-of-fill : double = 1
       fact: ilut level-of-fill : double = 1
       fact: level-of-fill : int = 0
       fact: relative threshold : double = 1
       fact: relax value : double = 0
       fact: sparskit: alph : double = 0
       fact: sparskit: droptol : double = 0
       fact: sparskit: lfil : int = 0
       fact: sparskit: mbloc : int = -1
       fact: sparskit: permtol : double = 0.1
       fact: sparskit: tol : double = 0
       fact: sparskit: type : string = ILUT
       partitioner: local parts : int = 1
       partitioner: overlap : int = 0
       partitioner: print level : int = 0
       partitioner: type : string = greedy
       partitioner: use symmetric graph : bool = 1
       relaxation: damping factor : double = 1
       relaxation: min diagonal value : double = 1
       relaxation: sweeps : int = 1
       relaxation: typ*** Caught standard exception : /home/rabartl/PROJECTS/Trilinos.release-7-0-branch/Trilinos/packages/stratimikos/src/Thyra_DefaultRealLinearSolverBuilder.cpp:277: itr == lowsf_map_.end(): Error, the value "Linear Solver Type"="Belos" is not a valid linear solver type.  Valid linear solve strategy names include {"AztecOO","Amesos"}!
e : string = Jacobi
       relaxation: zero starting solution : bool = 1
       schwarz: combine mode : string = Zero
       schwarz: compute condest : bool = 1
       schwarz: filter singletons : bool = 0
       schwarz: reordering type : string = none
   ML -> 
     PDE equations : int = 1
     aggregation: damping factor : double = 1.333
     aggregation: local aggregates : int = 128
     aggregation: threshold : double = 0
     aggregation: type : string = METIS
     coarse: max size : int = 128
     coarse: type : string = Amesos-KLU
     default values : string = DD
     increasing or decreasing : string = increasing
     max levels : int = 2
     output : int = 8
     prec type : string = MGV
     print unused : int = -2
     smoother: Aztec as solver : bool = 0
     smoother: Aztec options : int* = 0x8506c18
     smoother: Aztec params : double* = 0x8506cd8
     smoother: damping factor : double = 0.67
     smoother: pre or post : string = both
     smoother: sweeps : int = 2
     smoother: type : string = Aztec

Creating the LinearOpWithSolveFactoryBase object lowsFactory ...

Oh no! At least one of the tests failed!

Here is the main driver itself:

// @HEADER
// ***********************************************************************
// 
//         Stratimikos: Thyra-based strategies for linear solvers
//                Copyright (2006) Sandia Corporation
// 
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
// 
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//  
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//  
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
// Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
// 
// ***********************************************************************
// @HEADER

#include "test_single_stratimikos_solver.hpp"
#include "Thyra_DefaultRealLinearSolverBuilder.hpp"
#include "Thyra_EpetraLinearOp.hpp"
#include "Thyra_LinearOpWithSolveFactoryExamples.hpp"
#include "EpetraExt_readEpetraLinearSystem.h"
#include "Teuchos_ParameterList.hpp"

#ifdef HAVE_MPI
#  include "Epetra_MpiComm.h"
#else
#  include "Epetra_SerialComm.h"
#endif

bool Thyra::test_single_stratimikos_solver(
  Teuchos::ParameterList                  *paramList_inout
  ,const bool                             dumpAll
  ,Teuchos::FancyOStream                  *out
  )
{

  using Teuchos::rcp;
  using Teuchos::RefCountPtr;
  using Teuchos::OSTab;
  using Teuchos::ParameterList;
  using Teuchos::getParameter;
  bool success = true;

  try {

    TEST_FOR_EXCEPT(!paramList_inout);

    RefCountPtr<ParameterList>
      paramList = rcp(paramList_inout,false);

    if(out) {
      *out << "\nEchoing input parameters ...\n";
      paramList->print(*out,1,true,false);
    }

    // Create list of valid parameter sublists
    Teuchos::ParameterList validParamList("test_single_stratimikos_solver");
    validParamList.set("Matrix File","fileName");
    validParamList.sublist("Linear Solver Builder");
    validParamList.sublist("LinearOpTester");
    validParamList.sublist("LinearOpWithSolveTester");
    
    if(out) *out << "\nValidating top-level input parameters ...\n";
    paramList->validateParameters(validParamList,0);

    const std::string
      &matrixFile = getParameter<std::string>(*paramList,"Matrix File");
    RefCountPtr<ParameterList>
      solverBuilderSL  = sublist(paramList,"Linear Solver Builder",true),
      loTesterSL       = sublist(paramList,"LinearOpTester",true),
      lowsTesterSL     = sublist(paramList,"LinearOpWithSolveTester",true);

    if(out) *out << "\nReading in an epetra matrix A from the file \'"<<matrixFile<<"\' ...\n";
  
#ifdef HAVE_MPI
    Epetra_MpiComm comm(MPI_COMM_WORLD);
#else
    Epetra_SerialComm comm;
#endif
    Teuchos::RefCountPtr<Epetra_CrsMatrix> epetra_A;
    EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );

    Teuchos::RefCountPtr<LinearOpBase<double> >
      A = Teuchos::rcp(new EpetraLinearOp(epetra_A));

    if(out) *out << "\nCreating a Thyra::DefaultRealLinearSolverBuilder object ...\n";
    
    RefCountPtr<Thyra::LinearSolverBuilderBase<double> >
      linearSolverBuilder = rcp(new Thyra::DefaultRealLinearSolverBuilder);

    if(out) {
      *out << "\nValid parameters for DefaultRealLinearSolverBuilder ...\n";
      linearSolverBuilder->getValidParameters()->print(*out,1,true,false);
    }

    linearSolverBuilder->setParameterList(solverBuilderSL);

    if(out) *out << "\nCreating the LinearOpWithSolveFactoryBase object lowsFactory ...\n";
    RefCountPtr<LinearOpWithSolveFactoryBase<double> >
      lowsFactory = linearSolverBuilder->createLinearSolveStrategy();
    if(out) *out << "\nlowsFactory described as:\n" << describe(*lowsFactory,Teuchos::VERB_MEDIUM) << std::endl;

    if(out) *out << "\nRunning example use cases ...\n";
    
    nonExternallyPreconditionedLinearSolveUseCases(
      *A,*lowsFactory,false,*out
      );
    
    // ToDo: Finish tests!

    if(out) {
      *out << "\nPrinting the parameter list (showing what was used) ...\n";
      paramList->print(*out,1,true,true);
    }
    
  }
  catch( const std::exception &excpt ) {
    std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
    success = false;
  }
  
  return success;
  
}

Generated on Thu Sep 18 12:37:39 2008 for Stratimikos by doxygen 1.3.9.1