Amesos Package Browser (Single Doxygen Collection) Development
TestOtherClasses.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 "TestOtherClasses.h"
00009 #include "PerformOneSolveAndTest.h"
00010 
00011 int TestOtherClasses( const char* AmesosClass,
00012           int EpetraMatrixType,
00013           Epetra_CrsMatrix *& Amat, 
00014           const bool transpose, 
00015           const bool verbose, 
00016           const int Levels,
00017           const double Rcond,
00018           bool RowMapEqualsColMap, 
00019           bool TestAddZeroToDiag,
00020           int ExpectedError,
00021           double &maxrelerror, 
00022           double &maxrelresidual,
00023           int &NumTests ) {
00024 
00025 
00026   int iam = Amat->Comm().MyPID() ;  
00027   int NumErrors = 0 ;
00028   maxrelerror = 0.0;
00029   maxrelresidual = 0.0;
00030   const Epetra_Comm& Comm = Amat->Comm();
00031 
00032   bool MyVerbose = false ; // if set equal to verbose, we exceed the test harness 1 Megabyte limit
00033   std::string StringAmesosClass = AmesosClass ; 
00034   if ( AmesosClass ) MyVerbose = verbose ;    // Turn this on temporarily to debug Mumps on atlantis
00035   {
00036     Teuchos::ParameterList ParamList ;
00037 
00038     ParamList.set( "NoDestroy", true );    // Only affects Amesos_Mumps
00039     ParamList.set( "Redistribute", true );
00040     ParamList.set( "AddZeroToDiag", false );
00041     ParamList.set( "MaxProcs", 100000 );
00042     //  ParamList.print( std::cerr, 10 ) ; 
00043 
00044     double relerror;
00045     double relresidual;
00046    
00047     if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass 
00048           << " ParamList = " << ParamList 
00049           << " transpose = " << transpose 
00050           << " Levels = " << Levels 
00051           << std::endl ; 
00052 
00053     int Errors = PerformOneSolveAndTest(AmesosClass,
00054           EpetraMatrixType,
00055           Comm, 
00056           transpose, 
00057           MyVerbose,
00058           ParamList, 
00059           Amat, 
00060           Levels,
00061           Rcond, 
00062           relerror, 
00063           relresidual, ExpectedError ) ; 
00064 
00065     if (MyVerbose  || ( Errors && iam==0 )  ) std::cout << __FILE__ << "::" << __LINE__ 
00066           << " AmesosClass= " << AmesosClass 
00067           << " Errors = " << Errors 
00068           << std::endl ; 
00069 
00070     if ( Errors < 0 ) {
00071       NumErrors++;
00072       NumTests++ ; 
00073       if ( MyVerbose ) {
00074   std::cout << AmesosClass << " failed with error code " << Errors << " " << __FILE__ << "::" << __LINE__ << std::endl ; 
00075       }
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 << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ; 
00085     if ( MyVerbose && Errors ) {
00086       std::cout << AmesosClass << " failed with transpose = " << 
00087   (transpose?"true":"false") << std::endl ;  
00088     }
00089   }
00090 
00091   std::string AC = AmesosClass ; 
00092 
00093   bool taucs = ( AC ==  "Amesos_Taucs" );
00094   bool klu = ( AC ==  "Amesos_Klu" );
00095   bool paraklete = ( AC ==  "Amesos_Paraklete" );
00096   bool mumps = ( AC ==  "Amesos_Mumps" );
00097   bool scalapack = ( AC ==  "Amesos_Scalapack" ) ;
00098   bool lapack = ( AC ==  "Amesos_Lapack" );
00099 
00100 
00101   //
00102   //  Testing AddZeroToDiag and AddToDiag 
00103   //  When AddZeroToDiag is true, the value of AddToDiag is added to every diagonal element whether or not 
00104   //    that element exists in the structure of the matrix.
00105   //  When AddZeroToDiag is false, the value of AddToDiag is added only to those diagonal elements 
00106   //    which are structually non-zero.
00107   //  Support for these two flags varies
00108   //
00109   //
00110   //  klu, superludist and parakalete support AddToDiag with or without AddZeroToDiag 
00111   //  scalapack and lapack, being dense codes, support AddToDiag, but only when AddZeroToDiag is set 
00112   //
00113   //  pardiso does not support AddToDiag - bug #1993 
00114   bool supports_AddToDiag_with_AddZeroToDiag = ( klu || paraklete || scalapack || lapack ) ; 
00115   bool supports_AddToDiag_with_when_AddZeroTo_Diag_is_false = ( klu  || paraklete  || mumps || taucs || lapack ) ; 
00116 
00117 
00118   if ( RowMapEqualsColMap && supports_AddToDiag_with_AddZeroToDiag && TestAddZeroToDiag ) {
00119     Teuchos::ParameterList ParamList ;
00120     ParamList.set( "NoDestroy", true );    // Only affects Amesos_Mumps
00121     ParamList.set( "Redistribute", false );
00122     ParamList.set( "AddZeroToDiag", true );
00123     ParamList.set( "AddToDiag", 1.3e2 );
00124 
00125     //  ParamList.print( std::cerr, 10 ) ; 
00126 
00127     double relerror;
00128     double relresidual;
00129    
00130     if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass 
00131           << " ParamList = " << ParamList 
00132           << " transpose = " << transpose 
00133           << " Levels = " << Levels 
00134           << std::endl ; 
00135 
00136     int Errors = PerformOneSolveAndTest(AmesosClass,
00137           EpetraMatrixType,
00138           Comm, 
00139           transpose, 
00140           MyVerbose,
00141           ParamList, 
00142           Amat, 
00143           Levels,
00144           Rcond, 
00145           relerror, 
00146           relresidual, ExpectedError ) ; 
00147 
00148 
00149     if (MyVerbose  || ( Errors && iam==0 )  ) std::cout << __FILE__ << "::" << __LINE__ 
00150           << " AmesosClass= " << AmesosClass 
00151           << " Errors = " << Errors 
00152           << std::endl ; 
00153 
00154     if ( Errors < 0 ) {
00155       NumErrors++;
00156       NumTests++ ; 
00157       if ( MyVerbose ) {
00158   std::cout  << __FILE__ << "::" << __LINE__ 
00159     << AmesosClass << " failed with error code " << Errors << " " << __FILE__ << "::" << __LINE__ << std::endl ; 
00160       }
00161     } else { 
00162       NumErrors += Errors ; 
00163 
00164       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00165       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00166       NumTests++ ; 
00167 
00168     }
00169     if (MyVerbose)  std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ; 
00170     if ( MyVerbose && Errors ) {
00171       std::cout << AmesosClass << " failed with transpose = " << 
00172   (transpose?"true":"false") << std::endl ;  
00173     }
00174 
00175 
00176 
00177   }
00178   if ( RowMapEqualsColMap && supports_AddToDiag_with_when_AddZeroTo_Diag_is_false ) {
00179     Teuchos::ParameterList ParamList ;
00180     ParamList.set( "NoDestroy", true );    // Only affects Amesos_Mumps
00181     ParamList.set( "Redistribute", false );
00182     ParamList.set( "AddToDiag", 1e2 );
00183 
00184     //  ParamList.print( std::cerr, 10 ) ; 
00185 
00186     double relerror;
00187     double relresidual;
00188    
00189     if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass 
00190           << " ParamList = " << ParamList 
00191           << " transpose = " << transpose 
00192           << " Levels = " << Levels 
00193           << std::endl ; 
00194 
00195     int Errors = PerformOneSolveAndTest(AmesosClass,
00196           EpetraMatrixType,
00197           Comm, 
00198           transpose, 
00199           MyVerbose,
00200           ParamList, 
00201           Amat, 
00202           Levels,
00203           Rcond, 
00204           relerror, 
00205           relresidual, ExpectedError ) ; 
00206 
00207 
00208     if (MyVerbose  || ( Errors && iam==0 )  ) std::cout << __FILE__ << "::" << __LINE__ 
00209           << " AmesosClass= " << AmesosClass 
00210           << " Errors = " << Errors 
00211           << std::endl ; 
00212 
00213     if ( Errors < 0 ) {
00214       NumErrors++;
00215       NumTests++ ; 
00216       if ( MyVerbose ) {
00217   std::cout  << __FILE__ << "::" << __LINE__ 
00218     << AmesosClass << " failed with error code " << Errors << " " << __FILE__ << "::" << __LINE__ << std::endl ; 
00219       }
00220     } else { 
00221       NumErrors += Errors ; 
00222 
00223       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00224       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00225       NumTests++ ; 
00226 
00227     }
00228     if (MyVerbose)  std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ; 
00229     if ( MyVerbose && Errors ) {
00230       std::cout << AmesosClass << " failed with transpose = " << 
00231   (transpose?"true":"false") << std::endl ;  
00232     }
00233 
00234 
00235 
00236   }
00237 
00238   //
00239   //     2)  Refactorize = true 
00240   {
00241     Teuchos::ParameterList ParamList ;
00242     ParamList.set( "NoDestroy", true );    // Only affects Amesos_Mumps
00243     ParamList.set( "Refactorize", true );
00244       
00245     double relerror;
00246     double relresidual;
00247       
00248     if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass 
00249           << " ParamList = " << ParamList 
00250           << " transpose = " << transpose 
00251           << " Levels = " << Levels 
00252           << std::endl ; 
00253 
00254     int Errors = PerformOneSolveAndTest(AmesosClass,
00255           EpetraMatrixType,
00256           Comm, 
00257           transpose, 
00258           MyVerbose,
00259           ParamList, 
00260           Amat, 
00261           Levels,
00262           Rcond, 
00263           relerror, 
00264           relresidual, ExpectedError ) ; 
00265       
00266     if (MyVerbose  || ( Errors && iam==0 )  ) std::cout << __FILE__ << "::" << __LINE__ 
00267           << " AmesosClass= " << AmesosClass 
00268           << " Errors = " << Errors 
00269           << std::endl ; 
00270 
00271     if (Errors < 0 ) {
00272       if (MyVerbose ) std::cout << AmesosClass << " not built in this executable " << std::endl ; 
00273       return 0 ; 
00274     } else { 
00275       NumErrors += Errors ; 
00276   
00277       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00278       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00279       NumTests++ ; 
00280 
00281     }
00282     if (MyVerbose)  std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ; 
00283     if ( MyVerbose && Errors ) {
00284       std::cout << AmesosClass << " failed with transpose = " << 
00285   (transpose?"true":"false") << std::endl ;  
00286     }
00287   }
00288 
00289   //
00290   //     5)  MaxProcs = 2 
00291   {
00292     Teuchos::ParameterList ParamList ;
00293     ParamList.set( "NoDestroy", true );    // Only affects Amesos_Mumps
00294     ParamList.set( "MaxProcs", 2 );   // Only affects Paraklete (maybe Mumps) also Superludist byt that isn't tested here 
00295       
00296     double relerror;
00297     double relresidual;
00298       
00299     if (MyVerbose) std::cout << __FILE__ << "::" << __LINE__ << " AmesosClass= " << AmesosClass 
00300           << " ParamList = " << ParamList 
00301           << " transpose = " << transpose 
00302           << " Levels = " << Levels 
00303           << std::endl ; 
00304 
00305     int Errors = PerformOneSolveAndTest(AmesosClass,
00306           EpetraMatrixType,
00307           Comm, 
00308           transpose, 
00309           MyVerbose,
00310           ParamList, 
00311           Amat, 
00312           Levels,
00313           Rcond, 
00314           relerror, 
00315           relresidual, ExpectedError ) ; 
00316       
00317     if (MyVerbose  || ( Errors && iam==0 )  ) std::cout << __FILE__ << "::" << __LINE__ 
00318           << " AmesosClass= " << AmesosClass 
00319           << " Errors = " << Errors 
00320           << std::endl ; 
00321 
00322     if (Errors < 0 ) {
00323       if (MyVerbose ) std::cout << AmesosClass << " not built in this executable " << std::endl ; 
00324       return 0 ; 
00325     } else { 
00326       NumErrors += Errors ; 
00327   
00328       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00329       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00330       NumTests++ ; 
00331 
00332     }
00333     if (MyVerbose)  std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ; 
00334     if ( MyVerbose && Errors ) {
00335       std::cout << AmesosClass << " failed with transpose = " << 
00336   (transpose?"true":"false") << std::endl ;  
00337     }
00338   }
00339   //
00340   //  ComputeTrueResidual is, by design, not quiet - it prints out the residual 
00341   //
00342 #if 0
00343   //
00344   //     4)  ComputeTrueResidual==true
00345   {
00346     Teuchos::ParameterList ParamList ;
00347     ParamList.set( "NoDestroy", true );    // Only affects Amesos_Mumps
00348     ParamList.set( "ComputeTrueResidual", true );
00349       
00350     double relerror;
00351     double relresidual;
00352       
00353     int Errors = PerformOneSolveAndTest(AmesosClass,
00354           EpetraMatrixType,
00355           Comm, 
00356           transpose, 
00357           MyVerbose,
00358           ParamList, 
00359           Amat, 
00360           Levels,
00361           Rcond, 
00362           relerror, 
00363           relresidual, ExpectedError ) ;
00364 
00365     if (Errors < 0 ) {
00366       if (MyVerbose ) std::cout << AmesosClass << " not built in this executable " << std::endl ; 
00367       return 0 ; 
00368     } else { 
00369       NumErrors += Errors ; 
00370   
00371       maxrelerror = EPETRA_MAX( relerror, maxrelerror ) ; 
00372       maxrelresidual = EPETRA_MAX( relresidual, maxrelresidual ) ; 
00373       NumTests++ ; 
00374 
00375     }
00376     if (MyVerbose)  std::cout << " TestOtherClasses " << AmesosClass << "" << "::" << __LINE__ << " NumErrors = " << NumErrors << std::endl ; 
00377     if ( MyVerbose && Errors > 0 ) {
00378       std::cout << AmesosClass << " failed with transpose = " << 
00379   (transpose?"true":"false") << std::endl ;  
00380     }
00381   }
00382 #endif
00383 
00384 
00385   return NumErrors; 
00386   }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines