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