37 #include "amesos_paraklete_decl.h"
44 #undef __ASSERT_VOID_CAST
52 template<
class T,
class DeleteFunctor>
53 class DeallocFunctorDeleteWithCommon
56 DeallocFunctorDeleteWithCommon(
58 ,DeleteFunctor deleteFunctor
60 : common_(common), deleteFunctor_(deleteFunctor)
64 if(ptr) deleteFunctor_(&ptr,&*common_);
68 DeleteFunctor deleteFunctor_;
69 DeallocFunctorDeleteWithCommon();
72 template<
class T,
class DeleteFunctor>
73 DeallocFunctorDeleteWithCommon<T,DeleteFunctor>
74 deallocFunctorDeleteWithCommon(
76 ,DeleteFunctor deleteFunctor
79 return DeallocFunctorDeleteWithCommon<T,DeleteFunctor>(common,deleteFunctor);
106 UseTranspose_(false),
142 std::cerr <<
" The number of non zero entries in the matrix has changed since the last call to SymbolicFactorization(). " ;
148 std::cerr <<
" The number of non zero entries in the matrix has changed since the last call to SymbolicFactorization(). " ;
152 #ifdef HAVE_AMESOS_EPETRAEXT
153 if ( transposer_.get() != 0 ) {
181 std::cerr <<
" Amesos_Paraklete cannot handle this matrix. " ;
183 std::cerr <<
"Unknown error" << std::endl ;
186 std::cerr <<
" Try setting the Reindex parameter to true. " << std::endl ;
187 #ifndef HAVE_AMESOS_EPETRAEXT
188 std::cerr <<
" You will need to rebuild the Amesos library with the EpetraExt library to use the reindex feature" << std::endl ;
189 std::cerr <<
" To rebuild Amesos with EpetraExt, add --enable-epetraext to your configure invocation" << std::endl ;
228 int NumMyElements_ = 0 ;
264 #ifdef HAVE_AMESOS_EPETRAEXT
265 bool MakeDataContiguous =
true;
268 int OriginalTracebackMode =
CrsMatrixA_->GetTracebackMode();
271 CcsMatrixA = &(
dynamic_cast<Epetra_CrsMatrix&
>(((*transposer_)(*CrsMatrixA_))));
272 CrsMatrixA_->SetTracebackMode( OriginalTracebackMode );
274 std::cerr <<
"Amesos_Paraklete requires the EpetraExt library to solve non-transposed problems. " << std::endl ;
275 std::cerr <<
" To rebuild Amesos with EpetraExt, add --enable-epetraext to your configure invocation" << std::endl ;
283 #ifdef HAVE_AMESOS_EPETRAEXT
292 std::cerr <<
"Amesos_Paraklete requires EpetraExt to reindex matrices." << std::endl
293 <<
" Please rebuild with the EpetraExt library by adding --enable-epetraext to your configure invocation" << std::endl ;
371 bool StorageOptimized = ( CrsMatrix != 0 && CrsMatrix->
StorageOptimized() );
373 if (
AddToDiag_ != 0.0 ) StorageOptimized = false ;
378 if ( ! StorageOptimized ) {
386 int NumEntriesThisRow;
388 if( StorageOptimized ) {
393 ExtractMyRowView( MyRow, NumEntriesThisRow, RowValues,
396 for (
int j=0; j < NumEntriesThisRow; j++ ) {
397 Ai[
Ap[MyRow]+j] = ColIndices[j];
402 Ap[MyRow+1] =
Ap[MyRow] + NumEntriesThisRow ;
411 if ( firsttime && CrsMatrix == 0 ) {
417 if ( CrsMatrix != 0 ) {
419 ExtractMyRowView( MyRow, NumEntriesThisRow, RowValues,
425 ExtractMyRowCopy( MyRow, MaxNumEntries_,
435 Ap[MyRow] = Ai_index ;
436 for (
int j = 0; j < NumEntriesThisRow; j++ ) {
437 Ai[Ai_index] = ColIndices[j] ;
439 if (ColIndices[j] == MyRow) {
445 for (
int j = 0; j < NumEntriesThisRow; j++ ) {
446 VecAval[Ai_index] = RowValues[j] ;
447 if (ColIndices[j] == MyRow) {
454 Ap[MyRow] = Ai_index ;
466 pk_A.xtype = CHOLMOD_PATTERN ;
471 pk_A.xtype = CHOLMOD_REAL ;
476 pk_A.itype = CHOLMOD_LONG ;
477 pk_A.dtype = CHOLMOD_DOUBLE ;
509 if (ParameterList.
isSublist(
"Paraklete") ) {
527 amesos_paraklete_free_symbolic)
569 if (
GetProblem()->GetOperator()->OperatorRangeMap().NumGlobalPoints() !=
570 GetProblem()->GetOperator()->OperatorDomainMap().NumGlobalPoints() ) {
578 void my_handler (
int status,
char *file,
int line,
char *msg)
580 printf (
"Error handler: %s %d %d: %s\n", file, line, status, msg) ;
581 if (status != CHOLMOD_OK)
583 fprintf (stderr,
"\n\n*********************************************\n");
584 fprintf (stderr,
"**** Test failure: %s %d %d %s\n", file, line,
586 fprintf (stderr,
"*********************************************\n\n");
602 #ifdef HAVE_AMESOS_EPETRAEXT
643 assert (MpiComm != 0);
661 MPI_Group OrigGroup, ParakleteGroup;
662 MPI_Comm_group(MpiComm->
GetMpiComm(), &OrigGroup);
663 MPI_Group_incl(OrigGroup, MaxProcesses_, &ProcsInGroup[0], &ParakleteGroup);
672 cholmod_common *cm = &(pk_common.cm) ;
673 amesos_cholmod_l_start (cm) ;
674 PK_DEBUG_INIT (
"pk", cm) ;
682 pk_common.tol_diag = 0.001 ;
683 pk_common.tol_offdiag = 0.1 ;
684 pk_common.growth = 2. ;
717 if (
false && CrsMatrixA == 0 )
725 if (
false && CrsMatrixA == 0 ) {
770 #ifdef HAVE_AMESOS_EPETRAEXT
781 if ((vecX == 0) || (vecB == 0))
881 <<
" and " <<
numentries_ <<
" nonzeros" << std::endl;
882 std::cout <<
"Amesos_Paraklete : Nonzero elements per row = "
884 std::cout <<
"Amesos_Paraklete : Percentage of nonzero elements = "
886 std::cout <<
"Amesos_Paraklete : Use transpose = " <<
UseTranspose_ << std::endl;
917 std::string p =
"Amesos_Paraklete : ";
920 std::cout << p <<
"Time to convert matrix to Paraklete format = "
921 << ConTime <<
" (s)" << std::endl;
922 std::cout << p <<
"Time to redistribute matrix = "
923 << MatTime <<
" (s)" << std::endl;
924 std::cout << p <<
"Time to redistribute vectors = "
925 << VecTime <<
" (s)" << std::endl;
926 std::cout << p <<
"Number of symbolic factorizations = "
928 std::cout << p <<
"Time for sym fact = "
929 << SymTime *
NumSymbolicFact_ <<
" (s), avg = " << SymTime <<
" (s)" << std::endl;
930 std::cout << p <<
"Number of numeric factorizations = "
932 std::cout << p <<
"Time for num fact = "
933 << NumTime *
NumNumericFact_ <<
" (s), avg = " << NumTime <<
" (s)" << std::endl;
934 std::cout << p <<
"Number of solve phases = "
936 std::cout << p <<
"Time for solve = "
937 << SolTime *
NumSolve_ <<
" (s), avg = " << SolTime <<
" (s)" << std::endl;
942 std::cout << p <<
"Total time spent in Amesos = " << tt <<
" (s) " << std::endl;
943 std::cout << p <<
"Total time spent in the Amesos interface = " << OveTime <<
" (s)" << std::endl;
944 std::cout << p <<
"(the above time does not include PARAKLETE time)" << std::endl;
945 std::cout << p <<
"Amesos interface time / total time = " << OveTime / tt << std::endl;
int NumSymbolicFact_
Number of symbolic factorization phases.
int LRID(int GRID_in) const
int MtxConvTime_
Quick access pointers to internal timing information.
int NumGlobalElements() const
int SymbolicFactorization()
Performs SymbolicFactorization on the matrix A.
MPI_Comm GetMpiComm() const
bool StorageOptimized() const
Teuchos::RCP< Epetra_Import > ImportToSerial_
Importer to process 0.
virtual const Epetra_Map & RowMatrixRowMap() const =0
void PrintLine() const
Prints line on std::cout.
Epetra_MultiVector * GetLHS() const
~Amesos_Paraklete(void)
Amesos_Paraklete Destructor.
Epetra_MultiVector * GetRHS() const
bool SameAs(const Epetra_BlockMap &Map) const
bool IsSymbolicFactorizationOK_
If true, SymbolicFactorization() has been successfully called.
T & get(ParameterList &l, const std::string &name)
Epetra_MultiVector * SerialB_
Serial versions of the LHS and RHS (may point to the original vector if serial)
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
std::vector< double > RowValuesV_
Only used for RowMatrices to extract copies.
Epetra_RowMatrix * StdIndexMatrix_
Points to a Contiguous Copy of A.
bool AddZeroToDiag_
Adds zero to diagonal of redistributed matrix (some solvers choke on a matrix with a partly empty dia...
int numentries_
Number of non-zero entries in Problem_->GetOperator()
Teuchos::RCP< Epetra_MultiVector > SerialBextract_
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual const Epetra_Map & OperatorDomainMap() const =0
void SetMaxProcesses(int &MaxProcesses, const Epetra_RowMatrix &A)
Amesos_Paraklete(const Epetra_LinearProblem &LinearProblem)
Amesos_Paraklete Constructor.
void CreateTimer(const Epetra_Comm &Comm, int size=1)
Initializes the Time object.
std::vector< int > ColIndicesV_
Only used for RowMatrices to extract copies.
int NumNumericFact_
Number of numeric factorization phases.
virtual int NumGlobalNonzeros() const =0
bool UseTranspose_
If true, the transpose of A is used.
virtual int MyPID() const =0
int FillComplete(bool OptimizeDataStorage=true)
Epetra_MultiVector * SerialX_
const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
Teuchos::RCP< paraklete_symbolic > LUsymbolic_
Teuchos::RCP< Epetra_CrsMatrix > SerialCrsMatrixA_
Points to a Serial Copy of A (unused if UseDataInPlace_==1)
void my_handler(int status, char *file, int line, char *msg)
int NumSolve_
Number of solves.
const Epetra_Map & RowMap() const
bool isParameter(const std::string &name) const
int NumMyElements() const
Teuchos::RCP< Epetra_Import > ImportDomainToSerial_
virtual int MaxNumEntries() const =0
virtual const Epetra_Map & OperatorRangeMap() const =0
Teuchos::RCP< paraklete_common > common_
Teuchos::RCP< Epetra_Map > SerialMap_
Points to a Serial Map (unused if UseDataInPlace_ == 1 )
void SetStatusParameters(const Teuchos::ParameterList &ParameterList)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool ComputeVectorNorms_
If true, prints the norms of X and B in Solve().
void SetControlParameters(const Teuchos::ParameterList &ParameterList)
#define AMESOS_CHK_ERR(a)
bool isSublist(const std::string &name) const
int NumGlobalElements_
Number of rows and columns in the Problem_->GetOperator()
virtual const Epetra_BlockMap & Map() const =0
const Epetra_LinearProblem * GetProblem() const
Get a pointer to the Problem.
Epetra_RowMatrix * RowMatrixA_
Operator converted to a RowMatrix.
void PrintStatus() const
Prints information about the factorization and solution phases.
bool PrintTiming_
If true, prints timing information in the destructor.
Teuchos::RCP< Amesos_Paraklete_Pimpl > PrivateParakleteData_
Epetra_CrsMatrix * CrsMatrixA_
Operator converted to a CrsMatrix.
int NumVectors_
Number of vectors in RHS and LHS.
Teuchos::RCP< Amesos_StandardIndex > StdIndexDomain_
bool PrintStatus_
If true, print additional information in the destructor.
virtual int NumGlobalCols() const =0
int ConvertToParakleteCRS(bool firsttime)
int AddTime(const std::string what, int dataID, const int timerID=0)
Adds to field what the time elapsed since last call to ResetTimer().
int Solve()
Solves A X = B (or AT x = B)
void PrintTiming() const
Prints timing information.
virtual int Broadcast(double *MyVals, int Count, int Root) const =0
bool Reindex_
If true, the Amesos class should reindex the matrix to standard indexing (i.e.
int PerformNumericFactorization()
int NumericFactorization()
Performs NumericFactorization on the matrix A.
virtual int NumProc() const =0
void ComputeTrueResidual(const Epetra_RowMatrix &Matrix, const Epetra_MultiVector &X, const Epetra_MultiVector &B, const bool UseTranspose, const std::string prefix) const
Computes the true residual, B - Matrix * X, and prints the results.
int SetParameters(Teuchos::ParameterList &ParameterList)
Updates internal variables.
Teuchos::RCP< Amesos_StandardIndex > StdIndexRange_
int CreateLocalMatrixAndExporters()
bool MatrixShapeOK() const
Returns true if PARAKLETE can handle this matrix shape.
int UseDataInPlace_
1 if Problem_->GetOperator() is stored entirely on process 0
Epetra_RowMatrix * SerialMatrix_
Points to a Serial Copy of A.
Teuchos::RCP< Epetra_MultiVector > SerialXextract_
Serial versions of the LHS and RHS (if necessary)
bool TrustMe_
If true, no checks are made and the matrix is assume to be distributed.
void ResetTimer(const int timerID=0)
Resets the internally stored time object.
Epetra_Operator * GetOperator() const
int verbose_
Toggles the output level.
const Epetra_LinearProblem * Problem_
Pointer to the linear system problem.
double GetTime(const std::string what) const
Gets the cumulative time using the string.
int PerformSymbolicFactorization()
Teuchos::RCP< Epetra_Import > ImportRangeToSerial_
Teuchos::RCP< paraklete_numeric > LUnumeric_
double * SerialXBvalues_
Pointer to the actual values in the serial version of X and B.
bool IsNumericFactorizationOK_
If true, NumericFactorization() has been successfully called.
std::vector< long > Ap
Ap, Ai, Aval form the compressed row storage used by Paraklete Ai and Aval can point directly into a ...
std::vector< double > VecAval
virtual int NumGlobalRows() const =0
void ComputeVectorNorms(const Epetra_MultiVector &X, const Epetra_MultiVector &B, const std::string prefix) const
Computes the norms of X and B and print the results.
bool UseTranspose() const
Returns the current UseTranspose setting.
Teuchos::RCP< Amesos_StandardIndex > StdIndex_
bool ComputeTrueResidual_
If true, computes the true residual in Solve().
double AddToDiag_
Add this value to the diagonal.