17#include "fasp_functs.h"
41 printf(
"### DEBUG: nr = %d, nc = %d, nnz = %d\n", A->
row, A->
col, A->
nnz);
49 for (num_neg=i=0;i<m;++i) {
50 if (diag.
val[i]<0) num_neg++;
53 printf(
"Number of negative diagonal entries = %d\n", num_neg);
75 const INT *ia = A->
IA, *ja = A->
JA;
79 INT i,j,k,begin_row,end_row;
81 for ( i = 0; i < m; ++i ) {
82 begin_row = ia[i]; end_row = ia[i+1];
83 for ( k = begin_row; k < end_row; ++k ) {
87 printf(
"### ERROR: diag[%d] = %e, close to zero!\n", i, aj[k]);
117 const INT nnz = A->
IA[nn]-A->
IA[0];
123 for ( i=0; i<nn; ++i ) {
124 for ( j=A->
IA[i]; j<A->IA[i+1]; ++j ) rowp[j]=i;
127 for ( k=0, i=0; i<nn; ++i ) {
129 for ( j=A->
IA[i]; j<A->IA[i+1]; ++j ) {
130 if ( A->
JA[j]==i ) sum += A->
val[j];
131 if ( A->
JA[j]!=i ) sum -= fabs(A->
val[j]);
136 printf(
"Percentage of the diagonal-dominant rows is %3.2lf%s\n",
161 const REAL symmetry_tol = 1.0e-12;
163 INT *rowp,*rows[2],*cols[2];
172 const INT nnz = A->
IA[nn]-A->
IA[0];
175 printf(
"### ERROR: nnz=%d, ia[n]-ia[0]=%d, mismatch!\n",A->
nnz,nnz);
182 for (j=A->
IA[i];j<A->IA[i+1];++j) rowp[j]=i;
189 memcpy(rows[0],rowp,nnz*
sizeof(
INT));
190 memcpy(cols[0],A->
JA,nnz*
sizeof(
INT));
191 memcpy(vals[0],A->
val,nnz*
sizeof(
REAL));
203 memcpy(rows[0],rows[1],nnz*
sizeof(
INT));
204 memcpy(cols[0],cols[1],nnz*
sizeof(
INT));
205 memcpy(vals[0],vals[1],nnz*
sizeof(
REAL));
214 for (i=0;i<nnz;++i) {
215 rows[0][i]=rows[1][i]-rows[0][i];
222 cols[0][i]=cols[1][i]-cols[0][i];
230 dif=fabs(vals[1][i]-vals[0][i])/(fabs(vals[0][i])+fabs(vals[1][i]));
239 if (maxdif>symmetry_tol) type=-3;
243 printf(
"Matrix is symmetric with max relative difference is %1.3le\n",maxdif);
246 printf(
"Matrix has nonsymmetric pattern, check the %d-th, %d-th and %d-th rows and cols\n",
250 printf(
"Matrix has nonsymmetric pattern, check the %d-th, %d-th and %d-th cols and rows\n",
254 printf(
"Matrix is nonsymmetric with max relative difference is %1.3le\n",maxdif);
285 if ( (A->
IA == NULL) || (A->
JA == NULL) || (A->
val == NULL) ) {
286 printf(
"### ERROR: Something is wrong with the matrix!\n");
291 printf(
"### ERROR: Non-square CSR matrix!\n");
295 if ( ( A->
nnz <= 0 ) || ( A->
row == 0 ) || ( A->
col == 0 ) ) {
296 printf(
"### ERROR: Empty CSR matrix!\n");
300 for ( i = 0; i < A->
nnz; ++i ) {
301 if ( ( A->
JA[i] < 0 ) || ( A->
JA[i] >= A->
col ) ) {
302 printf(
"### ERROR: Wrong CSR matrix format!\n");
322 if ( (A->
IA == NULL) || (A->
JA == NULL) || (A->
val == NULL) ) {
323 printf(
"### ERROR: Something is wrong with the matrix!\n");
328 printf(
"### ERROR: Non-square CSR matrix!\n");
332 if ( (A->
nnz==0) || (A->
row==0) || (A->
col==0) ) {
333 printf(
"### ERROR: Empty CSR matrix!\n");
337 for (i=0;i<A->
nnz;++i) {
338 if ( (A->
JA[i]<0) || (A->
JA[i]-A->
col>=0) ) {
339 printf(
"### ERROR: Wrong CSR matrix format!\n");
360 INT i, j, j1, j2, start, end;
362 for ( i=0; i<n; ++i ) {
365 end = A->
IA[i+1] - 1;
367 for ( j=start; j<end-1; ++j ) {
368 j1 = A->
JA[j]; j2 = A->
JA[j + 1];
370 printf(
"### ERROR: Order in row %10d is wrong! %10d, %10d\n", i, j1, j2);
void fasp_mem_free(void *mem)
Free up previous allocated memory body and set pointer to NULL.
void * fasp_mem_calloc(const unsigned int size, const unsigned int type)
Allocate, initiate, and check memory.
void fasp_chkerr(const SHORT status, const char *fctname)
Check error status and print out error messages before quit.
void fasp_dvec_free(dvector *u)
Free vector data space of REAL type.
void fasp_dcsr_transpose(INT *row[2], INT *col[2], REAL *val[2], INT *nn, INT *tniz)
Transpose of a dCSRmat matrix.
void fasp_dcsr_getdiag(INT n, const dCSRmat *A, dvector *diag)
Get first n diagonal entries of a CSR matrix A.
void fasp_check_dCSRmat(const dCSRmat *A)
Check whether an dCSRmat matrix is supported or not.
INT fasp_check_diagdom(const dCSRmat *A)
Check whether a matrix is diagonally dominant.
SHORT fasp_check_iCSRmat(const iCSRmat *A)
Check whether an iCSRmat matrix is valid or not.
INT fasp_check_symm(const dCSRmat *A)
Check symmetry of a sparse matrix of CSR format.
INT fasp_check_diagpos(const dCSRmat *A)
Check positivity of diagonal entries of a CSR sparse matrix.
void fasp_check_ordering(dCSRmat *A)
Check whether each row of A is in ascending order w.r.t. column indices.
SHORT fasp_check_diagzero(const dCSRmat *A)
Check if a CSR sparse matrix has diagonal entries that are very close to zero.
Main header file for the FASP project.
#define SHORT
FASP integer and floating point numbers.
#define FASP_SUCCESS
Definition of return status and error messages.
#define ERROR_DATA_STRUCTURE
#define ERROR_DATA_ZERODIAG
Sparse matrix of REAL type in CSR format.
INT col
column of matrix A, n
REAL * val
nonzero entries of A
INT row
row number of matrix A, m
INT * IA
integer array of row pointers, the size is m+1
INT nnz
number of nonzero entries
INT * JA
integer array of column indexes, the size is nnz
Vector with n entries of REAL type.
REAL * val
actual vector entries
Sparse matrix of INT type in CSR format.
INT col
column of matrix A, n
INT row
row number of matrix A, m
INT * IA
integer array of row pointers, the size is m+1
INT nnz
number of nonzero entries
INT * JA
integer array of column indexes, the size is nnz
INT * val
nonzero entries of A