Go to the documentation of this file. 1 #ifndef PARGEMSLR_ILU_H
2 #define PARGEMSLR_ILU_H
10 #include "../utils/utils.hpp"
11 #include "../vectors/int_vector.hpp"
12 #include "../vectors/sequential_vector.hpp"
13 #include "../matrices/csr_matrix.hpp"
14 #include "../solvers/solver.hpp"
83 kIluOptionPartialILUT,
110 kIluOpenMPLevelScheduling,
118 template <
class MatrixType,
class VectorType,
typename DataType>
127 DataType _diag_shift_milu;
135 #ifdef PARGEMSLR_CUDA
147 csrsv2Info_t _matL_info;
153 csrsv2Info_t _matU_info;
217 #ifdef PARGEMSLR_OPENMP
327 typename std::conditional<PargemslrIsDoublePrecision<DataType>::value,
329 float>::type _droptol;
335 typename std::conditional<PargemslrIsDoublePrecision<DataType>::value,
337 float>::type _droptol_ef;
343 typename std::conditional<PargemslrIsDoublePrecision<DataType>::value,
345 float>::type _droptol_s;
411 int _matrix_location;
427 template <
typename T>
428 int ApplyShift( T &w,
int nz, T norm);
439 template <
typename T>
451 template <
typename T>
452 int Qsplit(T *a,
int *ind,
int n,
int Ncut);
471 int SetupILUKSymbolic(
int n,
int *A_i,
int *A_j,
int lfil,
int *perm,
int *qperm,
int *rqperm,
int *iw,
int *L_i,
int *U_i,
int **L_jp,
int **U_jp);
480 virtual int SolveHost( VectorType &x, VectorType &rhs);
489 virtual int SolveLHost( VectorType &x, VectorType &rhs);
498 virtual int SolveUHost( VectorType &x, VectorType &rhs);
500 #ifdef PARGEMSLR_CUDA
509 virtual int SolveDevice( VectorType &x, VectorType &rhs);
518 int SolveLDevice( VectorType &x, VectorType &rhs);
527 int SolveUDevice( VectorType &x, VectorType &rhs);
531 #ifdef PARGEMSLR_OPENMP
554 int SolveHostOmp( VectorType &x, VectorType &rhs);
565 int SolveHostOmpPoly( VectorType &x, VectorType &rhs,
int option);
621 virtual int Setup( VectorType &x, VectorType &rhs);
633 int Setup(MatrixType &L_mat, VectorType &D_vec, MatrixType &U_mat,
int *pperm,
int *qperm);
651 int SetupILUT( VectorType &x, VectorType &rhs);
660 int SetupILUK( VectorType &x, VectorType &rhs);
669 template <
typename T>
670 static void Swap( T *v,
int i,
int j)
686 template <
typename T1,
typename T2>
687 static void Swap(T1 *v, T2 *w,
int i,
int j)
710 template <
typename T1,
typename T2>
720 if(PargemslrAbs(heap[-p]) < PargemslrAbs(heap[-len]))
743 template <
typename T1,
typename T2>
758 l = r >= len || PargemslrAbs(heap[-l])>PargemslrAbs(heap[-r]) ? l : r;
759 if(PargemslrAbs(heap[-l])>PargemslrAbs(heap[-p]))
783 template <
typename T1,
typename T2>
793 if(heap[p] > heap[len])
818 template <
typename T1,
typename T2>
834 l = r >= len || heap[l]<heap[r] ? l : r;
860 template <
typename T>
861 static void Qsplit(T *a,
int *ind,
int left,
int bound,
int right)
870 for(i = left + 1 ; i <= right ; i ++)
872 if(PargemslrAbs(a[i]) > PargemslrAbs(a[left]))
901 virtual int Solve( VectorType &x, VectorType &rhs);
910 int SolveL( VectorType &x, VectorType &rhs);
919 int SolveU( VectorType &x, VectorType &rhs);
935 virtual int MoveData(
const int &location);
949 PARGEMSLR_ERROR(
"Change setup after preconditioner is built.");
950 return PARGEMSLR_ERROR_FUNCTION_CALL_ERR;
953 this->_droptol = params[PARGEMSLR_IO_ILU_DROPTOL_B_LOCAL];
954 this->_droptol_ef = params[PARGEMSLR_IO_ILU_DROPTOL_EF_LOCAL];
955 this->_droptol_s = params[PARGEMSLR_IO_ILU_DROPTOL_S_LOCAL];
956 this->_max_row_nnz = params[PARGEMSLR_IO_ILU_ROWNNZ_B_LOCAL];
957 this->_max_row_nnz_s = params[PARGEMSLR_IO_ILU_ROWNNZ_S_LOCAL];
958 this->_perm_option = params[PARGEMSLR_IO_ILU_PERM_OPTION_LOCAL];
959 this->_omp_option = params[PARGEMSLR_IO_ILU_OMP_OPTION_LOCAL];
960 this->_poly_order = params[PARGEMSLR_IO_POLY_ORDER];
961 this->
_print_option = params[PARGEMSLR_IO_GENERAL_PRINT_LEVEL];
962 this->_complex_shift = params[PARGEMSLR_IO_ADVANCED_USE_COMPLEX_SHIFT] != 0.0;
963 this->_diag_shift_milu = params[PARGEMSLR_IO_ADVANCED_DIAG_SHIFT_MODIFIED];
965 return PARGEMSLR_SUCCESS;
976 this->_fill_level = lfil;
977 return PARGEMSLR_SUCCESS;
988 this->_complex_shift = complex_shift;
989 return PARGEMSLR_SUCCESS;
998 template <
typename T>
1001 this->_droptol = droptol;
1002 return PARGEMSLR_SUCCESS;
1011 template <
typename T>
1016 PARGEMSLR_WARNING(
"Change setting after Setup is not going to change the preconditioner.");
1018 this->_droptol_ef = droptol_ef;
1019 return PARGEMSLR_SUCCESS;
1028 template <
typename T>
1033 PARGEMSLR_WARNING(
"Change setting after Setup is not going to change the preconditioner.");
1035 this->_droptol_s = droptol_s;
1036 return PARGEMSLR_SUCCESS;
1109 template <
typename T>
1114 PARGEMSLR_WARNING(
"Change setting after Setup is not going to change the preconditioner.");
1116 this->_diag_shift_milu = milu_shift;
1117 return PARGEMSLR_SUCCESS;
1190 typedef IluClass<CsrMatrixClass<float>, SequentialVectorClass<float>,
float> precond_ilu_csr_seq_float;
1191 typedef IluClass<CsrMatrixClass<double>, SequentialVectorClass<double>,
double> precond_ilu_csr_seq_double;
1192 typedef IluClass<CsrMatrixClass<complexs>, SequentialVectorClass<complexs>, complexs> precond_ilu_csr_seq_complexs;
1193 typedef IluClass<CsrMatrixClass<complexd>, SequentialVectorClass<complexd>, complexd> precond_ilu_csr_seq_complexd;
virtual int Clear()
Free the current precondioner.
Definition: ilu.cpp:329
int SetModified(bool modified)
Enable/Disable modified ILU.
Definition: ilu.cpp:3843
IluOpenMPOptionEnum
The ilu OpenMP solve option.
Definition: ilu.hpp:108
virtual ~IluClass()
The destructor of precondioner class.
Definition: ilu.cpp:317
virtual int Solve(VectorType &x, VectorType &rhs)
Solve phase. Call this function after Setup. Solve with cusparse if unified memory/device memory is u...
Definition: ilu.cpp:3417
static void Swap(T *v, int i, int j)
Swap v[i] and v[j].
Definition: ilu.hpp:670
SequentialVectorClass< DataType > & GetD()
Get the inverse of diagonal of the U matrix.
Definition: ilu.cpp:3885
int SetOpenMPOption(int omp_option)
Set the OpenMP option. See IluOpenMPOptionEnum.
Definition: ilu.cpp:3778
int SolveU(VectorType &x, VectorType &rhs)
Solve with U only. Call this function after Setup. Solve with cusparse if unified memory/device memor...
Definition: ilu.cpp:3479
CsrMatrixClass< DataType > & GetU()
Get the U matrix of the ILU factorizaiton without diagonal.
Definition: ilu.cpp:3895
int SetupPermutation(VectorType &x, VectorType &rhs)
Build the permutation vector.
Definition: ilu.cpp:607
int SetDropToleranceEF(T droptol_ef)
Set the drop tols in E, F part for Partial ILUT.
Definition: ilu.hpp:1012
int SetPolyOrder(int order)
Set the polynomia order in some OpenMP option. See IluOpenMPOptionEnum.
Definition: ilu.cpp:3818
virtual int SetWithParameterArray(double *params)
Setup with parameter array.
Definition: ilu.hpp:945
CsrMatrixClass< DataType > & GetF()
Get the U matrix of the ILU factorizaiton without diagonal.
Definition: ilu.cpp:3905
CsrMatrixClass< DataType > & GetE()
Get the U matrix of the ILU factorizaiton without diagonal.
Definition: ilu.cpp:3915
IntVectorClass< int > & GetRowPermutationVector()
Get the row permutation vector.
Definition: ilu.cpp:3945
int SetNB(int nB)
Set the size of the B block.
Definition: ilu.cpp:3742
int SetIluComplexShift(bool complex_shift)
Set if we turn on the complex shift or not (complex version only).
Definition: ilu.hpp:986
virtual long int GetNumNonzeros()
Get the total number of nonzeros the ILU.
Definition: ilu.cpp:3865
static void AbsMinHeapRemove_RN(T1 *heap, T2 *v, int len)
Remove value from a min heap based on the absolute value. RN stands for reverse (heap from right to l...
Definition: ilu.hpp:744
int SetPermutationOption(int perm_option)
Set the ILU permutation option. See IluReorderingOptionEnum.
Definition: ilu.cpp:3831
int SetLevelOfFill(int lfil)
Set the level of fill for ILU(K).
Definition: ilu.hpp:974
int SetDropToleranceS(T droptol_s)
Set the drop tols in S part for Partial ILUT.
Definition: ilu.hpp:1029
bool _ready
If the solver is ready.
Definition: solver.hpp:108
IluOptionEnum
The ilu option.
Definition: ilu.hpp:81
The base solver class.
Definition: solver.hpp:47
The template class complex.
Definition: complex.hpp:24
virtual int Setup(VectorType &x, VectorType &rhs)
Setup the precondioner phase. Will be called by the solver if not called directly.
Definition: ilu.cpp:381
int SetOption(int option)
Set the ILU option. See IluOptionEnum.
Definition: ilu.cpp:3760
int GetNB()
Get the U matrix of the ILU factorizaiton without diagonal.
Definition: ilu.cpp:3935
static void Qsplit(T *a, int *ind, int left, int bound, int right)
Does a quick-sort split of a real array.
Definition: ilu.hpp:861
static void MinHeapAdd_NNR(int *heap, T1 *v1, T2 *v2, int len)
Add value to a min heap. NNR stands for normal (heap from left to right), normal (v1 based on normal ...
Definition: ilu.hpp:784
int SolveL(VectorType &x, VectorType &rhs)
Solve with L only. Call this function after Setup. Solve with cusparse if unified memory/device memor...
Definition: ilu.cpp:3448
int _print_option
The print option.
Definition: solver.hpp:114
virtual int SetSolveLocation(const int &location)
Set the data location that the preconditioner apply to.
Definition: ilu.cpp:3965
int SetMaxNnzPerRow(int max_row_nnz)
Set the max fill allowed for each row/col of L and U.
Definition: ilu.cpp:3718
The local ilu preconditioner, only work for sequential CSR matrix.
Definition: ilu.hpp:120
CsrMatrixClass< DataType > & GetL()
Get the L matrix of the ILU factorizaiton without diagonal.
Definition: ilu.cpp:3875
int SetDropTolerance(T droptol)
Set the drop tols for ILUT.
Definition: ilu.hpp:999
CsrMatrixClass< DataType > & GetS()
Get the U matrix of the ILU factorizaiton without diagonal.
Definition: ilu.cpp:3925
IluClass()
The constructor of precondioner class.
Definition: ilu.cpp:18
static void MinHeapRemovd_NNR(int *heap, T1 *v1, T2 *v2, int len)
Remove value from a min heap. NNR stands for normal (heap from left to right), normal (v1 based on no...
Definition: ilu.hpp:819
static void AbsMinHeapAdd_RN(T1 *heap, T2 *v, int len)
Add value to a min heap based on the absolute value. RN stands for reverse (heap from right to left),...
Definition: ilu.hpp:711
int SetupPartialILUT(VectorType &x, VectorType &rhs)
Setup Partial ILUT, form approximate Schur Complement.
Definition: ilu.cpp:2711
IluClass< MatrixType, VectorType, DataType > & operator=(const IluClass< MatrixType, VectorType, DataType > &precond)
The operator = of precondioner class.
Definition: ilu.cpp:179
IluReorderingOptionEnum
The ilu reordering option.
Definition: ilu.hpp:93
int GetSize()
Get the size of the problem.
Definition: ilu.cpp:3855
int SetMaxNnzPerRowSPart(int max_row_nnz_s)
Set the max fill allowed for each row/col of S in partial ILU.
Definition: ilu.cpp:3730
int SetupILUT(VectorType &x, VectorType &rhs)
Setup ILUT, ingore the ilu option.
Definition: ilu.cpp:1632
int SetupILUK(VectorType &x, VectorType &rhs)
Setup ILU(K).
Definition: ilu.cpp:2148
int SetModifiedShift(T milu_shift)
Set the shift for the modified ILU.
Definition: ilu.hpp:1110
virtual int MoveData(const int &location)
Move the preconditioner to another location. Only can be called after Setup.
Definition: ilu.cpp:3984
static void Swap(T1 *v, T2 *w, int i, int j)
Swap v[i] and v[j], w[i] and w[j].
Definition: ilu.hpp:687
IntVectorClass< int > & GetColPermutationVector()
Get the column permutation vector.
Definition: ilu.cpp:3955