Amesos Package Browser (Single Doxygen Collection) Development
TestKlu.cpp
Go to the documentation of this file.
00001 #include "Epetra_Comm.h"
00002 #include "Teuchos_ParameterList.hpp"
00003 #include "Amesos.h"
00004 #include "Epetra_CrsMatrix.h"
00005 #include "Epetra_Map.h"
00006 #include "Epetra_Vector.h"
00007 #include "Epetra_LinearProblem.h"
00008 #include "PerformOneSolveAndTest.h"
00009 #include "TestKlu.h"
00010 
00011 //
00012 //  Tests:
00013 //     1)  no parameters
00014 //     2)  Refactorize = true 
00015 //     2A)  AddToDiag = 1e-12
00016 #if 0
00017 //     3)  ScaleMethod = 1 - argh I don't see how ScaleMEthod can work
00018 //     4)  ComputeTrueResidual==true
00019 #endif
00020 //
00021 int TestKlu( Epetra_CrsMatrix *& Amat, 
00022        int EpetraMatrixType,
00023        const bool transpose, 
00024        const bool verbose, 
00025        const int Levels,
00026        const double Rcond,
00027        Teuchos::ParameterList ParamList,
00028        bool RowMapEqualsColMap, 
00029              bool TestAddZeroToDiag,
00030        int ExpectedError,
00031        double &maxrelerror, 
00032        double &maxrelresidual,
00033        int &NumTests ) {
00034   
00035   bool MyVerbose = false ; //  if set equal to verbose, we exceed thee test harness 1 Megabyte limit
00036 
00037   int NumErrors = 0 ;
00038   maxrelerror = 0.0;
00039   maxrelresidual = 0.0;
00040   const Epetra_Comm& Comm = Amat->Comm();
00041 
00042   //
00043   //     1)  no parameters
00044 
00045   {
00046     Teuchos::ParameterList InternalParamList = ParamList ; 
00047       
00048     double relerror;
00049     double relresidual;
00050       
00051     if ( MyVerbose ) std::cout  << __FILE__ << "::"  << __LINE__ 
00052       << " InternalParamList = " <<
00053          InternalParamList <<  std::endl ; 
00054       
00055     int Errors = PerformOneSolveAndTest("Amesos_Klu",
00056           EpetraMatrixType,
00057           Comm, 
00058           transpose, 
00059           MyVerbose,
00060           InternalParamList, 
00061           Amat, 
00062           Levels,
00063           Rcond, 
00064           relerror, 
00065           relresidual,
00066           ExpectedError ) ;
00067 
00068       
00069     if ( Amat->Comm().MyPID() == 0 && Errors ) {
00070       std::cout << __FILE__ << "::"  << __LINE__ 
00071      << "Amesos_Klu failed with error code " << Errors<< std::endl ; 
00072       }
00073     if (Errors < 0 ) {
00074       NumErrors++;
00075       NumTests++ ; 
00076     } else { 
00077       NumErrors += Errors ; 
00078   
00079       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00080       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00081       NumTests++ ; 
00082 
00083     }
00084     if (MyVerbose)  std::cout << " TestKlu NumErrors = " 
00085            << NumErrors << " "
00086            << __FILE__ << "::" << __LINE__ 
00087            << std::endl ; 
00088     if ( Amat->Comm().MyPID() == 0 && Errors > 0 ) {
00089       std::cout << "Amesos_Klu" 
00090      << __FILE__ << "::"  << __LINE__ 
00091      << " Errors = " <<  Errors 
00092      << " failed with transpose = " << 
00093   (transpose?"true":"false") << std::endl ;  
00094     }
00095   }
00096 
00097   //
00098   //     2)  Refactorize = true 
00099   {
00100     Teuchos::ParameterList InternalParamList = ParamList ; 
00101 
00102     InternalParamList.set( "Refactorize", true );
00103       
00104     double relerror;
00105     double relresidual;
00106     if ( MyVerbose ) std::cout  << __FILE__ << "::"  << __LINE__ 
00107        << " InternalParamList = " <<
00108          InternalParamList <<  std::endl ; 
00109       
00110     int Errors = PerformOneSolveAndTest("Amesos_Klu",
00111           EpetraMatrixType,
00112           Comm, 
00113           transpose, 
00114           MyVerbose,
00115           InternalParamList, 
00116           Amat, 
00117           Levels,
00118           Rcond, 
00119           relerror, 
00120           relresidual,
00121           ExpectedError ) ;
00122       
00123     if (  Amat->Comm().MyPID() == 0 && Errors ) {
00124       std::cout << __FILE__ << "::"  << __LINE__ 
00125      << "Amesos_Klu failed with error code " << Errors<< std::endl ; 
00126       }
00127     if ( Errors < 0 ) {
00128       NumErrors++;
00129       NumTests++ ; 
00130     } else { 
00131       NumErrors += Errors ; 
00132   
00133       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00134       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00135       NumTests++ ; 
00136 
00137     }
00138     if (MyVerbose)  std::cout << " TestKlu NumErrors = " 
00139            << NumErrors << " "
00140            << __FILE__ << "::" << __LINE__ 
00141            << std::endl ; 
00142     if (  Amat->Comm().MyPID() == 0 && Errors > 0 ) {
00143       std::cout << "Amesos_Klu" 
00144      << __FILE__ << "::"  << __LINE__ 
00145      << " Errors = " <<  Errors 
00146      << " failed with transpose = " << 
00147   (transpose?"true":"false") << std::endl ;  
00148     }
00149   }
00150   //
00151   //     2a) TrustMe = true 
00152   //         Note:  Requires Optimized Storage (i.e. EpetraMatrixType == 2 ) 
00153   //                and does not support reindexing
00154   bool ReIndex = ParamList.get( "Reindex", false );
00155   bool DontTrustMe = ParamList.get( "DontTrustMe", false );
00156   if ( EpetraMatrixType == 2 && ! ReIndex && ! DontTrustMe ) {
00157     Teuchos::ParameterList InternalParamList = ParamList ; 
00158 
00159     InternalParamList.set( "TrustMe", true );
00160 
00161     if ( MyVerbose ) std::cout  << __FILE__ << "::"  << __LINE__ 
00162       << " InternalParamList = " <<
00163          InternalParamList <<  std::endl ; 
00164       
00165     double relerror;
00166     double relresidual;
00167       
00168     int Errors = PerformOneSolveAndTest("Amesos_Klu",
00169           EpetraMatrixType,
00170           Comm, 
00171           transpose, 
00172           MyVerbose,
00173           InternalParamList, 
00174           Amat, 
00175           Levels,
00176           Rcond, 
00177           relerror, 
00178           relresidual,
00179           ExpectedError ) ;
00180  
00181       
00182     if (  Amat->Comm().MyPID() == 0 && Errors ) {
00183       std::cout << __FILE__ << "::"  << __LINE__ 
00184      << "Amesos_Klu failed with error code " << Errors<< std::endl ; 
00185       }
00186     if ( Errors < 0 ) {
00187       NumErrors++;
00188       NumTests++ ; 
00189     } else { 
00190       NumErrors += Errors ; 
00191   
00192       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00193       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00194       NumTests++ ; 
00195 
00196     }
00197     if (MyVerbose)  std::cout << " TestKlu NumErrors = " 
00198            << NumErrors << " "
00199            << __FILE__ << "::" << __LINE__ 
00200            << std::endl ; 
00201     if (  Amat->Comm().MyPID() == 0 && Errors > 0 ) {
00202       std::cout << "Amesos_Klu" 
00203      << __FILE__ << "::"  << __LINE__ 
00204      << " Errors = " <<  Errors 
00205      << " failed with transpose = " << 
00206   (transpose?"true":"false") << std::endl ;  
00207     }
00208   }
00209   
00210 
00211   if ( ExpectedError == 0 ) {
00212     //
00213     //     2A)  AddToDiag 
00214     if (RowMapEqualsColMap ) {
00215       Teuchos::ParameterList InternalParamList = ParamList ; 
00216       InternalParamList.set( "Refactorize", true );
00217       //    InternalParamList.set( "AddZeroToDiag", true );
00218       InternalParamList.set( "AddToDiag", 1e2 );
00219       
00220       double relerror;
00221       double relresidual;
00222       
00223       if ( MyVerbose ) std::cout  << __FILE__ << "::"  << __LINE__ 
00224            << " InternalParamList = " <<
00225        InternalParamList <<  std::endl ; 
00226       
00227       int Errors = PerformOneSolveAndTest("Amesos_Klu",
00228             EpetraMatrixType,
00229             Comm, 
00230             transpose, 
00231             MyVerbose,
00232             InternalParamList, 
00233             Amat, 
00234             Levels,
00235             Rcond, 
00236             relerror, 
00237             relresidual,
00238             ExpectedError ) ;
00239       
00240       
00241       if (  Amat->Comm().MyPID() == 0 && Errors ) {
00242   std::cout << __FILE__ << "::"  << __LINE__ 
00243        << "Amesos_Klu failed with error code " << Errors<< std::endl ; 
00244       }
00245       if ( Errors < 0 ) {
00246   NumErrors++;
00247   NumTests++ ; 
00248       } else {
00249   NumErrors += Errors ; 
00250   
00251   maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00252   maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00253   NumTests++ ; 
00254   
00255       }
00256       if (MyVerbose)  std::cout << " TestKlu NumErrors = " 
00257          << NumErrors << " "
00258          << __FILE__ << "::" << __LINE__ 
00259          << std::endl ; 
00260       if ( Comm.MyPID() == 0 && Errors > 0 ) {
00261   std::cout << "Amesos_Klu" 
00262        << __FILE__ << "::"  << __LINE__ 
00263        << " Errors = " <<  Errors 
00264        << " failed with transpose = " << 
00265     (transpose?"true":"false") << std::endl ;  
00266       }
00267     }
00268 
00269     //
00270     //     2B)  AddToDiag with AddZeroToDiag
00271     if (RowMapEqualsColMap && TestAddZeroToDiag ) {
00272       Teuchos::ParameterList InternalParamList = ParamList ; 
00273       InternalParamList.set( "Refactorize", true );
00274       InternalParamList.set( "AddZeroToDiag", true );
00275       InternalParamList.set( "AddToDiag", 1e2 );
00276       
00277       double relerror;
00278       double relresidual;
00279       
00280       if ( MyVerbose ) std::cout  << __FILE__ << "::"  << __LINE__ 
00281            << " InternalParamList = " <<
00282        InternalParamList <<  std::endl ; 
00283       
00284       int Errors = PerformOneSolveAndTest("Amesos_Klu",
00285             EpetraMatrixType,
00286             Comm, 
00287             transpose, 
00288             MyVerbose,
00289             InternalParamList, 
00290             Amat, 
00291             Levels,
00292             Rcond, 
00293             relerror, 
00294             relresidual,
00295             ExpectedError ) ;
00296       
00297       if (  Amat->Comm().MyPID() == 0 && Errors ) {
00298   std::cout << __FILE__ << "::"  << __LINE__ 
00299        << "Amesos_Klu failed with error code " << Errors<< std::endl ; 
00300       }
00301       if ( Errors < 0 ) {
00302   NumErrors++;
00303   NumTests++ ; 
00304       } else {
00305   NumErrors += Errors ; 
00306   
00307   maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00308   maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00309   NumTests++ ; 
00310   
00311       }
00312       if (MyVerbose)  std::cout << " TestKlu NumErrors = " 
00313          << NumErrors << " "
00314          << __FILE__ << "::" << __LINE__ 
00315          << std::endl ; 
00316       if ( Comm.MyPID() == 0 && Errors > 0 ) {
00317   std::cout << "Amesos_Klu" 
00318        << __FILE__ << "::"  << __LINE__ 
00319        << " Errors = " <<  Errors 
00320        << " failed with transpose = " << 
00321     (transpose?"true":"false") << std::endl ;  
00322       }
00323     }
00324     
00325     //
00326     //     2C)   AddZeroToDiag without AddToDiag 
00327     if (RowMapEqualsColMap  ) {
00328       Teuchos::ParameterList InternalParamList = ParamList ; 
00329       InternalParamList.set( "Refactorize", true );
00330       InternalParamList.set( "AddZeroToDiag", true );
00331 
00332       double relerror;
00333       double relresidual;
00334       
00335       if ( MyVerbose ) std::cout  << __FILE__ << "::"  << __LINE__ 
00336            << " InternalParamList = " <<
00337        InternalParamList <<  std::endl ; 
00338       
00339       int Errors = PerformOneSolveAndTest("Amesos_Klu",
00340             EpetraMatrixType,
00341             Comm, 
00342             transpose, 
00343             MyVerbose,
00344             InternalParamList, 
00345             Amat, 
00346             Levels,
00347             Rcond, 
00348             relerror, 
00349             relresidual,
00350             ExpectedError ) ;
00351       
00352       if (  Amat->Comm().MyPID() == 0 && Errors ) {
00353   std::cout << __FILE__ << "::"  << __LINE__ 
00354        << "Amesos_Klu failed with error code " << Errors<< std::endl ; 
00355       }
00356       if ( Errors < 0 ) {
00357   NumErrors++;
00358   NumTests++ ; 
00359       } else {
00360   NumErrors += Errors ; 
00361   
00362   maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00363   maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00364   NumTests++ ; 
00365   
00366       }
00367       if (MyVerbose)  std::cout << " TestKlu NumErrors = " 
00368          << NumErrors << " "
00369          << __FILE__ << "::" << __LINE__ 
00370          << std::endl ; 
00371       if ( Comm.MyPID() == 0 && Errors > 0 ) {
00372   std::cout << "Amesos_Klu" 
00373        << __FILE__ << "::"  << __LINE__ 
00374        << " Errors = " <<  Errors 
00375        << " failed with transpose = " << 
00376     (transpose?"true":"false") << std::endl ;  
00377       }
00378     }
00379     
00380 #if 0
00381   //
00382   //     3)  ScaleMethod = 1 - argh I don't see how ScaleMEthod can work
00383   {
00384     double relerror;
00385     double relresidual;
00386       
00387     int Errors = PerformOneSolveAndTest("Amesos_Klu",
00388           Comm, 
00389           transpose, 
00390           MyVerbose,
00391           InternalParamList, 
00392           Amat, 
00393           Levels,
00394           Rcond, 
00395           relerror, 
00396           relresidual,
00397           ExpectedError ) ;
00398  
00399       
00400     if (Errors < 0 ) {
00401       if (MyVerbose ) std::cout << "Amesos_Klu" << " not built in this executable " << std::endl ; 
00402       return 0 ; 
00403     } else { 
00404       NumErrors += Errors ; 
00405   
00406       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00407       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00408       NumTests++ ; 
00409 
00410     }
00411     if (MyVerbose)  std::cout << " TestKlu NumErrors = " 
00412            << NumErrors << " "
00413            << __FILE__ << "::" << __LINE__ 
00414            << std::endl ; 
00415     if ( MyVerbose && Errors > 0 ) {
00416       std::cout << "Amesos_Klu" << " failed with transpose = " << 
00417   (transpose?"true":"false") << std::endl ;  
00418     }
00419   }
00420 #endif
00421 #if 0
00422 
00423   //  This fails on Stratus  - see bug #1420 - now marked as a duplicate of bug 1417
00424 
00425   //
00426   //     4)  ComputeTrueResidual==true
00427   {
00428     ParamList.set( "ComputeTrueResidual", true );
00429     //    Teuchos::ParameterList& KluParams = ParamList.sublist("Klu") ;
00430     //    KluParams.set( "grid_mb", 3 );
00431 
00432     double relerror;
00433     double relresidual;
00434       
00435     int Errors = PerformOneSolveAndTest("Amesos_Klu",
00436           EpetraMatrixType,
00437           Comm, 
00438           transpose, 
00439           MyVerbose,
00440           ParamList, 
00441           Amat, 
00442           Levels,
00443           Rcond, 
00444           relerror, 
00445           relresidual,
00446           ExpectedError ) ;
00447 
00448       
00449     if (Errors < 0 ) {
00450       if (MyVerbose ) std::cout << "Amesos_Klu" << " not built in this executable " << std::endl ; 
00451       return 0 ; 
00452     } else { 
00453       NumErrors += Errors ; 
00454   
00455       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00456       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00457       NumTests++ ; 
00458 
00459     }
00460     if (MyVerbose)  std::cout << " TestKlu NumErrors = " << NumErrors 
00461            << " " << __FILE__ << "::" << __LINE__ << std::endl ; 
00462     if ( MyVerbose && Errors > 0 ) {
00463       std::cout << "Amesos_Klu" << " failed with transpose = " << 
00464   (transpose?"true":"false") << std::endl ;  
00465     }
00466   }
00467 #endif
00468   }
00469     return NumErrors; 
00470 }
00471 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines