Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
BlaILUSetupCSR.c
Go to the documentation of this file.
1
14#include <math.h>
15#include <time.h>
16
17#include "fasp.h"
18#include "fasp_functs.h"
19
20/*---------------------------------*/
21/*-- Public Functions --*/
22/*---------------------------------*/
23
41 ILU_data *iludata,
42 ILU_param *iluparam)
43{
44 const INT type = iluparam->ILU_type, print_level = iluparam->print_level;
45 const INT n = A->col, nnz = A->nnz, mbloc = n;
46 const REAL ILU_droptol = iluparam->ILU_droptol;
47 const REAL permtol = iluparam->ILU_permtol;
48
49 // local variable
50 INT lfil = iluparam->ILU_lfil, lfilt = iluparam->ILU_lfil;
51 INT ierr, iwk, nzlu, nwork, *ijlu, *iperm;
52 REAL *luval;
53
54 REAL setup_start, setup_end, setup_duration;
55 SHORT status = FASP_SUCCESS;
56
57#if DEBUG_MODE > 0
58 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
59 printf("### DEBUG: m=%d, n=%d, nnz=%d\n", A->row, n, nnz);
60#endif
61
62 fasp_gettime(&setup_start);
63
64 // Expected amount of memory for ILU needed and allocate memory
65 switch (type) {
66 case ILUt:
67 iwk=100*nnz; // iwk is the maxim possible nnz for ILU
68 lfilt=(int)floor(n*0.5)+1;
69 break;
70 case ILUtp:
71 iwk=100*nnz; // iwk is the maxim possible nnz for ILU
72 lfilt=(int)floor(n*0.5)+1;
73 break;
74 default: // ILUk
75 if (lfil == 0) iwk=nnz+500;
76 else iwk=(lfil+5)*nnz;
77 }
78
79 nwork = 4*n;
80
81#if DEBUG_MODE > 1
82 printf("### DEBUG: fill-in = %d, iwk = %d, nwork = %d\n", lfil, iwk, nwork);
83#endif
84
85 // setup ILU preconditioner
86 iludata->A = A; // save a pointer to the coeff matrix for ILUtp
87 iludata->row = iludata->col = n;
88 iludata->ilevL = iludata->jlevL = NULL;
89 iludata->ilevU = iludata->jlevU = NULL;
90 iludata->iperm = NULL;
91 iludata->type = type;
92
93 fasp_ilu_data_create(iwk, nwork, iludata);
94
95#if DEBUG_MODE > 1
96 printf("### DEBUG: memory usage after %s: \n", __FUNCTION__);
98#endif
99
100 // ILU decomposition
101 ijlu = iludata->ijlu;
102 luval = iludata->luval;
103
104 switch (type) {
105
106 case ILUt:
107 fasp_ilut (n, A->val, A->JA, A->IA, lfilt, ILU_droptol, luval, ijlu,
108 iwk, &ierr, &nzlu);
109 break;
110
111 case ILUtp:
112 iperm = iludata->iperm;
113 fasp_ilutp (n, A->val, A->JA, A->IA, lfilt, ILU_droptol, permtol,
114 mbloc, luval, ijlu, iperm, iwk, &ierr, &nzlu);
115 break;
116
117 default: // ILUk
118 fasp_iluk (n, A->val, A->JA, A->IA, lfil, luval, ijlu, iwk,
119 &ierr, &nzlu);
120 break;
121
122 }
123 if (ierr != -4)
124 fasp_dcsr_shift(A, -1);
125
126#if DEBUG_MODE > 1
127 printf("### DEBUG: memory usage after ILU setup: \n");
129#endif
130
131 iludata->nzlu = nzlu;
132 iludata->nwork = nwork;
133
134#if DEBUG_MODE > 1
135 printf("### DEBUG: iwk = %d, nzlu = %d\n", iwk, nzlu);
136#endif
137
138 if (ierr!=0) {
139 printf("### ERROR: ILU setup failed (ierr=%d)! [%s]\n", ierr, __FUNCTION__);
140 status = ERROR_SOLVER_ILUSETUP;
141 goto FINISHED;
142 }
143
144 if (iwk<nzlu) {
145 printf("### ERROR: ILU needs more RAM %d! [%s]\n", iwk-nzlu, __FUNCTION__);
146 status = ERROR_SOLVER_ILUSETUP;
147 goto FINISHED;
148 }
149
150 if (print_level>PRINT_NONE) {
151 fasp_gettime(&setup_end);
152 setup_duration = setup_end - setup_start;
153
154 switch (type) {
155 case ILUt:
156 printf("ILUt setup costs %f seconds.\n", setup_duration);
157 break;
158 case ILUtp:
159 printf("ILUtp setup costs %f seconds.\n", setup_duration);
160 break;
161 default: // ILUk
162 printf("ILUk setup costs %f seconds.\n", setup_duration);
163 break;
164 }
165 }
166
167FINISHED:
168
169#if DEBUG_MODE > 0
170 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
171#endif
172
173 return status;
174}
175
176/*---------------------------------*/
177/*-- End of File --*/
178/*---------------------------------*/
void fasp_mem_usage(void)
Show total allocated memory currently.
Definition: AuxMemory.c:183
void fasp_gettime(REAL *time)
Get system time.
Definition: AuxTiming.c:37
SHORT fasp_ilu_dcsr_setup(dCSRmat *A, ILU_data *iludata, ILU_param *iluparam)
Get ILU decomposition of a CSR matrix A.
void fasp_iluk(INT n, REAL *a, INT *ja, INT *ia, INT lfil, REAL *alu, INT *jlu, INT iwk, INT *ierr, INT *nzlu)
Get ILU factorization with level of fill-in k (ilu(k)) for a CSR matrix A.
Definition: BlaILU.c:72
void fasp_ilutp(INT n, REAL *a, INT *ja, INT *ia, INT lfil, REAL droptol, REAL permtol, INT mbloc, REAL *alu, INT *jlu, INT *iperm, INT iwk, INT *ierr, INT *nz)
Get incomplete LU factorization with pivoting dual truncations of a CSR matrix A.
Definition: BlaILU.c:906
void fasp_ilut(INT n, REAL *a, INT *ja, INT *ia, INT lfil, REAL droptol, REAL *alu, INT *jlu, INT iwk, INT *ierr, INT *nz)
Get incomplete LU factorization with dual truncations of a CSR matrix A.
Definition: BlaILU.c:467
void fasp_dcsr_shift(dCSRmat *A, const INT offset)
Re-index a REAL matrix in CSR format to make the index starting from 0 or 1.
void fasp_ilu_data_create(const INT iwk, const INT nwork, ILU_data *iludata)
Allocate workspace for ILU factorization.
Definition: PreDataInit.c:411
Main header file for the FASP project.
#define REAL
Definition: fasp.h:75
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:71
#define INT
Definition: fasp.h:72
#define FASP_SUCCESS
Definition of return status and error messages.
Definition: fasp_const.h:19
#define ERROR_SOLVER_ILUSETUP
Definition: fasp_const.h:46
#define ILUtp
Definition: fasp_const.h:151
#define ILUt
Definition: fasp_const.h:150
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Definition: fasp_const.h:73
Data for ILU setup.
Definition: fasp.h:651
INT * ijlu
integer array of row pointers and column indexes, the size is nzlu
Definition: fasp.h:669
REAL * luval
nonzero entries of LU
Definition: fasp.h:672
INT col
column of matrix LU, n
Definition: fasp.h:663
INT * jlevU
mapping from row to color for upper triangle
Definition: fasp.h:716
INT nwork
work space size
Definition: fasp.h:678
INT row
row number of matrix LU, m
Definition: fasp.h:660
INT type
type of ILUdata
Definition: fasp.h:657
INT * iperm
permutation arrays for ILUtp
Definition: fasp.h:684
INT nzlu
number of nonzero entries
Definition: fasp.h:666
INT * jlevL
mapping from row to color for lower triangle
Definition: fasp.h:713
INT * ilevL
number of vertices in each color for lower triangle
Definition: fasp.h:707
dCSRmat * A
pointer to the original coefficient matrix
Definition: fasp.h:654
INT * ilevU
number of vertices in each color for upper triangle
Definition: fasp.h:710
Parameters for ILU.
Definition: fasp.h:404
INT ILU_lfil
level of fill-in for ILUk
Definition: fasp.h:413
SHORT print_level
print level
Definition: fasp.h:407
SHORT ILU_type
ILU type for decomposition.
Definition: fasp.h:410
REAL ILU_droptol
drop tolerance for ILUt
Definition: fasp.h:416
REAL ILU_permtol
permuted if permtol*|a(i,j)| > |a(i,i)|
Definition: fasp.h:422
Sparse matrix of REAL type in CSR format.
Definition: fasp.h:151
INT col
column of matrix A, n
Definition: fasp.h:157
REAL * val
nonzero entries of A
Definition: fasp.h:169
INT row
row number of matrix A, m
Definition: fasp.h:154
INT * IA
integer array of row pointers, the size is m+1
Definition: fasp.h:163
INT nnz
number of nonzero entries
Definition: fasp.h:160
INT * JA
integer array of column indexes, the size is nnz
Definition: fasp.h:166