1 #ifndef SPARSKIT_H 2 #define SPARSKIT_H 3 4 #include "ListUtils.h" 5 6 #define ELAP 1 7 #define KUL 2 8 9 #define NONE 0 10 11 #define SPARSE 1 12 #define DENSE 2 13 14 #define CSR 1 /* Compressed Sparse Row */ 15 #define CSC 2 /* Compressed Sparse Column */ 16 #define MSR 3 /* Modified Sparse Row */ 17 #define COO 4 /* Coordinate */ 18 19 #define CG 1 20 #define CGNR 2 21 #define BCG 3 22 #define DBCG 4 23 #define BCGSTAB 5 24 #define TFQMR 6 25 #define FOM 7 26 #define GMRES 8 27 #define FGMRES 9 28 #define DQGMRES 10 29 #define LU 11 30 #define PGMRES 12 31 32 #define ILUT 1 33 #define ILUTP 2 34 #define ILUD 3 35 #define ILUDP 4 36 #define ILUK 5 37 #define ILU0 6 38 #define MILU0 7 39 #define DIAGONAL 8 40 41 #define RCMK 1 42 43 #define DIAG_SCALING 1 44 #define MAX_SCALING 2 45 #define NORM1_SCALING 3 46 #define NORM2_SCALING 4 47 48 #if defined(HAVE_ILU_FLOAT) 49 #define sscalar float 50 #else 51 #define sscalar double 52 #endif 53 54 typedef struct { 55 /* sparse matrix */ 56 List_T *a; 57 List_T *jptr, *ai, *ptr; 58 59 /* permuted matrix */ 60 double *a_rcmk ; 61 int *ia_rcmk, *ja_rcmk; 62 63 /* permutation vectors */ 64 int *permr, *permp, *rpermr; 65 66 /* ILU decomposition */ 67 sscalar *alu; 68 int *jlu, *ju; 69 }Sparse_Matrix; 70 71 typedef struct { 72 int LU_Exist; 73 double *a, *lu; 74 }Dense_Matrix; 75 76 typedef struct{ 77 int T, N, changed, ILU_Exists, notranspose, scaled; 78 double *rowscal, *colscal; 79 Sparse_Matrix S; 80 Dense_Matrix F; 81 }Matrix; 82 83 typedef struct { 84 int Matrix_Format; 85 int Matrix_Printing; 86 int Matrix_Storage; 87 int Scaling ; 88 int Renumbering_Technique; 89 int Preconditioner; 90 int Preconditioner_Position; 91 int Nb_Fill; 92 double Dropping_Tolerance; 93 double Permutation_Tolerance; 94 double Diagonal_Compensation; 95 int Re_Use_ILU; 96 int Algorithm; 97 int Krylov_Size; 98 double IC_Acceleration; 99 int Iterative_Improvement; 100 int Re_Use_LU; 101 int Nb_Iter_Max; 102 double Stopping_Test; 103 }Solver_Params; 104 105 void init_solver(Solver_Params *p, const char *name); 106 void init_solver_option(Solver_Params *p, const char *name, const char *value); 107 108 void init_matrix(int Nb, Matrix *M, Solver_Params *p); 109 void init_vector(int Nb, double **V); 110 111 void free_matrix(Matrix *M); 112 113 void zero_matrix(Matrix *M); 114 void zero_matrix2(Matrix *M); 115 void zero_vector(int Nb, double *V); 116 117 void copy_vector(int Nb, double *U, double *V); 118 119 void add_vector_vector(int Nb, double *U, double *V); 120 void add_vector_prod_vector_double(int Nb, double *U, double *V, double d); 121 void add_matrix_double(Matrix *M, int il, int ic, double val); 122 void add_matrix_matrix(Matrix *M, Matrix *N); 123 void add_matrix_prod_matrix_double(Matrix *M, Matrix *N, double d); 124 125 void sub_vector_vector_1(int Nb, double *U, double *V); 126 void sub_vector_vector_2(int Nb, double *U, double *V); 127 128 void prod_vector_double(int Nb, double *U, double a); 129 void prodsc_vector_vector(int Nb, double *U, double *V, double *prosca); 130 void prodsc_vectorconj_vector(int Nb, double *U, double *V, double *proscar, double *proscai); 131 void prod_matrix_vector(Matrix *M, double *v, double *res); 132 void prod_matrix_double(Matrix *M, double v); 133 void multi_prod_matrix_double(int n, Matrix **Mat, double *coef, Matrix *MatRes); 134 void multi_prod_vector_double(int n, int Sizevec, double **Vec, double *coef, double *VecRes); 135 void multi_prod_matrix_vector(int n, int Sizevec, Matrix **Mat, double **Vec, double *VecRes); 136 137 void norm2_vector(int Nb, double *U, double *norm); 138 void norminf_vector(int Nb, double *U, double *norm); 139 140 void identity_matrix(Matrix *M); 141 142 void scale_matrix(int scaling, Matrix *M); 143 void scale_vector(int ROW_or_COLUMN, Matrix *M, double *V); 144 145 void get_column_in_matrix(Matrix *M, int col, double *V); 146 void get_element_in_matrix(Matrix *M, int row, int col, double *V); 147 148 void formatted_write_matrix(FILE *pfile, Matrix *M, int style); 149 void formatted_write_vector(FILE *pfile, int Nb, double *V, int style); 150 void formatted_read_matrix(Matrix *M, const char *name, const char *ext, int style); 151 void formatted_read_vector(int Nb, double *V, const char *name, const char *ext, int style); 152 153 void binary_write_matrix(Matrix *M, const char *name, const char *ext); 154 void binary_write_vector(int Nb, double *V, const char *name, const char *ext); 155 void binary_read_matrix(Matrix *M, const char *name, const char *ext); 156 void binary_read_vector(int Nb, double **V, const char *name, const char *ext); 157 158 void print_matrix(Matrix *M); 159 void print_vector(double *v, int N); 160 void print_vector_int(int *v, int N); 161 162 void print_matrix_info_CSR(int N, int *jptr, int *ai); 163 void print_matrix_info_MSR(int N, sscalar *a, int *jptr); 164 void print_matrix_info_DENSE(int N); 165 166 void csr_format(Sparse_Matrix *M, int N); 167 void restore_format(Sparse_Matrix *M); 168 169 void solve_matrix(Matrix *M, Solver_Params *p, double *b, double *x); 170 void print_parametres(Solver_Params *p); 171 172 #endif 173