Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
BlaSparseCSR.c File Reference

Sparse matrix operations for dCSRmat matrices. More...

#include <math.h>
#include <time.h>
#include "fasp.h"
#include "fasp_functs.h"

Go to the source code of this file.

Functions

dCSRmat fasp_dcsr_create (const INT m, const INT n, const INT nnz)
 Create CSR sparse matrix data memory space. More...
 
iCSRmat fasp_icsr_create (const INT m, const INT n, const INT nnz)
 Create CSR sparse matrix data memory space. More...
 
void fasp_dcsr_alloc (const INT m, const INT n, const INT nnz, dCSRmat *A)
 Allocate CSR sparse matrix memory space. More...
 
void fasp_dcsr_free (dCSRmat *A)
 Free CSR sparse matrix data memory space. More...
 
void fasp_icsr_free (iCSRmat *A)
 Free CSR sparse matrix data memory space. More...
 
INT fasp_dcsr_bandwidth (const dCSRmat *A)
 Get bandwith of matrix. More...
 
dCSRmat fasp_dcsr_perm (dCSRmat *A, INT *P)
 Apply permutation of A, i.e. Aperm=PAP' by the orders given in P. More...
 
void fasp_dcsr_sort (dCSRmat *A)
 Sort each row of A in ascending order w.r.t. column indices. More...
 
SHORT fasp_dcsr_getblk (const dCSRmat *A, const INT *Is, const INT *Js, const INT m, const INT n, dCSRmat *B)
 Get a sub CSR matrix of A with specified rows and columns. More...
 
void fasp_dcsr_getdiag (INT n, const dCSRmat *A, dvector *diag)
 Get first n diagonal entries of a CSR matrix A. More...
 
void fasp_dcsr_getcol (const INT n, const dCSRmat *A, REAL *col)
 Get the n-th column of a CSR matrix A. More...
 
void fasp_dcsr_diagpref (dCSRmat *A)
 Re-order the column and data arrays of a CSR matrix, so that the first entry in each row is the diagonal. More...
 
SHORT fasp_dcsr_regdiag (dCSRmat *A, const REAL value)
 Regularize diagonal entries of a CSR sparse matrix. More...
 
void fasp_icsr_cp (const iCSRmat *A, iCSRmat *B)
 Copy a iCSRmat to a new one B=A. More...
 
void fasp_dcsr_cp (const dCSRmat *A, dCSRmat *B)
 copy a dCSRmat to a new one B=A More...
 
void fasp_icsr_trans (const iCSRmat *A, iCSRmat *AT)
 Find transpose of iCSRmat matrix A. More...
 
INT fasp_dcsr_trans (const dCSRmat *A, dCSRmat *AT)
 Find transpose of dCSRmat matrix A. More...
 
void fasp_dcsr_transpose (INT *row[2], INT *col[2], REAL *val[2], INT *nn, INT *tniz)
 Transpose of a dCSRmat matrix. More...
 
void fasp_dcsr_compress (const dCSRmat *A, dCSRmat *B, const REAL dtol)
 Compress a CSR matrix A and store in CSR matrix B by dropping small entries abs(aij)<=dtol. More...
 
SHORT fasp_dcsr_compress_inplace (dCSRmat *A, const REAL dtol)
 Compress a CSR matrix A IN PLACE by dropping small entries abs(aij)<=dtol. More...
 
void fasp_dcsr_shift (dCSRmat *A, const INT offset)
 Re-index a REAL matrix in CSR format to make the index starting from 0 or 1. More...
 
void fasp_dcsr_symdiagscale (dCSRmat *A, const dvector *diag)
 Symmetric diagonal scaling D^{-1/2}AD^{-1/2}. More...
 
dCSRmat fasp_dcsr_sympart (dCSRmat *A)
 Get symmetric part of a dCSRmat matrix. More...
 
void fasp_dcsr_transz (dCSRmat *A, INT *p, dCSRmat *AT)
 Generalized transpose of A: (n x m) matrix given in dCSRmat format. More...
 
dCSRmat fasp_dcsr_permz (dCSRmat *A, INT *p)
 Permute rows and cols of A, i.e. A=PAP' by the ordering in p. More...
 
void fasp_dcsr_sortz (dCSRmat *A, const SHORT isym)
 Sort each row of A in ascending order w.r.t. column indices. More...
 
void fasp_dcsr_multicoloring (dCSRmat *A, INT *flags, INT *groups)
 Use the greedy multi-coloring to get color groups of the adjacency graph of A. More...
 
void dCSRmat_Multicoloring (dCSRmat *A, INT *rowmax, INT *groups)
 Use the greedy multicoloring algorithm to get color groups for for the adjacency graph of A. More...
 
void dCSRmat_Multicoloring_Strong_Coupled (dCSRmat *A, iCSRmat *S, INT *flags, INT *groups)
 Use the greedy multicoloring algorithm to get color groups for the adjacency graph of A. More...
 
void dCSRmat_Multicoloring_Theta (dCSRmat *A, REAL theta, INT *rowmax, INT *groups)
 Use the greedy multicoloring algorithm to get color groups for for the adjacency graph of A. More...
 
void fasp_smoother_dcsr_gs_multicolor (dvector *u, dCSRmat *A, dvector *b, INT L, const INT order)
 

Detailed Description

Sparse matrix operations for dCSRmat matrices.

Note
This file contains Level-1 (Bla) functions. It requires: AuxArray.c, AuxMemory.c, AuxMessage.c, AuxSort.c, AuxThreads.c, AuxVector.c, and BlaSpmvCSR.c

Copyright (C) 2009–Present by the FASP team. All rights reserved.

Released under the terms of the GNU Lesser General Public License 3.0 or later.

Definition in file BlaSparseCSR.c.

Function Documentation

◆ dCSRmat_Multicoloring()

void dCSRmat_Multicoloring ( dCSRmat A,
INT rowmax,
INT groups 
)

Use the greedy multicoloring algorithm to get color groups for for the adjacency graph of A.

Parameters
AInput dCSRmat
rowmaxMax row nonzeros of A
groupsReturn group numbers
Author
Chunsheng Feng
Date
09/15/2012

Definition at line 1687 of file BlaSparseCSR.c.

◆ dCSRmat_Multicoloring_Strong_Coupled()

void dCSRmat_Multicoloring_Strong_Coupled ( dCSRmat A,
iCSRmat S,
INT flags,
INT groups 
)

Use the greedy multicoloring algorithm to get color groups for the adjacency graph of A.

Parameters
AInput dCSRmat
SInput iCSRmat Strong Coupled Matrix of A.
flagsFlags for the independent group
groupsReturn group numbers
Author
Chunsheng Feng
Date
09/15/2012

Definition at line 1867 of file BlaSparseCSR.c.

◆ dCSRmat_Multicoloring_Theta()

void dCSRmat_Multicoloring_Theta ( dCSRmat A,
REAL  theta,
INT rowmax,
INT groups 
)

Use the greedy multicoloring algorithm to get color groups for for the adjacency graph of A.

Parameters
AInput dCSRmat
thetaStrength threshold parameter
rowmaxMax row nonzeros of A
groupsReturn group numbers
Author
Li Zhao
Date
04/15/2022

Definition at line 1984 of file BlaSparseCSR.c.

◆ fasp_dcsr_alloc()

void fasp_dcsr_alloc ( const INT  m,
const INT  n,
const INT  nnz,
dCSRmat A 
)

Allocate CSR sparse matrix memory space.

Parameters
mNumber of rows
nNumber of columns
nnzNumber of nonzeros
APointer to the dCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06

Definition at line 138 of file BlaSparseCSR.c.

◆ fasp_dcsr_bandwidth()

INT fasp_dcsr_bandwidth ( const dCSRmat A)

Get bandwith of matrix.

Parameters
Apointer to the dCSRmat matrix
Author
Zheng Li
Date
03/22/2015

Definition at line 245 of file BlaSparseCSR.c.

◆ fasp_dcsr_compress()

void fasp_dcsr_compress ( const dCSRmat A,
dCSRmat B,
const REAL  dtol 
)

Compress a CSR matrix A and store in CSR matrix B by dropping small entries abs(aij)<=dtol.

Parameters
APointer to dCSRmat CSR matrix
BPointer to dCSRmat CSR matrix
dtolDrop tolerance
Author
Shiquan Zhang
Date
03/10/2010

Modified by Chunsheng Feng, Zheng Li on 08/25/2012

Definition at line 1086 of file BlaSparseCSR.c.

◆ fasp_dcsr_compress_inplace()

SHORT fasp_dcsr_compress_inplace ( dCSRmat A,
const REAL  dtol 
)

Compress a CSR matrix A IN PLACE by dropping small entries abs(aij)<=dtol.

Parameters
APointer to dCSRmat CSR matrix
dtolDrop tolerance
Author
Xiaozhe Hu
Date
12/25/2010

Modified by Chensong Zhang on 02/21/2013 Modified by Chunsheng Feng on 10/16/2020: Avoid filtering diagonal entries.

Note
This routine can be modified for filtering.

Definition at line 1166 of file BlaSparseCSR.c.

◆ fasp_dcsr_cp()

void fasp_dcsr_cp ( const dCSRmat A,
dCSRmat B 
)

copy a dCSRmat to a new one B=A

Parameters
APointer to the dCSRmat matrix
BPointer to the dCSRmat matrix
Author
Chensong Zhang
Date
04/06/2010

Modified by Chunsheng Feng, Xiaoqiang Yue on 05/23/2012

Definition at line 851 of file BlaSparseCSR.c.

◆ fasp_dcsr_create()

dCSRmat fasp_dcsr_create ( const INT  m,
const INT  n,
const INT  nnz 
)

Create CSR sparse matrix data memory space.

Parameters
mNumber of rows
nNumber of columns
nnzNumber of nonzeros
Returns
A the new dCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06

Definition at line 47 of file BlaSparseCSR.c.

◆ fasp_dcsr_diagpref()

void fasp_dcsr_diagpref ( dCSRmat A)

Re-order the column and data arrays of a CSR matrix, so that the first entry in each row is the diagonal.

Parameters
APointer to the matrix to be re-ordered
Author
Zhiyang Zhou
Date
09/09/2010
Author
Chunsheng Feng, Zheng Li
Date
09/02/2012
Note
Reordering is done in place.

Modified by Chensong Zhang on Dec/21/2012

Definition at line 680 of file BlaSparseCSR.c.

◆ fasp_dcsr_free()

void fasp_dcsr_free ( dCSRmat A)

Free CSR sparse matrix data memory space.

Parameters
APointer to the dCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06 Modified by Chunsheng Feng on 08/11/2017: init A to NULL

Definition at line 184 of file BlaSparseCSR.c.

◆ fasp_dcsr_getblk()

SHORT fasp_dcsr_getblk ( const dCSRmat A,
const INT Is,
const INT Js,
const INT  m,
const INT  n,
dCSRmat B 
)

Get a sub CSR matrix of A with specified rows and columns.

Parameters
APointer to dCSRmat matrix
BPointer to dCSRmat matrix
IsPointer to selected rows
JsPointer to selected columns
mNumber of selected rows
nNumber of selected columns
Returns
FASP_SUCCESS if succeeded, otherwise return error information.
Author
Shiquan Zhang, Xiaozhe Hu
Date
12/25/2010

Modified by Chunsheng Feng, Xiaoqiang Yue on 05/23/2012

Definition at line 446 of file BlaSparseCSR.c.

◆ fasp_dcsr_getcol()

void fasp_dcsr_getcol ( const INT  n,
const dCSRmat A,
REAL col 
)

Get the n-th column of a CSR matrix A.

Parameters
nIndex of a column of A (0 <= n <= A.col-1)
APointer to dCSRmat CSR matrix
colPointer to the column
Author
Xiaozhe Hu
Date
11/07/2009

Modified by Chunsheng Feng, Zheng Li on 07/08/2012

Definition at line 602 of file BlaSparseCSR.c.

◆ fasp_dcsr_getdiag()

void fasp_dcsr_getdiag ( INT  n,
const dCSRmat A,
dvector diag 
)

Get first n diagonal entries of a CSR matrix A.

Parameters
nNumber of diagonal entries to get (if n=0, then get all diagonal entries)
APointer to dCSRmat CSR matrix
diagPointer to the diagonal as a dvector
Author
Chensong Zhang
Date
05/20/2009

Modified by Chunsheng Feng, Xiaoqiang Yue on 05/23/2012

Definition at line 537 of file BlaSparseCSR.c.

◆ fasp_dcsr_multicoloring()

void fasp_dcsr_multicoloring ( dCSRmat A,
INT flags,
INT groups 
)

Use the greedy multi-coloring to get color groups of the adjacency graph of A.

Parameters
AInput dCSRmat
flagsflags for the independent group
groupsReturn group numbers
Author
Chunsheng Feng
Date
09/15/2012

Definition at line 1602 of file BlaSparseCSR.c.

◆ fasp_dcsr_perm()

dCSRmat fasp_dcsr_perm ( dCSRmat A,
INT P 
)

Apply permutation of A, i.e. Aperm=PAP' by the orders given in P.

Parameters
APointer to the original dCSRmat matrix
PPointer to orders
Returns
The new ordered dCSRmat matrix if succeed, NULL if fail
Author
Shiquan Zhang
Date
03/10/2010
Note
P[i] = k means k-th row and column become i-th row and column!
Deprecated! Will be replaced by fasp_dcsr_permz later. –Chensong

Modified by Chunsheng Feng, Zheng Li on 07/12/2012

Definition at line 275 of file BlaSparseCSR.c.

◆ fasp_dcsr_permz()

dCSRmat fasp_dcsr_permz ( dCSRmat A,
INT p 
)

Permute rows and cols of A, i.e. A=PAP' by the ordering in p.

Parameters
APointer to the original dCSRmat matrix
pPointer to ordering
Note
This is just applying twice fasp_dcsr_transz(&A,p,At).
In matlab notation: Aperm=A(p,p);
Returns
The new ordered dCSRmat matrix if succeed, NULL if fail
Author
Ludmil Zikatanov
Date
19951219 (Fortran), 20150912 (C)

Definition at line 1540 of file BlaSparseCSR.c.

◆ fasp_dcsr_regdiag()

SHORT fasp_dcsr_regdiag ( dCSRmat A,
const REAL  value 
)

Regularize diagonal entries of a CSR sparse matrix.

Parameters
APointer to the dCSRmat matrix
valueSet a value on diag(A) which is too close to zero to "value"
Returns
FASP_SUCCESS if no diagonal entry is close to zero, else ERROR
Author
Shiquan Zhang
Date
11/07/2009

Definition at line 786 of file BlaSparseCSR.c.

◆ fasp_dcsr_shift()

void fasp_dcsr_shift ( dCSRmat A,
const INT  offset 
)

Re-index a REAL matrix in CSR format to make the index starting from 0 or 1.

Parameters
APointer to CSR matrix
offsetSize of offset (1 or -1)
Author
Chensong Zhang
Date
04/06/2010

Modified by Chunsheng Feng, Zheng Li on 07/11/2012

Definition at line 1212 of file BlaSparseCSR.c.

◆ fasp_dcsr_sort()

void fasp_dcsr_sort ( dCSRmat A)

Sort each row of A in ascending order w.r.t. column indices.

Parameters
APointer to the dCSRmat matrix
Author
Shiquan Zhang
Date
06/10/2010

Definition at line 385 of file BlaSparseCSR.c.

◆ fasp_dcsr_sortz()

void fasp_dcsr_sortz ( dCSRmat A,
const SHORT  isym 
)

Sort each row of A in ascending order w.r.t. column indices.

Parameters
APointer to the dCSRmat matrix
isymFlag for symmetry, =[0/nonzero]=[general/symmetric] matrix
Note
Applying twice fasp_dcsr_transz(), if A is symmetric, then the transpose is applied only once and then AT copied on A.
Author
Ludmil Zikatanov
Date
19951219 (Fortran), 20150912 (C)

Definition at line 1571 of file BlaSparseCSR.c.

◆ fasp_dcsr_symdiagscale()

void fasp_dcsr_symdiagscale ( dCSRmat A,
const dvector diag 
)

Symmetric diagonal scaling D^{-1/2}AD^{-1/2}.

Parameters
APointer to the dCSRmat matrix
diagPointer to the diagonal entries
Author
Xiaozhe Hu
Date
01/31/2011

Modified by Chunsheng Feng, Zheng Li on 07/11/2012

Definition at line 1270 of file BlaSparseCSR.c.

◆ fasp_dcsr_sympart()

dCSRmat fasp_dcsr_sympart ( dCSRmat A)

Get symmetric part of a dCSRmat matrix.

Parameters
APointer to the dCSRmat matrix
Returns
Symmetrized the dCSRmat matrix
Author
Xiaozhe Hu
Date
03/21/2011

Definition at line 1357 of file BlaSparseCSR.c.

◆ fasp_dcsr_trans()

void fasp_dcsr_trans ( const dCSRmat A,
dCSRmat AT 
)

Find transpose of dCSRmat matrix A.

Parameters
APointer to the dCSRmat matrix
ATPointer to the transpose of dCSRmat matrix A (output)
Author
Chensong Zhang
Date
04/06/2010

Modified by Chunsheng Feng, Zheng Li on 06/20/2012

Definition at line 952 of file BlaSparseCSR.c.

◆ fasp_dcsr_transpose()

void fasp_dcsr_transpose ( INT row[2],
INT col[2],
REAL val[2],
INT nn,
INT tniz 
)

Transpose of a dCSRmat matrix.

Note
This subroutine transpose in CSR format IN ORDER
Parameters
rowPointers of the rows of the matrix and its transpose
colPointers of the columns of the matrix and its transpose
valPointers to the values of the matrix and its transpose
nnPointer to the number of rows/columns of A and A'
tnizPointer to the number of nonzeros A and A'
Author
Shuo Zhang
Date
07/06/2009

Definition at line 1037 of file BlaSparseCSR.c.

◆ fasp_dcsr_transz()

void fasp_dcsr_transz ( dCSRmat A,
INT p,
dCSRmat AT 
)

Generalized transpose of A: (n x m) matrix given in dCSRmat format.

Parameters
APointer to matrix in dCSRmat for transpose, INPUT
pPermutation, INPUT
ATPointer to matrix AT = transpose(A) if p = NULL, OR AT = transpose(A)p if p is not NULL
Note
The storage for all pointers in AT should already be allocated, i.e. AT->IA, AT->JA and AT->val should be allocated before calling this function. If A.val=NULL, then AT->val[] is not changed.
performs AT=transpose(A)p, where p is a permutation. If p=NULL then p=I is assumed. Applying twice this procedure one gets At=transpose(transpose(A)p)p = transpose(p)Ap, which is the same A with rows and columns permutted according to p.
If A=NULL, then only transposes/permutes the structure of A.
For p=NULL, applying this two times A-->AT-->A orders all the row indices in A in increasing order.

Reference: Fred G. Gustavson. Two fast algorithms for sparse matrices: multiplication and permuted transposition. ACM Trans. Math. Software, 4(3):250�C269, 1978.

Author
Ludmil Zikatanov
Date
19951219 (Fortran), 20150912 (C)

Definition at line 1416 of file BlaSparseCSR.c.

◆ fasp_icsr_cp()

void fasp_icsr_cp ( const iCSRmat A,
iCSRmat B 
)

Copy a iCSRmat to a new one B=A.

Parameters
APointer to the iCSRmat matrix
BPointer to the iCSRmat matrix
Author
Chensong Zhang
Date
05/16/2013

Definition at line 827 of file BlaSparseCSR.c.

◆ fasp_icsr_create()

iCSRmat fasp_icsr_create ( const INT  m,
const INT  n,
const INT  nnz 
)

Create CSR sparse matrix data memory space.

Parameters
mNumber of rows
nNumber of columns
nnzNumber of nonzeros
Returns
A the new iCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06

Definition at line 96 of file BlaSparseCSR.c.

◆ fasp_icsr_free()

void fasp_icsr_free ( iCSRmat A)

Free CSR sparse matrix data memory space.

Parameters
APointer to the iCSRmat matrix
Author
Chensong Zhang
Date
2010/04/06 Modified by Chunsheng Feng on 08/11/2017: init A to NULL

Definition at line 219 of file BlaSparseCSR.c.

◆ fasp_icsr_trans()

void fasp_icsr_trans ( const iCSRmat A,
iCSRmat AT 
)

Find transpose of iCSRmat matrix A.

Parameters
APointer to the iCSRmat matrix A
ATPointer to the iCSRmat matrix A'
Author
Chensong Zhang
Date
04/06/2010

Modified by Chunsheng Feng, Zheng Li on 06/20/2012

Definition at line 875 of file BlaSparseCSR.c.

◆ fasp_smoother_dcsr_gs_multicolor()

void fasp_smoother_dcsr_gs_multicolor ( dvector u,
dCSRmat A,
dvector b,
INT  L,
const INT  order 
)

Definition at line 2123 of file BlaSparseCSR.c.