SRC/slu_util.h

Go to the documentation of this file.
00001 
00011 #ifndef __SUPERLU_UTIL /* allow multiple inclusions */
00012 #define __SUPERLU_UTIL
00013 
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <string.h>
00017 /*
00018 #ifndef __STDC__
00019 #include <malloc.h>
00020 #endif
00021 */
00022 #include <assert.h>
00023 
00024 /***********************************************************************
00025  * Macros
00026  ***********************************************************************/
00027 #define FIRSTCOL_OF_SNODE(i)    (xsup[i])
00028 /* No of marker arrays used in the symbolic factorization,
00029    each of size n */
00030 #define NO_MARKER     3
00031 #define NUM_TEMPV(m,w,t,b)  ( SUPERLU_MAX(m, (t + b)*w) )
00032 
00033 #ifndef USER_ABORT
00034 #define USER_ABORT(msg) superlu_abort_and_exit(msg)
00035 #endif
00036 
00037 #define ABORT(err_msg) \
00038  { char msg[256];\
00039    sprintf(msg,"%s at line %d in file %s\n",err_msg,__LINE__, __FILE__);\
00040    USER_ABORT(msg); }
00041 
00042 
00043 #ifndef USER_MALLOC
00044 #if 1
00045 #define USER_MALLOC(size) superlu_malloc(size)
00046 #else
00047 /* The following may check out some uninitialized data */
00048 #define USER_MALLOC(size) memset (superlu_malloc(size), '\x0F', size)
00049 #endif
00050 #endif
00051 
00052 #define SUPERLU_MALLOC(size) USER_MALLOC(size)
00053 
00054 #ifndef USER_FREE
00055 #define USER_FREE(addr) superlu_free(addr)
00056 #endif
00057 
00058 #define SUPERLU_FREE(addr) USER_FREE(addr)
00059 
00060 #define CHECK_MALLOC(where) {                 \
00061     extern int superlu_malloc_total;        \
00062     printf("%s: malloc_total %d Bytes\n",     \
00063            where, superlu_malloc_total); \
00064 }
00065 
00066 #define SUPERLU_MAX(x, y)       ( (x) > (y) ? (x) : (y) )
00067 #define SUPERLU_MIN(x, y)       ( (x) < (y) ? (x) : (y) )
00068 
00069 /*********************************************************
00070  * Macros used for easy access of sparse matrix entries. *
00071  *********************************************************/
00072 #define L_SUB_START(col)     ( Lstore->rowind_colptr[col] )
00073 #define L_SUB(ptr)           ( Lstore->rowind[ptr] )
00074 #define L_NZ_START(col)      ( Lstore->nzval_colptr[col] )
00075 #define L_FST_SUPC(superno)  ( Lstore->sup_to_col[superno] )
00076 #define U_NZ_START(col)      ( Ustore->colptr[col] )
00077 #define U_SUB(ptr)           ( Ustore->rowind[ptr] )
00078 
00079 
00080 /***********************************************************************
00081  * Constants 
00082  ***********************************************************************/
00083 #define EMPTY   (-1)
00084 /*#define NO    (-1)*/
00085 #define FALSE   0
00086 #define TRUE    1
00087 
00088 /***********************************************************************
00089  * Enumerate types
00090  ***********************************************************************/
00091 typedef enum {NO, YES}                                          yes_no_t;
00092 typedef enum {DOFACT, SamePattern, SamePattern_SameRowPerm, FACTORED} fact_t;
00093 typedef enum {NOROWPERM, LargeDiag, MY_PERMR}                   rowperm_t;
00094 typedef enum {NATURAL, MMD_ATA, MMD_AT_PLUS_A, COLAMD, MY_PERMC}colperm_t;
00095 typedef enum {NOTRANS, TRANS, CONJ}                             trans_t;
00096 typedef enum {NOEQUIL, ROW, COL, BOTH}                          DiagScale_t;
00097 typedef enum {NOREFINE, SINGLE=1, DOUBLE, EXTRA}                IterRefine_t;
00098 typedef enum {LUSUP, UCOL, LSUB, USUB}                          MemType;
00099 typedef enum {HEAD, TAIL}                                       stack_end_t;
00100 typedef enum {SYSTEM, USER}                                     LU_space_t;
00101 
00102 /* 
00103  * The following enumerate type is used by the statistics variable 
00104  * to keep track of flop count and time spent at various stages.
00105  *
00106  * Note that not all of the fields are disjoint.
00107  */
00108 typedef enum {
00109     COLPERM, /* find a column ordering that minimizes fills */
00110     RELAX,   /* find artificial supernodes */
00111     ETREE,   /* compute column etree */
00112     EQUIL,   /* equilibrate the original matrix */
00113     FACT,    /* perform LU factorization */
00114     RCOND,   /* estimate reciprocal condition number */
00115     SOLVE,   /* forward and back solves */
00116     REFINE,  /* perform iterative refinement */
00117     TRSV,    /* fraction of FACT spent in xTRSV */
00118     GEMV,    /* fraction of FACT spent in xGEMV */
00119     FERR,    /* estimate error bounds after iterative refinement */
00120     NPHASES  /* total number of phases */
00121 } PhaseType;
00122 
00123 
00124 /***********************************************************************
00125  * Type definitions
00126  ***********************************************************************/
00127 typedef float    flops_t;
00128 typedef unsigned char Logical;
00129 
00130 /* 
00131  *-- This contains the options used to control the solve process.
00132  *
00133  * Fact   (fact_t)
00134  *        Specifies whether or not the factored form of the matrix
00135  *        A is supplied on entry, and if not, how the matrix A should
00136  *        be factorizaed.
00137  *        = DOFACT: The matrix A will be factorized from scratch, and the
00138  *             factors will be stored in L and U.
00139  *        = SamePattern: The matrix A will be factorized assuming
00140  *             that a factorization of a matrix with the same sparsity
00141  *             pattern was performed prior to this one. Therefore, this
00142  *             factorization will reuse column permutation vector 
00143  *             ScalePermstruct->perm_c and the column elimination tree
00144  *             LUstruct->etree.
00145  *        = SamePattern_SameRowPerm: The matrix A will be factorized
00146  *             assuming that a factorization of a matrix with the same
00147  *             sparsity pattern and similar numerical values was performed
00148  *             prior to this one. Therefore, this factorization will reuse
00149  *             both row and column scaling factors R and C, both row and
00150  *             column permutation vectors perm_r and perm_c, and the
00151  *             data structure set up from the previous symbolic factorization.
00152  *        = FACTORED: On entry, L, U, perm_r and perm_c contain the 
00153  *              factored form of A. If DiagScale is not NOEQUIL, the matrix
00154  *              A has been equilibrated with scaling factors R and C.
00155  *
00156  * Equil  (yes_no_t)
00157  *        Specifies whether to equilibrate the system (scale A's row and
00158  *        columns to have unit norm).
00159  *
00160  * ColPerm (colperm_t)
00161  *        Specifies what type of column permutation to use to reduce fill.
00162  *        = NATURAL: use the natural ordering 
00163  *        = MMD_ATA: use minimum degree ordering on structure of A'*A
00164  *        = MMD_AT_PLUS_A: use minimum degree ordering on structure of A'+A
00165  *        = COLAMD: use approximate minimum degree column ordering
00166  *        = MY_PERMC: use the ordering specified in ScalePermstruct->perm_c[]
00167  *         
00168  * Trans  (trans_t)
00169  *        Specifies the form of the system of equations:
00170  *        = NOTRANS: A * X = B        (No transpose)
00171  *        = TRANS:   A**T * X = B     (Transpose)
00172  *        = CONJ:    A**H * X = B     (Transpose)
00173  *
00174  * IterRefine (IterRefine_t)
00175  *        Specifies whether to perform iterative refinement.
00176  *        = NO: no iterative refinement
00177  *        = WorkingPrec: perform iterative refinement in working precision
00178  *        = ExtraPrec: perform iterative refinement in extra precision
00179  *
00180  * DiagPivotThresh (double, in [0.0, 1.0]) (only for sequential SuperLU)
00181  *        Specifies the threshold used for a diagonal entry to be an
00182  *        acceptable pivot.
00183  *
00184  * PivotGrowth (yes_no_t)
00185  *        Specifies whether to compute the reciprocal pivot growth.
00186  *
00187  * ConditionNumber (ues_no_t)
00188  *        Specifies whether to compute the reciprocal condition number.
00189  *
00190  * RowPerm (rowperm_t) (only for SuperLU_DIST)
00191  *        Specifies whether to permute rows of the original matrix.
00192  *        = NO: not to permute the rows
00193  *        = LargeDiag: make the diagonal large relative to the off-diagonal
00194  *        = MY_PERMR: use the permutation given in ScalePermstruct->perm_r[]
00195  *           
00196  * SymmetricMode (yest_no_t)
00197  *        Specifies whether to use symmetric mode.
00198  *
00199  * PrintStat (yes_no_t)
00200  *        Specifies whether to print the solver's statistics.
00201  *
00202  * ReplaceTinyPivot (yes_no_t) (only for SuperLU_DIST)
00203  *        Specifies whether to replace the tiny diagonals by
00204  *        sqrt(epsilon)*||A|| during LU factorization.
00205  *
00206  * SolveInitialized (yes_no_t) (only for SuperLU_DIST)
00207  *        Specifies whether the initialization has been performed to the
00208  *        triangular solve.
00209  *
00210  * RefineInitialized (yes_no_t) (only for SuperLU_DIST)
00211  *        Specifies whether the initialization has been performed to the
00212  *        sparse matrix-vector multiplication routine needed in iterative
00213  *        refinement.
00214  */
00215 typedef struct {
00216     fact_t        Fact;
00217     yes_no_t      Equil;
00218     colperm_t     ColPerm;
00219     trans_t       Trans;
00220     IterRefine_t  IterRefine;
00221     double        DiagPivotThresh;
00222     yes_no_t      PivotGrowth;
00223     yes_no_t      ConditionNumber;
00224     rowperm_t     RowPerm;
00225     yes_no_t      SymmetricMode;
00226     yes_no_t      PrintStat;
00227     yes_no_t      ReplaceTinyPivot;
00228     yes_no_t      SolveInitialized;
00229     yes_no_t      RefineInitialized;
00230 } superlu_options_t;
00231 
00232 typedef struct {
00233     int     *panel_histo; /* histogram of panel size distribution */
00234     double  *utime;       /* running time at various phases */
00235     flops_t *ops;         /* operation count at various phases */
00236     int     TinyPivots;   /* number of tiny pivots */
00237     int     RefineSteps;  /* number of iterative refinement steps */
00238 } SuperLUStat_t;
00239 
00240 typedef struct {
00241     float for_lu;
00242     float total_needed;
00243     int   expansions;
00244 } mem_usage_t;
00245 
00246 
00247 /***********************************************************************
00248  * Prototypes
00249  ***********************************************************************/
00250 #ifdef __cplusplus
00251 extern "C" {
00252 #endif
00253 
00254 extern void    Destroy_SuperMatrix_Store(SuperMatrix *);
00255 extern void    Destroy_CompCol_Matrix(SuperMatrix *);
00256 extern void    Destroy_CompRow_Matrix(SuperMatrix *);
00257 extern void    Destroy_SuperNode_Matrix(SuperMatrix *);
00258 extern void    Destroy_CompCol_Permuted(SuperMatrix *);
00259 extern void    Destroy_Dense_Matrix(SuperMatrix *);
00260 extern void    get_perm_c(int, SuperMatrix *, int *);
00261 extern void    set_default_options(superlu_options_t *options);
00262 extern void    sp_preorder (superlu_options_t *, SuperMatrix*, int*, int*,
00263                             SuperMatrix*);
00264 extern void    superlu_abort_and_exit(char*);
00265 extern void    *superlu_malloc (size_t);
00266 extern int     *intMalloc (int);
00267 extern int     *intCalloc (int);
00268 extern void    superlu_free (void*);
00269 extern void    SetIWork (int, int, int, int *, int **, int **, int **,
00270                          int **, int **, int **, int **);
00271 extern int     sp_coletree (int *, int *, int *, int, int, int *);
00272 extern void    relax_snode (const int, int *, const int, int *, int *);
00273 extern void    heap_relax_snode (const int, int *, const int, int *, int *);
00274 extern void    resetrep_col (const int, const int *, int *);
00275 extern int     spcoletree (int *, int *, int *, int, int, int *);
00276 extern int     *TreePostorder (int, int *);
00277 extern double  SuperLU_timer_ ();
00278 extern int     sp_ienv (int);
00279 extern int     lsame_ (char *, char *);
00280 extern int     xerbla_ (char *, int *);
00281 extern void    ifill (int *, int, int);
00282 extern void    snode_profile (int, int *);
00283 extern void    super_stats (int, int *);
00284 extern void    PrintSumm (char *, int, int, int);
00285 extern void    StatInit(SuperLUStat_t *);
00286 extern void    StatPrint (SuperLUStat_t *);
00287 extern void    StatFree(SuperLUStat_t *);
00288 extern void    print_panel_seg(int, int, int, int, int *, int *);
00289 extern void    check_repfnz(int, int, int, int *);
00290 
00291 #ifdef __cplusplus
00292   }
00293 #endif
00294 
00295 #endif /* __SUPERLU_UTIL */

Generated on Fri Aug 1 22:40:39 2008 for SuperLU by  doxygen 1.4.6