Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
message.c
Go to the documentation of this file.
1 
8 #include <math.h>
9 
10 #include "fasp.h"
11 #include "fasp_functs.h"
12 
13 /*---------------------------------*/
14 /*-- Public Functions --*/
15 /*---------------------------------*/
16 
36 void print_itinfo (const INT ptrlvl,
37  const INT stop_type,
38  const INT iter,
39  const REAL relres,
40  const REAL absres,
41  const REAL factor)
42 {
43  if ( ptrlvl >= PRINT_SOME ) {
44 
45  if ( iter > 0 ) {
46  printf("%6d | %13.6e | %13.6e | %10.4f\n", iter, relres, absres, factor);
47  }
48  else { // iter = 0: initial guess
49  printf("-----------------------------------------------------------\n");
50  switch (stop_type) {
51  case STOP_REL_RES:
52  printf("It Num | ||r||/||b|| | ||r|| | Conv. Factor\n");
53  break;
54  case STOP_REL_PRECRES:
55  printf("It Num | ||r||_B/||b||_B | ||r||_B | Conv. Factor\n");
56  break;
57  case STOP_MOD_REL_RES:
58  printf("It Num | ||r||/||x|| | ||r|| | Conv. Factor\n");
59  break;
60  }
61  printf("-----------------------------------------------------------\n");
62  printf("%6d | %13.6e | %13.6e | -.-- \n", iter, relres, absres);
63  } // end if iter
64 
65  } // end if ptrlvl
66 }
67 
80  const SHORT prtlvl)
81 {
82  const SHORT max_levels=mgl->num_levels;
83  SHORT level;
84  REAL gridcom=0.0, opcom=0.0;
85 
86  if ( prtlvl >= PRINT_SOME ) {
87 
88  printf("-----------------------------------------------------------\n");
89  printf(" Level Num of rows Num of nonzeros Avg. NNZ / row \n");
90  printf("-----------------------------------------------------------\n");
91 
92  for ( level = 0; level < max_levels; ++level) {
93  REAL AvgNNZ = (REAL) mgl[level].A.nnz/mgl[level].A.row;
94  printf("%5d %13d %17d %14.2f\n",
95  level, mgl[level].A.row, mgl[level].A.nnz, AvgNNZ);
96  gridcom += mgl[level].A.row;
97  opcom += mgl[level].A.nnz;
98  }
99  printf("-----------------------------------------------------------\n");
100 
101  gridcom /= mgl[0].A.row;
102  opcom /= mgl[0].A.nnz;
103  printf(" Grid complexity = %.3f |", gridcom);
104  printf(" Operator complexity = %.3f\n", opcom);
105 
106  printf("-----------------------------------------------------------\n");
107 
108  }
109 }
110 
123  const SHORT prtlvl)
124 {
125  const SHORT max_levels = mgl->num_levels;
126  SHORT level;
127  REAL gridcom = 0.0, opcom = 0.0;
128 
129  if ( prtlvl >= PRINT_SOME ) {
130 
131  printf("-----------------------------------------------------------\n");
132  printf(" Level Num of rows Num of nonzeros Avg. NNZ / row \n");
133  printf("-----------------------------------------------------------\n");
134 
135  for ( level = 0; level < max_levels; ++level ) {
136  REAL AvgNNZ = (REAL) mgl[level].A.NNZ/mgl[level].A.ROW;
137  printf("%5d %13d %17d %14.2f\n",
138  level,mgl[level].A.ROW, mgl[level].A.NNZ, AvgNNZ);
139  gridcom += mgl[level].A.ROW;
140  opcom += mgl[level].A.NNZ;
141  }
142  printf("-----------------------------------------------------------\n");
143 
144  gridcom /= mgl[0].A.ROW;
145  opcom /= mgl[0].A.NNZ;
146  printf(" Grid complexity = %.3f |", gridcom);
147  printf(" Operator complexity = %.3f\n", opcom);
148 
149  printf("-----------------------------------------------------------\n");
150 
151  }
152 }
153 
165 void print_cputime (const char *message,
166  const REAL cputime)
167 {
168  printf("%s costs %.4f seconds.\n", message, cputime);
169 }
170 
182 void print_message (const INT ptrlvl,
183  const char *message)
184 {
185  if ( ptrlvl > PRINT_NONE ) printf("%s", message);
186 }
187 
199 void fasp_chkerr (const SHORT status,
200  const char *fctname)
201 {
202  if ( status >= 0 ) return; // No error at all
203 
204  switch ( status ) {
205  case ERROR_OPEN_FILE:
206  printf("### ERROR: %s -- Cannot open file!\n", fctname);
207  break;
208  case ERROR_WRONG_FILE:
209  printf("### ERROR: %s -- Wrong file format!\n", fctname);
210  break;
211  case ERROR_INPUT_PAR:
212  printf("### ERROR: %s -- Wrong input arguments!\n", fctname);
213  break;
214  case ERROR_REGRESS:
215  printf("### ERROR: %s -- Regression test failed!\n", fctname);
216  break;
217  case ERROR_ALLOC_MEM:
218  printf("### ERROR: %s -- Cannot allocate memory!\n", fctname);
219  break;
220  case ERROR_NUM_BLOCKS:
221  printf("### ERROR: %s -- Wrong number of blocks!\n", fctname);
222  break;
224  printf("### ERROR: %s -- Data structure mismatch!\n", fctname);
225  break;
226  case ERROR_DATA_ZERODIAG:
227  printf("### ERROR: %s -- Matrix has zero diagonal entries!\n", fctname);
228  break;
229  case ERROR_DUMMY_VAR:
230  printf("### ERROR: %s -- Unexpected input argument!\n", fctname);
231  break;
233  printf("### ERROR: %s -- Unknown AMG interpolation type!\n", fctname);
234  break;
236  printf("### ERROR: %s -- Unknown AMG coarsening type!\n", fctname);
237  break;
239  printf("### ERROR: %s -- Unknown AMG smoother type!\n", fctname);
240  break;
241  case ERROR_SOLVER_TYPE:
242  printf("### ERROR: %s -- Unknown solver type!\n", fctname);
243  break;
245  printf("### ERROR: %s -- Unknown preconditioner type!\n", fctname);
246  break;
247  case ERROR_SOLVER_STAG:
248  printf("### ERROR: %s -- Solver stagnation error!\n", fctname);
249  break;
251  printf("### ERROR: %s -- Solution is close to zero!\n", fctname);
252  break;
254  printf("### ERROR: %s -- Tol is too small for the solver!\n", fctname);
255  break;
257  printf("### ERROR: %s -- ILU setup failed!\n", fctname);
258  break;
259  case ERROR_SOLVER_MAXIT:
260  printf("### ERROR: %s -- Max iteration number reached!\n", fctname);
261  break;
262  case ERROR_SOLVER_EXIT:
263  printf("### ERROR: %s -- Solver exited unexpected!\n", fctname);
264  break;
265  case ERROR_SOLVER_MISC:
266  printf("### ERROR: %s -- Unknown solver runtime error!\n", fctname);
267  break;
268  case ERROR_MISC:
269  printf("### ERROR: %s -- Unknown error occurred!\n", fctname);
270  break;
271  case ERROR_QUAD_TYPE:
272  printf("### ERROR: %s -- Unknown quadrature rules!\n", fctname);
273  break;
274  case ERROR_QUAD_DIM:
275  printf("### ERROR: %s -- Num of quad points is not supported!\n", fctname);
276  break;
277  case ERROR_UNKNOWN:
278  printf("### ERROR: %s -- Function does not exit successfully!\n", fctname);
279  break;
280  default:
281  break;
282  }
283 
284  exit(status);
285 }
286 
287 /*---------------------------------*/
288 /*-- End of File --*/
289 /*---------------------------------*/
void fasp_chkerr(const SHORT status, const char *fctname)
Check error status and print out error messages before quit.
Definition: message.c:199
#define ERROR_OPEN_FILE
Definition: fasp_const.h:29
#define ERROR_INPUT_PAR
Definition: fasp_const.h:31
#define REAL
Definition: fasp.h:67
#define ERROR_DATA_ZERODIAG
Definition: fasp_const.h:39
dBSRmat A
pointer to the matrix at level level_num
Definition: fasp_block.h:207
#define ERROR_AMG_SMOOTH_TYPE
Definition: fasp_const.h:43
SHORT num_levels
number of levels in use <= max_levels
Definition: fasp.h:730
#define ERROR_UNKNOWN
Definition: fasp_const.h:62
#define ERROR_AMG_INTERP_TYPE
Definition: fasp_const.h:42
#define ERROR_QUAD_TYPE
Definition: fasp_const.h:57
#define STOP_MOD_REL_RES
Definition: fasp_const.h:133
void print_amgcomplexity_bsr(AMG_data_bsr *mgl, const SHORT prtlvl)
Print complexities of AMG method for BSR matrices.
Definition: message.c:122
#define ERROR_WRONG_FILE
Definition: fasp_const.h:30
#define ERROR_QUAD_DIM
Definition: fasp_const.h:58
#define ERROR_SOLVER_MISC
Definition: fasp_const.h:53
#define ERROR_SOLVER_MAXIT
Definition: fasp_const.h:54
#define PRINT_SOME
Definition: fasp_const.h:81
#define INT
Definition: fasp.h:64
void print_itinfo(const INT ptrlvl, const INT stop_type, const INT iter, const REAL relres, const REAL absres, const REAL factor)
Print out iteration information for iterative solvers.
Definition: message.c:36
#define ERROR_REGRESS
Definition: fasp_const.h:32
#define ERROR_SOLVER_TYPE
Definition: fasp_const.h:47
Data for multigrid levels. (BSR format)
Definition: fasp_block.h:198
INT NNZ
number of nonzero sub-blocks in matrix A, NNZ
Definition: fasp_block.h:53
#define STOP_REL_PRECRES
Definition: fasp_const.h:132
INT nnz
number of nonzero entries
Definition: fasp.h:157
#define ERROR_MISC
Definition: fasp_const.h:35
#define ERROR_SOLVER_ILUSETUP
Definition: fasp_const.h:52
Main header file for FASP.
#define ERROR_SOLVER_PRECTYPE
Definition: fasp_const.h:48
#define ERROR_ALLOC_MEM
Definition: fasp_const.h:37
void print_amgcomplexity(AMG_data *mgl, const SHORT prtlvl)
Print complexities of AMG method.
Definition: message.c:79
#define ERROR_NUM_BLOCKS
Definition: fasp_const.h:34
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Definition: fasp_const.h:79
INT row
row number of matrix A, m
Definition: fasp.h:151
#define ERROR_SOLVER_TOLSMALL
Definition: fasp_const.h:51
#define ERROR_SOLVER_SOLSTAG
Definition: fasp_const.h:50
#define ERROR_SOLVER_EXIT
Definition: fasp_const.h:55
#define ERROR_SOLVER_STAG
Definition: fasp_const.h:49
#define ERROR_AMG_COARSE_TYPE
Definition: fasp_const.h:44
#define STOP_REL_RES
Definition of iterative solver stopping criteria types.
Definition: fasp_const.h:131
#define ERROR_DUMMY_VAR
Definition: fasp_const.h:40
#define ERROR_DATA_STRUCTURE
Definition: fasp_const.h:38
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:63
dCSRmat A
pointer to the matrix at level level_num
Definition: fasp.h:735
void print_cputime(const char *message, const REAL cputime)
Print CPU walltime.
Definition: message.c:165
void print_message(const INT ptrlvl, const char *message)
Print output information if necessary.
Definition: message.c:182
INT num_levels
number of levels in use <= max_levels
Definition: fasp_block.h:204
Data for AMG solvers.
Definition: fasp.h:722
INT ROW
number of rows of sub-blocks in matrix A, M
Definition: fasp_block.h:47