SuperLU 6.0.1
slu_util.h
Go to the documentation of this file.
1
21#ifndef __SUPERLU_UTIL /* allow multiple inclusions */
22#define __SUPERLU_UTIL
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27/*
28#ifndef __STDC__
29#include <malloc.h>
30#endif
31*/
32#include <assert.h>
33#include "superlu_enum_consts.h"
34
35
36/***********************************************************************
37 * Macros
38 ***********************************************************************/
39/*
40 * You can support older version of SuperLU.
41 * At compile-time, you can catch the new release as:
42 * #ifdef SUPERLU_MAJOR_VERSION == 5
43 * use the new interface
44 * #else
45 * use the old interface
46 * #endif
47 * Versions 4.x and earlier do not include a #define'd version numbers.
48 */
49#define SUPERLU_MAJOR_VERSION 6
50#define SUPERLU_MINOR_VERSION 0
51#define SUPERLU_PATCH_VERSION 1
52
53
54#define FIRSTCOL_OF_SNODE(i) (xsup[i])
55/* No of marker arrays used in the symbolic factorization,
56 each of size n */
57#define NO_MARKER 3
58#define NUM_TEMPV(m,w,t,b) ( SUPERLU_MAX(m, (t + b)*w) )
59
60#ifndef USER_ABORT
61#define USER_ABORT(msg) superlu_abort_and_exit(msg)
62#endif
63
64#define ABORT(err_msg) \
65 { char msg[256];\
66 sprintf(msg,"%s at line %d in file %s\n",err_msg,__LINE__, __FILE__);\
67 USER_ABORT(msg); }
68
69
70#ifndef USER_MALLOC
71#if 1
72#define USER_MALLOC(size) superlu_malloc(size)
73#else
74/* The following may check out some uninitialized data */
75#define USER_MALLOC(size) memset (superlu_malloc(size), '\x0F', size)
76#endif
77#endif
78
79#define SUPERLU_MALLOC(size) USER_MALLOC(size)
80
81#ifndef USER_FREE
82#define USER_FREE(addr) superlu_free(addr)
83#endif
84
85#define SUPERLU_FREE(addr) USER_FREE(addr)
86
87#define CHECK_MALLOC(where) { \
88 extern int superlu_malloc_total; \
89 printf("%s: malloc_total %d Bytes\n", \
90 where, superlu_malloc_total); \
91}
92
93#define SUPERLU_MAX(x, y) ( (x) > (y) ? (x) : (y) )
94#define SUPERLU_MIN(x, y) ( (x) < (y) ? (x) : (y) )
95
96/*********************************************************
97 * Macros used for easy access of sparse matrix entries. *
98 *********************************************************/
99#define L_SUB_START(col) ( Lstore->rowind_colptr[col] )
100#define L_SUB(ptr) ( Lstore->rowind[ptr] )
101#define L_NZ_START(col) ( Lstore->nzval_colptr[col] )
102#define L_FST_SUPC(superno) ( Lstore->sup_to_col[superno] )
103#define U_NZ_START(col) ( Ustore->colptr[col] )
104#define U_SUB(ptr) ( Ustore->rowind[ptr] )
105
106
107/***********************************************************************
108 * Constants
109 ***********************************************************************/
110#define EMPTY (-1)
111/*#define NO (-1)*/
112#define FALSE 0
113#define TRUE 1
114
115#if 0 // this was old; new one is 6, defined in superlu_enum_consts.h
116#define NO_MEMTYPE 4 /* 0: lusup;
117 1: ucol;
118 2: lsub;
119 3: usub */
120#endif
121
122#define GluIntArray(n) (5 * (n) + 5)
123
124/* Dropping rules */
125#define NODROP ( 0x0000 )
126#define DROP_BASIC ( 0x0001 ) /* ILU(tau) */
127#define DROP_PROWS ( 0x0002 ) /* ILUTP: keep p maximum rows */
128#define DROP_COLUMN ( 0x0004 ) /* ILUTP: for j-th column,
129 p = gamma * nnz(A(:,j)) */
130#define DROP_AREA ( 0x0008 ) /* ILUTP: for j-th column, use
131 nnz(F(:,1:j)) / nnz(A(:,1:j))
132 to limit memory growth */
133#define DROP_SECONDARY ( 0x000E ) /* PROWS | COLUMN | AREA */
134#define DROP_DYNAMIC ( 0x0010 ) /* adaptive tau */
135#define DROP_INTERP ( 0x0100 ) /* use interpolation */
137
138#if 1
139#define MILU_ALPHA (1.0e-2) /* multiple of drop_sum to be added to diagonal */
140#else
141#define MILU_ALPHA 1.0 /* multiple of drop_sum to be added to diagonal */
142#endif
143
144
145/***********************************************************************
146 * Type definitions
147 ***********************************************************************/
148typedef float flops_t;
149typedef unsigned char Logical;
150
151/*
152 *-- This contains the options used to control the solution process.
153 *
154 * Fact (fact_t)
155 * Specifies whether or not the factored form of the matrix
156 * A is supplied on entry, and if not, how the matrix A should
157 * be factorizaed.
158 * = DOFACT: The matrix A will be factorized from scratch, and the
159 * factors will be stored in L and U.
160 * = SamePattern: The matrix A will be factorized assuming
161 * that a factorization of a matrix with the same sparsity
162 * pattern was performed prior to this one. Therefore, this
163 * factorization will reuse column permutation vector
164 * ScalePermstruct->perm_c and the column elimination tree
165 * LUstruct->etree.
166 * = SamePattern_SameRowPerm: The matrix A will be factorized
167 * assuming that a factorization of a matrix with the same
168 * sparsity pattern and similar numerical values was performed
169 * prior to this one. Therefore, this factorization will reuse
170 * both row and column scaling factors R and C, both row and
171 * column permutation vectors perm_r and perm_c, and the
172 * L & U data structures set up from the previous factorization.
173 * = FACTORED: On entry, L, U, perm_r and perm_c contain the
174 * factored form of A. If DiagScale is not NOEQUIL, the matrix
175 * A has been equilibrated with scaling factors R and C.
176 *
177 * Equil (yes_no_t)
178 * Specifies whether to equilibrate the system (scale A's row and
179 * columns to have unit norm).
180 *
181 * ColPerm (colperm_t)
182 * Specifies what type of column permutation to use to reduce fill.
183 * = NATURAL: use the natural ordering
184 * = MMD_ATA: use minimum degree ordering on structure of A'*A
185 * = MMD_AT_PLUS_A: use minimum degree ordering on structure of A'+A
186 * = COLAMD: use approximate minimum degree column ordering
187 * = MY_PERMC: use the ordering specified by the user
188 *
189 * Trans (trans_t)
190 * Specifies the form of the system of equations:
191 * = NOTRANS: A * X = B (No transpose)
192 * = TRANS: A**T * X = B (Transpose)
193 * = CONJ: A**H * X = B (Transpose)
194 *
195 * IterRefine (IterRefine_t)
196 * Specifies whether to perform iterative refinement.
197 * = NO: no iterative refinement
198 * = SLU_SINGLE: perform iterative refinement in single precision
199 * = SLU_DOUBLE: perform iterative refinement in double precision
200 * = SLU_EXTRA: perform iterative refinement in extra precision
201 *
202 * DiagPivotThresh (double, in [0.0, 1.0]) (only for sequential SuperLU)
203 * Specifies the threshold used for a diagonal entry to be an
204 * acceptable pivot.
205 *
206 * SymmetricMode (yest_no_t)
207 * Specifies whether to use symmetric mode. Symmetric mode gives
208 * preference to diagonal pivots, and uses an (A'+A)-based column
209 * permutation algorithm.
210 *
211 * PivotGrowth (yes_no_t)
212 * Specifies whether to compute the reciprocal pivot growth.
213 *
214 * ConditionNumber (ues_no_t)
215 * Specifies whether to compute the reciprocal condition number.
216 *
217 * RowPerm (rowperm_t) (only for SuperLU_DIST or ILU)
218 * Specifies whether to permute rows of the original matrix.
219 * = NO: not to permute the rows
220 * = LargeDiag: make the diagonal large relative to the off-diagonal
221 * = MY_PERMR: use the permutation given by the user
222 *
223 * ILU_DropRule (int)
224 * Specifies the dropping rule:
225 * = DROP_BASIC: Basic dropping rule, supernodal based ILUTP(tau).
226 * = DROP_PROWS: Supernodal based ILUTP(p,tau), p = gamma * nnz(A)/n.
227 * = DROP_COLUMN: Variant of ILUTP(p,tau), for j-th column,
228 * p = gamma * nnz(A(:,j)).
229 * = DROP_AREA: Variation of ILUTP, for j-th column, use
230 * nnz(F(:,1:j)) / nnz(A(:,1:j)) to control memory.
231 * = DROP_DYNAMIC: Modify the threshold tau during factorizaion:
232 * If nnz(L(:,1:j)) / nnz(A(:,1:j)) > gamma
233 * tau_L(j) := MIN(tau_0, tau_L(j-1) * 2);
234 * Otherwise
235 * tau_L(j) := MAX(tau_0, tau_L(j-1) / 2);
236 * tau_U(j) uses the similar rule.
237 * NOTE: the thresholds used by L and U are separate.
238 * = DROP_INTERP: Compute the second dropping threshold by
239 * interpolation instead of sorting (default).
240 * In this case, the actual fill ratio is not
241 * guaranteed to be smaller than gamma.
242 * Note: DROP_PROWS, DROP_COLUMN and DROP_AREA are mutually exclusive.
243 * ( Default: DROP_BASIC | DROP_AREA )
244 *
245 * ILU_DropTol (double)
246 * numerical threshold for dropping.
247 *
248 * ILU_FillFactor (double)
249 * Gamma in the secondary dropping.
250 *
251 * ILU_Norm (norm_t)
252 * Specify which norm to use to measure the row size in a
253 * supernode: infinity-norm, 1-norm, or 2-norm.
254 *
255 * ILU_FillTol (double)
256 * numerical threshold for zero pivot perturbation.
257 *
258 * ILU_MILU (milu_t)
259 * Specifies which version of MILU to use.
260 *
261 * ILU_MILU_Dim (double)
262 * Dimension of the PDE if available.
263 *
264 * ReplaceTinyPivot (yes_no_t) (only for SuperLU_DIST)
265 * Specifies whether to replace the tiny diagonals by
266 * sqrt(epsilon)*||A|| during LU factorization.
267 *
268 * SolveInitialized (yes_no_t) (only for SuperLU_DIST)
269 * Specifies whether the initialization has been performed to the
270 * triangular solve.
271 *
272 * RefineInitialized (yes_no_t) (only for SuperLU_DIST)
273 * Specifies whether the initialization has been performed to the
274 * sparse matrix-vector multiplication routine needed in iterative
275 * refinement.
276 *
277 * PrintStat (yes_no_t)
278 * Specifies whether to print the solver's statistics.
279 */
280typedef struct {
281 fact_t Fact;
282 yes_no_t Equil;
283 colperm_t ColPerm;
284 trans_t Trans;
285 IterRefine_t IterRefine;
286 double DiagPivotThresh;
287 yes_no_t SymmetricMode;
288 yes_no_t PivotGrowth;
289 yes_no_t ConditionNumber;
290 rowperm_t RowPerm;
291 int ILU_DropRule;
292 double ILU_DropTol; /* threshold for dropping */
293 double ILU_FillFactor; /* gamma in the secondary dropping */
294 norm_t ILU_Norm; /* infinity-norm, 1-norm, or 2-norm */
295 double ILU_FillTol; /* threshold for zero pivot perturbation */
296 milu_t ILU_MILU;
297 double ILU_MILU_Dim; /* Dimension of PDE (if available) */
298 yes_no_t ParSymbFact;
299 yes_no_t ReplaceTinyPivot; /* used in SuperLU_DIST */
300 yes_no_t SolveInitialized;
301 yes_no_t RefineInitialized;
302 yes_no_t PrintStat;
303 int nnzL, nnzU; /* used to store nnzs for now */
304 int num_lookaheads; /* num of levels in look-ahead */
305 yes_no_t lookahead_etree; /* use etree computed from the
306 serial symbolic factorization */
307 yes_no_t SymPattern; /* symmetric factorization */
311typedef struct e_node {
312 int_t size; /* length of the memory mem[] that has been used */
313 void *mem; /* pointer to the new malloc'd store */
316typedef struct {
317 int_t size;
318 int_t used;
319 int_t top1; /* grow upward, relative to &array[0] */
320 int_t top2; /* grow downward */
321 void *array;
324typedef struct {
325 int *panel_histo; /* histogram of panel size distribution */
326 double *utime; /* running time at various phases */
327 flops_t *ops; /* operation count at various phases */
328 int TinyPivots; /* number of tiny pivots */
329 int RefineSteps; /* number of iterative refinement steps */
330 int expansions; /* number of memory expansions */
333typedef struct {
334 float for_lu;
335 float total_needed;
339typedef struct {
340 int *xsup; /* supernode and column mapping */
341 int *supno;
342 int_t *lsub; /* compressed L subscripts */
343 int_t *xlsub;
344 void *lusup; /* L supernodes */
345 int_t *xlusup;
346 void *ucol; /* U columns */
347 int_t *usub;
348 int_t *xusub;
349 int_t nzlmax; /* current max size of lsub */
350 int_t nzumax; /* " " " ucol */
351 int_t nzlumax; /* " " " lusup */
352 int n; /* number of columns in the matrix */
353 LU_space_t MemModel; /* 0 - system malloc'd; 1 - user provided */
354 int num_expansions;
355 ExpHeader *expanders; /* Array of pointers to 4 types of memory */
356 LU_stack_t stack; /* use user supplied memory */
357} GlobalLU_t;
358
359
360/***********************************************************************
361 * Prototypes
362 ***********************************************************************/
363#ifdef __cplusplus
364extern "C" {
365#endif
366
367extern int input_error(char *, int *);
368
374extern void Destroy_Dense_Matrix(SuperMatrix *);
375extern void get_perm_c(int, SuperMatrix *, int *);
376extern void set_default_options(superlu_options_t *options);
377extern void ilu_set_default_options(superlu_options_t *options);
378extern void sp_preorder (superlu_options_t *, SuperMatrix*, int*, int*,
379 SuperMatrix*);
380extern void superlu_abort_and_exit(char*);
381extern void *superlu_malloc (size_t);
382extern int *int32Malloc (int);
383extern int *int32Calloc (int);
384extern int_t *intMalloc (int_t);
385extern int_t *intCalloc (int_t);
386extern void superlu_free (void*);
387extern void SetIWork (int, int, int, int *, int **, int **, int_t **xplore,
388 int **, int **, int_t **xprune, int **);
389extern int sp_coletree (int_t *, int_t *, int_t *, int, int, int *);
390extern void relax_snode (const int, int *, const int, int *, int *);
391extern void heap_relax_snode (const int, int *, const int, int *, int *);
392extern int mark_relax(int, int *, int *, int_t *, int_t *, int_t *, int *);
393extern void countnz(const int n, int_t *xprune, int_t *nnzL, int_t *nnzU, GlobalLU_t *);
394extern void ilu_countnz (const int, int_t *, int_t *, GlobalLU_t *);
395extern void fixupL (const int, const int *, GlobalLU_t *);
396extern void ilu_relax_snode (const int, int *, const int, int *,
397 int *, int *);
398extern void ilu_heap_relax_snode (const int, int *, const int, int *,
399 int *, int*);
400extern void resetrep_col (const int, const int *, int *);
401extern int spcoletree (int *, int *, int *, int, int, int *);
402extern int *TreePostorder (int, int *);
403extern double SuperLU_timer_ (void);
404extern int sp_ienv (int);
405extern int xerbla_ (char *, int *);
406extern void ifill (int *, int, int);
407extern void snode_profile (int, int *);
408extern void super_stats (int, int *);
409extern void check_repfnz(int, int, int, int *);
410extern void PrintSumm (char *, int, int, int);
411extern void StatInit(SuperLUStat_t *);
412extern void StatPrint (SuperLUStat_t *);
413extern void StatFree(SuperLUStat_t *);
414extern void print_panel_seg(int, int, int, int, int *, int *);
415extern int print_int_vec(char *,int, int *);
416extern int slu_PrintInt10(char *, int, int *);
417extern int check_perm(char *what, int n, int *perm);
418
419#ifdef __cplusplus
420 }
421#endif
422
423#endif /* __SUPERLU_UTIL */
void snode_profile(int, int *)
int spcoletree(int *, int *, int *, int, int, int *)
void superlu_free(void *)
Definition: memory.c:94
void ilu_relax_snode(const int, int *, const int, int *, int *, int *)
Definition: ilu_relax_snode.c:33
void get_perm_c(int, SuperMatrix *, int *)
Definition: get_perm_c.c:437
void countnz(const int n, int_t *xprune, int_t *nnzL, int_t *nnzU, GlobalLU_t *)
Count the total number of nonzeros in factors L and U, and in the symmetrically reduced L.
Definition: util.c:184
int * int32Calloc(int)
Definition: memory.c:166
void Destroy_SuperMatrix_Store(SuperMatrix *)
Deallocate the structure pointing to the actual storage of the matrix.
Definition: util.c:114
unsigned char Logical
Definition: slu_util.h:146
void StatInit(SuperLUStat_t *)
Definition: util.c:316
void Destroy_CompCol_Matrix(SuperMatrix *)
Definition: util.c:120
void PrintSumm(char *, int, int, int)
Print a summary of the testing results.
Definition: util.c:478
void set_default_options(superlu_options_t *options)
Set the default values for the options argument.
Definition: util.c:48
void print_panel_seg(int, int, int, int, int *, int *)
Diagnostic print of segment info after panel_dfs().
Definition: util.c:300
int_t * intMalloc(int_t)
Definition: memory.c:156
void Destroy_CompCol_Permuted(SuperMatrix *)
A is of type Stype==NCP.
Definition: util.c:151
void * superlu_malloc(size_t)
Definition: memory.c:87
int sp_coletree(int_t *, int_t *, int_t *, int, int, int *)
Definition: sp_coletree.c:169
void fixupL(const int, const int *, GlobalLU_t *)
Fix up the data storage lsub for L-subscripts. It removes the subscript sets for structural pruning,...
Definition: util.c:263
int sp_ienv(int)
sp_ienv() is inquired to choose machine-dependent parameters for the local environment.
Definition: sp_ienv.c:69
int input_error(char *, int *)
Definition: input_error.c:45
int print_int_vec(char *, int, int *)
Definition: util.c:491
int xerbla_(char *, int *)
double SuperLU_timer_(void)
Timer function.
Definition: superlu_timer.c:87
void Destroy_CompRow_Matrix(SuperMatrix *)
Definition: util.c:129
void check_repfnz(int, int, int, int *)
Check whether repfnz[] == EMPTY after reset.
Definition: util.c:462
void Destroy_Dense_Matrix(SuperMatrix *)
A is of type Stype==DN.
Definition: util.c:160
void StatPrint(SuperLUStat_t *)
Definition: util.c:350
int mark_relax(int, int *, int *, int_t *, int_t *, int_t *, int *)
Definition: mark_relax.c:30
void ilu_countnz(const int, int_t *, int_t *, GlobalLU_t *)
Count the total number of nonzeros in factors L and U.
Definition: util.c:228
void relax_snode(const int, int *, const int, int *, int *)
Definition: relax_snode.c:44
float flops_t
Definition: slu_util.h:145
void ifill(int *, int, int)
Fills an integer array with a given value.
Definition: util.c:399
void StatFree(SuperLUStat_t *)
Definition: util.c:373
void resetrep_col(const int, const int *, int *)
Reset repfnz[] for the current column.
Definition: util.c:170
void superlu_abort_and_exit(char *)
Global statistics variale.
Definition: util.c:40
void SetIWork(int, int, int, int *, int **, int **, int_t **xplore, int **, int **, int_t **xprune, int **)
Set up pointers for integer working arrays.
Definition: memory.c:105
void super_stats(int, int *)
Definition: util.c:411
int check_perm(char *what, int n, int *perm)
Definition: util.c:513
void ilu_heap_relax_snode(const int, int *, const int, int *, int *, int *)
Definition: ilu_heap_relax_snode.c:35
int_t * intCalloc(int_t)
Definition: memory.c:178
void Destroy_SuperNode_Matrix(SuperMatrix *)
Definition: util.c:138
int slu_PrintInt10(char *, int, int *)
Definition: util.c:499
void heap_relax_snode(const int, int *, const int, int *, int *)
Definition: heap_relax_snode.c:46
void sp_preorder(superlu_options_t *, SuperMatrix *, int *, int *, SuperMatrix *)
Definition: sp_preorder.c:72
int * TreePostorder(int, int *)
Definition: sp_coletree.c:325
int * int32Malloc(int)
Definition: memory.c:146
void ilu_set_default_options(superlu_options_t *options)
Set the default values for the options argument for ILU.
Definition: util.c:64
struct e_node ExpHeader
Headers for 4 types of dynamatically managed memory.
Definition: slu_util.h:336
Definition: slu_util.h:313
Definition: slu_util.h:321
Definition: supermatrix.h:54
Headers for 4 types of dynamatically managed memory.
Definition: slu_util.h:308
int_t size
Definition: slu_util.h:309
void * mem
Definition: slu_util.h:310
Definition: slu_util.h:330
Definition: slu_util.h:277
int64_t int_t
Definition: superlu_config.h:18
enum constants header file
trans_t
Definition: superlu_enum_consts.h:34
milu_t
Definition: superlu_enum_consts.h:46
LU_space_t
Definition: superlu_enum_consts.h:40
IterRefine_t
Definition: superlu_enum_consts.h:36
rowperm_t
Definition: superlu_enum_consts.h:31
colperm_t
Definition: superlu_enum_consts.h:32
fact_t
Definition: superlu_enum_consts.h:30
norm_t
Definition: superlu_enum_consts.h:41
yes_no_t
Definition: superlu_enum_consts.h:29