38 #include "Trilinos_Util.h"
39 #include "Trilinos_Util_ReadMatrixMarket2Epetra.h"
49 #ifdef HAVE_AMESOS_UMFPACK
65 #ifdef HAVE_VALGRIND_H
66 #include <valgrind/valgrind.h>
69 #ifdef HAVE_VALGRIND_VALGRIND_H
70 #include <valgrind/valgrind.h>
83 const bool transpose,
const bool distribute,
95 FILE *in_file = fopen( in_filename,
"r");
99 filename = &in_filename[1] ;
102 filename = in_filename ;
107 std::string FileName (filename);
109 int FN_Size = FileName.size() ;
110 std::string LastFiveBytes = FileName.substr(
EPETRA_MAX(0,FN_Size-5), FN_Size );
111 std::string LastFourBytes = FileName.substr(
EPETRA_MAX(0,FN_Size-4), FN_Size );
113 if ( LastFiveBytes ==
".triU" ) {
115 EPETRA_CHK_ERR( Trilinos_Util_ReadTriples2Epetra( filename,
false, Comm, readMap, readA, readx,
116 readb, readxexact) );
119 if ( LastFiveBytes ==
".triS" ) {
121 EPETRA_CHK_ERR( Trilinos_Util_ReadTriples2Epetra( filename,
true, Comm, readMap, readA, readx,
122 readb, readxexact) );
125 if ( LastFourBytes ==
".mtx" ) {
126 EPETRA_CHK_ERR( Trilinos_Util_ReadMatrixMarket2Epetra( filename, Comm, readMap,
127 readA, readx, readb, readxexact) );
128 in_file = fopen( filename,
"r");
129 assert (in_file != NULL) ;
131 char buffer[BUFSIZE] ;
132 fgets( buffer, BUFSIZE, in_file ) ;
133 std::string headerline1 = buffer;
135 if ( headerline1.find(
"symmetric") < BUFSIZE ) symmetric =
true;
137 if ( headerline1.find(
"symmetric") != std::string::npos) symmetric =
true;
144 Trilinos_Util_ReadHb2Epetra( filename, Comm, readMap, readA, readx,
146 if ( LastFourBytes ==
".rsa" ) symmetric = true ;
152 if ( readb )
delete readb;
153 if ( readx )
delete readx;
154 if ( readxexact )
delete readxexact;
168 serialA = transposeA ;
175 assert( (
void *) &serialA->
Graph() ) ;
176 assert( (
void *) &serialA->
RowMap() ) ;
196 Amat->Export(*serialA, exporter,
Add);
224 int TestErrors(
const std::vector<bool> AmesosClassesInstalled,
225 const char *filename,
236 double residual = -13;
239 for (
int iterTrans =0 ; iterTrans < 2; iterTrans++ ) {
240 const bool transpose = iterTrans == 1 ;
242 const bool distribute = 1;
244 const int iterRowindex = 0;
245 const int iterColindex = 0 ;
246 const int iterRangemap = 0 ;
247 const int iterDomainmap = 0 ;
248 const int iterDiagonalOpts = 0 ;
249 bool printit = true ;
250 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
251 const int EpetraMatrixType = 0 ;
252 bool symmetric =
true;
253 const int iterDist = 0 ;
257 CreateCrsMatrix( filename, Comm, readMap, transpose, distribute, symmetric, Amat ) ;
259 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ <<
260 " Creating matrix from " <<
261 " filename = " << filename <<
262 " symmetric = " << symmetric <<
263 " distribute = " << distribute <<
264 " iterRowindex = " << iterRowindex <<
265 " iterColindex = " << iterColindex <<
266 " iterRangemap = " << iterRangemap <<
267 " iterDomainmap = " << iterDomainmap <<
268 " EpetraMatrixType = " << EpetraMatrixType <<
269 " iterDiagonalOpts = " << iterDiagonalOpts <<
270 " transpose = " << transpose
271 <<
" iterDist = " << iterDist << std::endl ;
273 if ( iterDiagonalOpts ) Comm.SetTracebackMode(1);
275 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
284 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
285 Comm.SetTracebackMode(2);
287 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ <<
288 " filename = " << filename <<
289 " symmetric = " << symmetric <<
290 " distribute = " << distribute <<
291 " iterRowindex = " << iterRowindex <<
292 " iterColindex = " << iterColindex <<
293 " iterRangemap = " << iterRangemap <<
294 " iterDomainmap = " << iterDomainmap <<
295 " EpetraMatrixType = " << EpetraMatrixType <<
296 " iterDiagonalOpts = " << iterDiagonalOpts <<
297 " transpose = " << transpose <<
" iterDist = " << iterDist << std::endl ;
306 const double MaxError = 1e-3;
308 int NumTheseTests = 0 ;
310 std::cout <<
" About to test " << filename
311 << __FILE__ <<
"::" << __LINE__
312 <<
" EpetraMatrixType = " << EpetraMatrixType
313 << (transpose?
" transpose":
"" )
314 << (distribute?
" distribute":
"" )
318 AmesosClassesInstalled,
335 NumTests += NumTheseTests ;
339 if ( Amat )
delete Amat ;
340 if ( readMap )
delete readMap ;
342 if ( verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
348 const char *filename,
356 const bool PerformDiagonalTest,
362 double residual = -13;
375 CreateCrsMatrix( filename, Comm, readMap,
false,
false, symmetric, Amat ) ;
381 Abase = Afactory.
Create(
"Amesos_Umfpack", Problem ) ;
383 std::cerr <<
" AMESOS_UMFPACK is required for this test " << std::endl ;
400 double AnormInf = Amat->
NormInf() ;
401 if (verbose) std::cout <<
" norm(Amat) = " << AnormInf << std::endl;
405 if (verbose) std::cout <<
" norm(Amat) = " << AnormInf << std::endl;
410 double Rcond1 = UmfpackOperator->GetRcond();
415 if (verbose) std::cout <<
" norm(Amat) = " << AnormInf << std::endl;
418 double Rcond2 = UmfpackOperator->GetRcond();
420 if (verbose) std::cout <<
" Rcond1 = " << Rcond1 << std::endl;
421 if (verbose) std::cout <<
" Rcond2 = " << Rcond2 << std::endl;
423 if ( readMap )
delete readMap ;
425 double Rcond1 = Rcond ;
426 double Rcond2 = Rcond ;
434 const int RowindexMax = 3;
435 const int ColindexMax = 2;
450 int DiagonalOptsMax = 2;
454 int EpetraMatrixTypeMax = 3;
459 if ( Comm.NumProc() == 1 ) {
469 if (! PerformDiagonalTest ) DiagonalOptsMax = 1 ;
471 for (
int iterTrans =0 ; iterTrans < 2; iterTrans++ ) {
472 bool transpose = iterTrans == 1 ;
474 for (
int iterDist =0; iterDist < iterDistMax; iterDist++ ) {
475 bool distribute = ( iterDist == 1 );
478 for (
int iterRowindex = 0 ; iterRowindex < RowindexMax; iterRowindex++ ) {
479 for (
int iterColindex = 0 ; iterColindex < ColindexMax; iterColindex++ ) {
484 int ThisRangemapMax = RangemapMax ;
486 ThisRangemapMax =
EPETRA_MIN( 3, ThisRangemapMax );
487 int ThisDomainmapMax =
EPETRA_MIN( 3, ThisRangemapMax );
488 for (
int iterRangemap = 0 ; iterRangemap < ThisRangemapMax; iterRangemap++ ) {
489 for (
int iterDomainmap = 0 ; iterDomainmap < ThisDomainmapMax; iterDomainmap++ ) {
490 for (
int iterDiagonalOpts = 0 ; iterDiagonalOpts < DiagonalOptsMax; iterDiagonalOpts++ ) {
492 int iterRowindex = 0; {
493 int iterColindex = 0 ; {
494 int iterRangemap = 0 ; {
495 int iterDomainmap = 0 ; {
496 for (
int iterDiagonalOpts = 1 ; iterDiagonalOpts < DiagonalOptsMax; iterDiagonalOpts++ ) {
498 const bool printit =
false;
503 if ( ( iterColindex == 0 && distribute ) || iterDiagonalOpts == 0 ) {
504 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
505 for (
int EpetraMatrixType = 0 ; EpetraMatrixType < EpetraMatrixTypeMax; EpetraMatrixType++ ) {
507 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
513 if ( iterRowindex == 0 &&
516 iterDomainmap == 0 ) RunTest[0] = 1;
517 Comm.Broadcast( RunTest, 1, 0 ) ;
523 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
525 if ( iterRowindex > 0 ) MaxLevel = 1 ;
526 if ( iterColindex > 0 ) MaxLevel = 1 ;
527 if ( iterRangemap > 0 ) MaxLevel = 1 ;
528 if ( iterDomainmap > 0 ) MaxLevel = 1 ;
530 bool symmetric =
true;
534 CreateCrsMatrix( filename, Comm, readMap, transpose, distribute, symmetric, Amat ) ;
537 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ <<
538 " Creating matrix from " <<
539 " filename = " << filename <<
540 " symmetric = " << symmetric <<
541 " distribute = " << distribute <<
542 " iterRowindex = " << iterRowindex <<
543 " iterColindex = " << iterColindex <<
544 " iterRangemap = " << iterRangemap <<
545 " iterDomainmap = " << iterDomainmap <<
546 " EpetraMatrixType = " << EpetraMatrixType <<
547 " iterDiagonalOpts = " << iterDiagonalOpts <<
548 " transpose = " << transpose <<
" iterDist = " << iterDist << std::endl ;
551 if ( iterDiagonalOpts ) Comm.SetTracebackMode(1);
553 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
562 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
563 Comm.SetTracebackMode(2);
565 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ <<
566 " filename = " << filename <<
567 " symmetric = " << symmetric <<
568 " distribute = " << distribute <<
569 " iterRowindex = " << iterRowindex <<
570 " iterColindex = " << iterColindex <<
571 " iterRangemap = " << iterRangemap <<
572 " iterDomainmap = " << iterDomainmap <<
573 " EpetraMatrixType = " << EpetraMatrixType <<
574 " iterDiagonalOpts = " << iterDiagonalOpts <<
575 " transpose = " << transpose <<
" iterDist = " << iterDist << std::endl ;
585 if ( Rcond*Rcond1*Rcond2 > 1e-16 ) {
587 MaxError = Rcond*Rcond1*Rcond2;
588 }
else if ( Rcond*Rcond1 > 1e-16 ) {
590 MaxError = Rcond*Rcond1;
596 int NumTheseTests = 0 ;
598 std::cout <<
" About to test " << filename
599 << __FILE__ <<
"::" << __LINE__
600 <<
" EpetraMatrixType = " << EpetraMatrixType
601 << (transpose?
" transpose":
"" )
602 << (distribute?
" distribute":
"" )
605 if ( iterDiagonalOpts == 0 )
606 Comm.SetTracebackMode(2);
608 Comm.SetTracebackMode(1);
611 AmesosClassesInstalled,
628 NumTests += NumTheseTests ;
630 if ( Comm.MyPID() == 0 && ( ( verbose && NumTheseTests ) || Error ) ) {
631 std::cout <<
" Tested " << filename
632 << __FILE__ <<
"::" << __LINE__
633 <<
" EpetraMatrixType = " << EpetraMatrixType
634 << (transpose?
" transpose":
"" )
635 << (distribute?
" distribute":
"" ) <<
" error = "
643 if ( Amat )
delete Amat ;
644 if ( readMap )
delete readMap ;
647 errors[(int) AMESOS_SUPERLUDIST] =
EPETRA_MAX( errors[ (
int) AMESOS_SUPERLUDIST], error ) ;
648 residuals[(int) AMESOS_SUPERLUDIST] =
EPETRA_MAX( residuals[ (
int) AMESOS_SUPERLUDIST], residual ) ;
649 NumErrors += ( residual > maxresidual ) ;
653 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
655 if ( printit && verbose ) std::cout << __FILE__ <<
"::" << __LINE__ << std::endl ;
668 #define TEST_P(variable) { { \
669 if ( true ) { std::cerr << "AMESOS_PRINT " << # variable << "= " << variable << std::endl; }; }\
673 #define TEST_PRINT(variable) { { \
674 if ( true ) { std::cerr << "AMESOS_PRINT " << # variable << "= " << variable << ", " \
675 << __FILE__ << ", line " << __LINE__ << std::endl; }; }\
691 MPI_Init(&argc,&argv);
698 bool verbose =
false;
701 if ( argc >= 2 && (argv[1][0] ==
'-') && (argv[1][1] ==
'v') )
703 if ( argc >= 3 && (argv[2][0] ==
'-') && (argv[2][1] ==
'v') )
705 if ( argc >= 4 && (argv[3][0] ==
'-') && (argv[3][1] ==
'v') )
708 if ( argc >= 2 && (argv[1][0] ==
'-') && (argv[1][1] ==
's') )
710 if ( argc >= 3 && (argv[2][0] ==
'-') && (argv[2][1] ==
's') )
712 if ( argc >= 4 && (argv[3][0] ==
'-') && (argv[3][1] ==
's') )
715 if ( argc >= 2 && (argv[1][0] ==
'-') && (argv[1][1] ==
'q') )
717 if ( argc >= 3 && (argv[2][0] ==
'-') && (argv[2][1] ==
'q') )
719 if ( argc >= 4 && (argv[3][0] ==
'-') && (argv[3][1] ==
'q') )
723 if ( argc >= 2 && (argv[1][0] ==
'-') && (argv[1][1] ==
'h') ) {
724 std::cerr <<
"Usage TestOptions [-s] [-v] [-q] " << std::endl ;
725 std::cerr <<
"-v: verbose " << std::endl ;
726 std::cerr <<
"-s: small " << std::endl ;
727 std::cerr <<
"-q: quiet " << std::endl ;
733 #ifdef HAVE_AMESOS_KLU
739 #ifdef HAVE_AMESOS_PARAKLETE
747 #ifdef HAVE_AMESOS_PARDISO
752 #ifdef HAVE_AMESOS_SUPERLUDIST
759 #ifdef HAVE_AMESOS_LAPACK
763 #ifdef HAVE_AMESOS_SUPERLU
767 #ifdef HAVE_AMESOS_TAUCS
771 #ifdef HAVE_AMESOS_UMFPACK
777 #ifdef HAVE_AMESOS_DSCPACK
781 #ifdef HAVE_AMESOS_MUMPS
785 #ifdef HAVE_AMESOS_SCALAPACK
799 if ( Comm.
MyPID() != 0 ) verbose =
false ;
804 if ( Comm.
MyPID() == 0 ) {
806 while ( what ==
'a' )
811 std::cout << __FILE__ <<
"::" << __LINE__ <<
" Comm.MyPID() = " << Comm.
MyPID() << std::endl ;
820 Comm.SetTracebackMode(2);
822 #ifndef HAVE_AMESOS_EPETRAEXT
823 if ( ! quiet && Comm.
MyPID() == 0 )
824 std::cout <<
"Amesos has been built without epetraext, capabilites requiring epetraext, such as reindexing and Amesos_Paraklete non-transpose solves, will not be tested" << std::endl ;
832 if ( !quiet && Comm.
MyPID() == 0 ) std::cout <<
AmesosClasses[i] <<
" not built in this configuration" << std::endl ;
833 AmesosClassesInstalled[i] =
false;
835 if ( !quiet && Comm.
MyPID() == 0 ) std::cout <<
" Testing " <<
AmesosClasses[i] << std::endl ;
836 AmesosClassesInstalled[i] =
true;
838 ParamList.
set(
"NoDestroy",
true );
854 result +=
TestOneMatrix( AmesosClassesInstalled, (
char *)
"../Test_Basic/SuperLU.triU", Comm, verbose,
false, 1e-6 , numtests ) ;
864 result +=
TestOneMatrix( AmesosClassesInstalled, (
char *)
"../Test_Basic/MissingADiagonal.mtx", Comm, verbose,
false, 1e-2 , numtests ) ;
865 result +=
TestOneMatrix( AmesosClassesInstalled,
"../Test_Basic/Khead.triS", Comm, verbose,
true, 1e-6 , numtests ) ;
866 result +=
TestOneMatrix( AmesosClassesInstalled, (
char *)
"../Test_Basic/bcsstk04.mtx", Comm, verbose,
false, 1e-4 , numtests ) ;
871 result +=
TestOneMatrix( AmesosClassesInstalled, (
char *)
"../Test_Basic/Diagonal.mtx", Comm, verbose,
false, 1e-1 , numtests ) ;
873 result +=
TestOneMatrix( AmesosClassesInstalled, (
char *)
"../Test_Basic/662_bus_out.rsa", Comm, verbose,
false, 1e-5 , numtests ) ;
874 result +=
TestOneMatrix( AmesosClassesInstalled, (
char *)
"../Test_Basic/SuperLU.rua", Comm, verbose,
false, 1e-2 , numtests ) ;
875 result +=
TestOneMatrix( AmesosClassesInstalled,
"../Test_Basic/ImpcolB.rua", Comm, verbose,
false, 1e-6 , numtests ) ;
886 result+=
TestErrors( AmesosClassesInstalled, (
char *)
"../Test_Basic/StructurallySingular.mtx",
887 Comm, verbose, numtests ) ;
888 result+=
TestErrors( AmesosClassesInstalled, (
char *)
"../Test_Basic/NumericallySingular.mtx",
889 Comm, verbose, numtests ) ;
891 if ( ! quiet && Comm.
MyPID() == 0 ) std::cout << result <<
" Tests failed " << numtests <<
" Tests performed " << std::endl ;
893 if ( result == 0 && numtests > 0 ) {
894 if (! quiet && Comm.
MyPID() == 0)
895 std::cout << std::endl <<
"TEST PASSED" << std::endl << std::endl;
898 if (Comm.
MyPID() == 0)
899 std::cout << std::endl <<
"TEST FAILED" << std::endl << std::endl;
914 int main(
int argc,
char *argv[] ) {
915 int retval =
NextMain( argc, argv ) ;
int NumGlobalElements() const
bool MyGRID(int GRID_in) const
void SetOperator(Epetra_RowMatrix *A)
int NextMain(int argc, char *argv[])
bool GlobalIndicesLongLong() const
bool SameAs(const Epetra_BlockMap &Map) const
virtual int NumericFactorization()=0
Performs NumericFactorization on the matrix A.
virtual int SymbolicFactorization()=0
Performs SymbolicFactorization on the matrix A.
virtual int SetParameters(Teuchos::ParameterList &ParameterList)=0
Updates internal variables.
int CrsMatrixTranspose(Epetra_CrsMatrix *In, Epetra_CrsMatrix *Out)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool GlobalIndicesInt() const
int FillComplete(bool OptimizeDataStorage=true)
int TestErrors(const std::vector< bool > AmesosClassesInstalled, const char *filename, Epetra_MpiComm &Comm, const bool verbose, int &NumTests)
const Epetra_Map & RowMap() const
int TestAllClasses(const std::vector< std::string > AmesosClasses, int EpetraMatrixType, const std::vector< bool > AmesosClassesInstalled, Epetra_CrsMatrix *&Amat, const bool transpose, const bool verbose, const bool symmetric, const int Levels, const double Rcond, int Diagonal, int ReindexRowMap, int ReindexColMap, int RangeMapType, int DomainMapType, bool distribute, const char *filename, double &maxrelerror, double &maxrelresidual, int &NumTests)
#define AMESOS_CHK_ERR(a)
int main(int argc, char *argv[])
Factory for binding a third party direct solver to an Epetra_LinearProblem.
#define EPETRA_CHK_ERR(xxx)
int CreateCrsMatrix(const char *in_filename, const Epetra_Comm &Comm, Epetra_Map *&readMap, const bool transpose, const bool distribute, bool &symmetric, Epetra_CrsMatrix *&Matrix)
RCP< Epetra_CrsMatrix > NewMatNewMap(Epetra_CrsMatrix &In, int Diagonal, int ReindexRowMap, int ReindexColMap, int RangeMapType, int DomainMapType)
int SumIntoMyValues(int MyRow, int NumEntries, const double *Values, const int *Indices)
Amesos_BaseSolver * Create(const char *ClassType, const Epetra_LinearProblem &LinearProblem)
Amesos Create method.
int TestOneMatrix(const std::vector< bool > AmesosClassesInstalled, const char *filename, Epetra_MpiComm &Comm, const bool verbose, const bool PerformDiagonalTest, double Rcond, int &NumTests)
const Epetra_CrsGraph & Graph() const
Amesos_BaseSolver: A pure virtual class for direct solution of real-valued double-precision operators...
Class Amesos_Umfpack: An object-oriented wrapper for UMFPACK.
std::vector< string > AmesosClasses