programmer's documentation
Macros | Functions | Variables
cs_sla_matrix.c File Reference
#include "cs_defs.h"
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <bft_mem.h>
#include <bft_printf.h>
#include "cs_sort.h"
#include "cs_search.h"
#include "cs_sla.h"
Include dependency graph for cs_sla_matrix.c:

Macros

#define CS_SLA_MATRIX_DBG   0
 

Functions

static _spa_t * _spa_init (size_t a_size, size_t l_size)
 Initialize a Sparse Accumulator (SPA) for MSR and CSR type. More...
 
static _spa_t * _spa_free (_spa_t *spa)
 Free a Sparse Accumulator (SPA) for MSR and CSR type. More...
 
static _spa_dec_t * _spa_dec_init (size_t a_size, size_t l_size)
 Initialize a Sparse Accumulator (SPA) for DEC type. More...
 
static _spa_dec_t * _spa_dec_free (_spa_dec_t *spa)
 Free a Sparse Accumulator (SPA) for MSR and CSR type. More...
 
static void _spa_add (_spa_t *spa, double value, cs_lnum_t pos, cs_lnum_t row_id)
 Add the contribution of a new entry. More...
 
static void _spa_dec_add (_spa_dec_t *spa, short int value, cs_lnum_t pos, cs_lnum_t row_id)
 Add the contribution of a new entry. More...
 
static size_t _spa_gather (_spa_t *spa, size_t idx, cs_lnum_t *col_id, double *val)
 Gather data from the current SPA state to update matrix structure Do not add zero entries. More...
 
static size_t _spa_dec_gather (_spa_dec_t *spa, size_t idx, cs_lnum_t *col_id, short int *connect)
 Gather data from the current SPA state to update matrix structure Do not add zero entries. More...
 
static void _estimate_sizes (const cs_sla_matrix_t *a, const cs_sla_matrix_t *b, size_t *nnz, size_t *stencil)
 Estimate roughly the number of nnz of the matrix c = a*b and the stencil of c. Size estimation is given by E. Cohen (1997) in Structure Prediction and Computation of Sparse Matrix Product. More...
 
static cs_sla_matrix_t_init_mat (const cs_sla_matrix_t *a, const cs_sla_matrix_t *b, cs_sla_matrix_type_t type, size_t guess_size)
 
static void _resize_mat (cs_sla_matrix_t *mat, size_t cur_size, size_t *max_size)
 
static cs_sla_matrix_t_multiply_dec_matrices (const cs_sla_matrix_t *a, const cs_sla_matrix_t *b)
 Compute c = a*b for a and b in DEC storage. More...
 
static cs_sla_matrix_t_multiply_csr_matrices (const cs_sla_matrix_t *a, const cs_sla_matrix_t *b)
 Compute c = a*b for a and b in CSR storage. More...
 
static cs_sla_matrix_t_multiply_deccsr_matrices (const cs_sla_matrix_t *a, const cs_sla_matrix_t *b)
 Compute c = a*b for a in DEC storage and b in CSR storage. More...
 
static cs_sla_matrix_t_multiply_csrdec_matrices (const cs_sla_matrix_t *a, const cs_sla_matrix_t *b)
 Compute c = a*b for a in CSR storage and b in DEC storage. More...
 
static cs_sla_matrix_t_multiply_decmsr_matrices (const cs_sla_matrix_t *a, const cs_sla_matrix_t *b)
 Compute c = a*b for a in DEC storage and b in MSR storage. More...
 
static cs_sla_matrix_t_multiply_msrdec_matrices (const cs_sla_matrix_t *a, const cs_sla_matrix_t *b)
 Compute c = a*b for a in MSR storage and b in DEC storage. More...
 
static void _decdec_AtDA (const cs_sla_matrix_t *At, const double D[], const cs_sla_matrix_t *A, cs_sla_matrix_t *C, int *w)
 Compute the product C = At * Diag * A where A and At are DEC matrices. More...
 
static void _csrcsr_AtDA (const cs_sla_matrix_t *At, const double D[], const cs_sla_matrix_t *A, cs_sla_matrix_t *C, int *w)
 Compute the product C = At * Diag * A where A and At are CSR matrices. More...
 
static void _pack_dec (cs_sla_matrix_t *final, const cs_sla_matrix_t *init, const cs_lnum_t *row_z2i_ids, const cs_lnum_t *col_i2z_ids)
 Fill a matrix resulting from an extraction of row/column for matrix in DEC format. More...
 
static void _pack_csr (cs_sla_matrix_t *final, const cs_sla_matrix_t *init, const cs_lnum_t *row_z2i_ids, const cs_lnum_t *col_i2z_ids)
 Fill a matrix resulting from an extraction of row/column for matrix in CSR format. More...
 
static void _pack_msr (cs_sla_matrix_t *final, const cs_sla_matrix_t *init, const cs_lnum_t *row_z2i_ids, const cs_lnum_t *col_i2z_ids, _Bool msr2csr)
 Fill a matrix resulting from an extraction of row/column for matrix in MSR format. More...
 
cs_sla_matrix_tcs_sla_matrix_create (cs_lnum_t n_rows, cs_lnum_t n_cols, int stride, cs_sla_matrix_type_t type, bool sym)
 Create a cs_sla_matrix_t structure. More...
 
cs_sla_matrix_tcs_sla_matrix_create_from_ref (const cs_sla_matrix_t *ref, cs_sla_matrix_type_t type, int stride)
 Create a cs_sla_matrix_t structure from an existing one. idx, didx and col_id are shared with ref. Initialize related buffers. More...
 
cs_sla_matrix_tcs_sla_matrix_create_msr_from_index (const cs_connect_index_t *connect_idx, bool is_symmetric, bool sorted_idx, int stride)
 Create a cs_sla_matrix_t structure with MSR type from an existing connectivity index. Be aware of removing the diagonal entry in the connectivity index before the call to this routine. More...
 
cs_sla_matrix_tcs_sla_matrix_copy (const cs_sla_matrix_t *a, bool shared)
 Create a new matrix structure from the copy of an existing one. More...
 
cs_sla_matrix_tcs_sla_matrix_transpose (const cs_sla_matrix_t *a)
 Transpose a cs_sla_matrix_t structure. More...
 
cs_sla_matrix_tcs_sla_matrix_free (cs_sla_matrix_t *m)
 Free a cs_sla_matrix_t structure. More...
 
void cs_sla_matrix_rmzeros (cs_sla_matrix_t *m)
 Remove entries with zero values Only available for CSR and MSR matrices with stride = 1. More...
 
void cs_sla_matrix_clean (cs_sla_matrix_t *m, double eps)
 Remove entries in a cs_sla_matrix_t structure below a given threshold. |a(i,j)| < eps * max|a(i,j)| i Be careful when using this function since one can loose the symmetry Only available for matrices with stride = 1. More...
 
size_t cs_sla_matrix_get_nnz (const cs_sla_matrix_t *m)
 Retrieve the number of non-zeros (nnz) elements in a matrix. More...
 
void cs_sla_matrix_diag_idx (cs_sla_matrix_t *m)
 Build diagonal index. More...
 
void cs_sla_matrix_get_diag (const cs_sla_matrix_t *m, double *p_diag[])
 Get the diagonal entries of a given matrix. More...
 
void cs_sla_matrix_sort (cs_sla_matrix_t *m)
 Sort each row by increasing colomn number. More...
 
void cs_sla_matrix_set_info (cs_sla_matrix_t *m)
 Compute general information related to a cs_sla_matrix_t structure and store it into a cs_sla_matrix_info_t structure. More...
 
void cs_sla_matrix_msr2csr (cs_sla_matrix_t *a)
 Change matrix representation from MSR to CSR. More...
 
void cs_sla_matrix_csr2msr (cs_sla_matrix_t *a)
 Change matrix representation from CSR to MSR. More...
 
void cs_sla_matrix_share2own (cs_sla_matrix_t *a)
 Allocate its own pattern if shared. More...
 
void cs_sla_assemble_msr_sym (const cs_locmat_t *loc, cs_sla_matrix_t *ass, bool only_diag)
 Assemble a MSR matrix from local contributions –> We assume that the local matrices are symmetric –> We assume that the assembled matrix has its columns sorted. More...
 
void cs_sla_assemble_msr (const cs_locmat_t *loc, cs_sla_matrix_t *ass)
 Assemble a MSR matrix from local contributions –> We assume that the assembled matrix has its columns sorted. More...
 
cs_sla_matrix_tcs_sla_matrix_pack (cs_lnum_t n_final_rows, cs_lnum_t n_final_cols, const cs_sla_matrix_t *init, const cs_lnum_t *row_z2i_ids, const cs_lnum_t *col_i2z_ids, _Bool keep_sym)
 Build a new matrix resulting from the extraction of some listed rows and columns. The output is a new matrix packed (or zipped) w.r.t the initial matrix. More...
 
cs_sla_matrix_tcs_sla_matrix_add (double alpha, const cs_sla_matrix_t *a, double beta, const cs_sla_matrix_t *b)
 Add two sparse matrices a and b. c = alpha*a + beta*b. More...
 
void cs_sla_matvec (const cs_sla_matrix_t *m, const double v[], double *inout[], bool reset)
 Compute a matrix vector product. If inout is not allocated, allocation is done inside this function If reset is set to true, initialization inout to 0. More...
 
void cs_sla_amxby (double alpha, const cs_sla_matrix_t *m, const double x[], double beta, const double y[], double *inout[])
 Compute an array resulting from alpha * M(x) + beta * y If inout is not allocated, allocation is done inside this function. More...
 
cs_sla_matrix_tcs_sla_matrix_multiply (const cs_sla_matrix_t *a, const cs_sla_matrix_t *b)
 Main subroutine to multiply two sparse matrices a and b. c= a*b. More...
 
cs_sla_matrix_tcs_sla_multiply_AtDA (const cs_sla_matrix_t *At, const double D[], const cs_sla_matrix_t *A, cs_lnum_t *w)
 Compute the product C = At * Diag * A. More...
 
cs_sla_matrix_tcs_sla_matrix_combine (double alpha, const cs_sla_matrix_t *a, double beta, const cs_sla_matrix_t *bt, const cs_sla_matrix_t *b)
 Specific matrix multiplication. Compute Bt * beta * B + alpha * A alpha and beta are scalar. More...
 
void cs_sla_matvec_block2 (const cs_sla_matrix_t *A, const cs_sla_matrix_t *B, const cs_sla_matrix_t *C, const cs_sla_matrix_t *D, const double X[], const double Y[], double *F[], double *G[], _Bool reset)
 Matrix block 2x2 multiply by a vector. More...
 
void cs_sla_bread (const char *name, cs_sla_matrix_t **p_mat, double *p_rhs[], double *p_sol[])
 Read from a binary file a matrix in CSR format, its righ hand side and the solution. Matrix must have a stride equal to 1. More...
 
void cs_sla_bwrite (const char *name, const cs_sla_matrix_t *m, const double *rhs, const double *sol)
 Write in binary format a matrix in CSR format, its righ hand side and the solution. More...
 
void cs_sla_matrix_summary (const char *name, FILE *f, cs_sla_matrix_t *m)
 Synthesis of a cs_sla_matrix_t structure. More...
 
void cs_sla_matrix_dump (const char *name, FILE *f, const cs_sla_matrix_t *m)
 Dump a cs_sla_matrix_t structure. More...
 
void cs_sla_system_dump (const char *name, FILE *f, const cs_sla_matrix_t *m, const double *rhs)
 Dump a cs_sla_matrix_t structure and its related right-hand side. More...
 

Variables

static const char _sla_err_stride []
 
static const char _sla_matrix_type [CS_SLA_MAT_N_TYPES][CS_CDO_LEN_NAME]
 

Macro Definition Documentation

#define CS_SLA_MATRIX_DBG   0

Function Documentation

static void _csrcsr_AtDA ( const cs_sla_matrix_t At,
const double  D[],
const cs_sla_matrix_t A,
cs_sla_matrix_t C,
int *  w 
)
static

Compute the product C = At * Diag * A where A and At are CSR matrices.

Parameters
[in]Atpointer to a cs_sla_matrix_t struct. (CSR type)
[in]Darray standing for a diagonal operator
[in]Apointer to a cs_sla_matrix_t struct. (CSR type)
[in,out]Cpointer to a cs_sla_matrix_t storing the result
[in,out]wwork buffer
static void _decdec_AtDA ( const cs_sla_matrix_t At,
const double  D[],
const cs_sla_matrix_t A,
cs_sla_matrix_t C,
int *  w 
)
static

Compute the product C = At * Diag * A where A and At are DEC matrices.

Parameters
[in]Atpointer to a cs_sla_matrix_t struct. (DEC type)
[in]Darray standing for a diagonal operator
[in]Apointer to a cs_sla_matrix_t struct. (DEC type)
[in,out]Cpointer to a cs_sla_matrix_t storing the result
[in,out]wwork buffer
static void _estimate_sizes ( const cs_sla_matrix_t a,
const cs_sla_matrix_t b,
size_t *  nnz,
size_t *  stencil 
)
static

Estimate roughly the number of nnz of the matrix c = a*b and the stencil of c. Size estimation is given by E. Cohen (1997) in Structure Prediction and Computation of Sparse Matrix Product.

Parameters
[in]apointer to the matrix struct. a
[in]bpointer to the matrix struct. b
[in,out]nnzsize_t element
[in,out]stencilsize_t element
static cs_sla_matrix_t* _init_mat ( const cs_sla_matrix_t a,
const cs_sla_matrix_t b,
cs_sla_matrix_type_t  type,
size_t  guess_size 
)
static
static cs_sla_matrix_t* _multiply_csr_matrices ( const cs_sla_matrix_t a,
const cs_sla_matrix_t b 
)
static

Compute c = a*b for a and b in CSR storage.

Parameters
[in]apointer to the matrix struct. a
[in]bpointer to the matrix struct. b
Returns
a pointer to matrix struct. c
static cs_sla_matrix_t* _multiply_csrdec_matrices ( const cs_sla_matrix_t a,
const cs_sla_matrix_t b 
)
static

Compute c = a*b for a in CSR storage and b in DEC storage.

Parameters
[in]apointer to the matrix struct. a
[in]bpointer to the matrix struct. b
Returns
a pointer to matrix struct. c
static cs_sla_matrix_t* _multiply_dec_matrices ( const cs_sla_matrix_t a,
const cs_sla_matrix_t b 
)
static

Compute c = a*b for a and b in DEC storage.

Parameters
[in]apointer to the matrix struct. a
[in]bpointer to the matrix struct. b
Returns
a pointer to matrix struct. c
static cs_sla_matrix_t* _multiply_deccsr_matrices ( const cs_sla_matrix_t a,
const cs_sla_matrix_t b 
)
static

Compute c = a*b for a in DEC storage and b in CSR storage.

Parameters
[in]apointer to the matrix struct. a
[in]bpointer to the matrix struct. b
Returns
a pointer to matrix struct. c
static cs_sla_matrix_t* _multiply_decmsr_matrices ( const cs_sla_matrix_t a,
const cs_sla_matrix_t b 
)
static

Compute c = a*b for a in DEC storage and b in MSR storage.

Parameters
[in]apointer to the matrix struct. a
[in]bpointer to the matrix struct. b
Returns
a pointer to matrix struct. c
static cs_sla_matrix_t* _multiply_msrdec_matrices ( const cs_sla_matrix_t a,
const cs_sla_matrix_t b 
)
static

Compute c = a*b for a in MSR storage and b in DEC storage.

Parameters
[in]apointer to the matrix struct. a
[in]bpointer to the matrix struct. b
Returns
a pointer to matrix struct. c
static void _pack_csr ( cs_sla_matrix_t final,
const cs_sla_matrix_t init,
const cs_lnum_t row_z2i_ids,
const cs_lnum_t col_i2z_ids 
)
static

Fill a matrix resulting from an extraction of row/column for matrix in CSR format.

Parameters
[in,out]finalpointer to the block matrix struct.
[in]initinit matrix to work with
[in]row_z2i_idszipped -> init numbering for rows
[in]col_i2z_idsinit -> zipped numbering for columns
Returns
a pointer to the new final matrix struct
static void _pack_dec ( cs_sla_matrix_t final,
const cs_sla_matrix_t init,
const cs_lnum_t row_z2i_ids,
const cs_lnum_t col_i2z_ids 
)
static

Fill a matrix resulting from an extraction of row/column for matrix in DEC format.

Parameters
[in,out]finalpointer to the final matrix struct.
[in]initinit matrix to work with
[in]row_z2i_idszipped -> init numbering for rows
[in]col_i2z_idsinit -> zipped numbering for columns
Returns
a pointer to the new final matrix struct
static void _pack_msr ( cs_sla_matrix_t final,
const cs_sla_matrix_t init,
const cs_lnum_t row_z2i_ids,
const cs_lnum_t col_i2z_ids,
_Bool  msr2csr 
)
static

Fill a matrix resulting from an extraction of row/column for matrix in MSR format.

Parameters
[in,out]finalpointer to the block matrix struct.
[in]initinit matrix to work with
[in]row_z2i_idszipped -> init numbering for rows
[in]col_i2z_idsinit -> zipped numbering for columns
[in]msr2csrchange matrix type
Returns
a pointer to the new final matrix struct
static void _resize_mat ( cs_sla_matrix_t mat,
size_t  cur_size,
size_t *  max_size 
)
static
static void _spa_add ( _spa_t *  spa,
double  value,
cs_lnum_t  pos,
cs_lnum_t  row_id 
)
inlinestatic

Add the contribution of a new entry.

Parameters
[in,out]spapointer to the SPA struct. to update
[in]valuevalue to add
[in]posposition related to this value
[in]row_idcurrent row
static void _spa_dec_add ( _spa_dec_t *  spa,
short int  value,
cs_lnum_t  pos,
cs_lnum_t  row_id 
)
inlinestatic

Add the contribution of a new entry.

Parameters
[in,out]spapointer to the SPA struct. to update
[in]valuevalue to add
[in]posposition related to this value
[in]row_idcurrent row
static _spa_dec_t* _spa_dec_free ( _spa_dec_t *  spa)
static

Free a Sparse Accumulator (SPA) for MSR and CSR type.

Parameters
[in,out]spapointer to a SPA struct. to free
Returns
a NULL pointer
static size_t _spa_dec_gather ( _spa_dec_t *  spa,
size_t  idx,
cs_lnum_t col_id,
short int *  connect 
)
static

Gather data from the current SPA state to update matrix structure Do not add zero entries.

Parameters
[in]spapointer to the SPA struct.
[in]idxcurrent index position
[in,out]col_idpointer to matrix->col_id array
[in,out]connectpointer to matrix->sgn array
Returns
the number of entries added
static _spa_dec_t* _spa_dec_init ( size_t  a_size,
size_t  l_size 
)
static

Initialize a Sparse Accumulator (SPA) for DEC type.

Parameters
[in]a_sizesize of tag and connect arrays
[in]l_sizesize of lst
Returns
a pointer to a new allocated and initialize SPA struct.
static _spa_t* _spa_free ( _spa_t *  spa)
static

Free a Sparse Accumulator (SPA) for MSR and CSR type.

Parameters
[in,out]spapointer to a SPA struct. to free
Returns
a NULL pointer
static size_t _spa_gather ( _spa_t *  spa,
size_t  idx,
cs_lnum_t col_id,
double *  val 
)
static

Gather data from the current SPA state to update matrix structure Do not add zero entries.

Parameters
[in]spapointer to the SPA struct.
[in]idxcurrent index position
[in,out]col_idpointer to matrix->col_id array
[in,out]valpointer to matrix->val array
Returns
the number of entries added
static _spa_t* _spa_init ( size_t  a_size,
size_t  l_size 
)
static

Initialize a Sparse Accumulator (SPA) for MSR and CSR type.

Parameters
[in]a_sizesize of tag and val arrays
[in]l_sizesize of lst
Returns
a pointer to a new allocated and initialize SPA struct.
void cs_sla_amxby ( double  alpha,
const cs_sla_matrix_t m,
const double  x[],
double  beta,
const double  y[],
double *  inout[] 
)

Compute an array resulting from alpha * M(x) + beta * y If inout is not allocated, allocation is done inside this function.

Parameters
[in]alphamultiplicative coefficient
[in]mpointer to a cs_sla_matrix_t structure
[in]xpointer to an array of double
[in]betamultiplicative coefficient
[in]ypointer to an array of double
[in,out]inoutpointer to a pointer of double
void cs_sla_assemble_msr ( const cs_locmat_t loc,
cs_sla_matrix_t ass 
)

Assemble a MSR matrix from local contributions –> We assume that the assembled matrix has its columns sorted.

Parameters
[in]locpointer to a local matrix
[in,out]asspointer to a cs_sla_matrix_t struct. collecting data
void cs_sla_assemble_msr_sym ( const cs_locmat_t loc,
cs_sla_matrix_t ass,
bool  only_diag 
)

Assemble a MSR matrix from local contributions –> We assume that the local matrices are symmetric –> We assume that the assembled matrix has its columns sorted.

Parameters
[in]locpointer to a local matrix
[in,out]asspointer to a cs_sla_matrix_t struct.
[in]only_diagtrue if assembly is only for diagonal terms
void cs_sla_bread ( const char *  name,
cs_sla_matrix_t **  p_mat,
double *  p_rhs[],
double *  p_sol[] 
)

Read from a binary file a matrix in CSR format, its righ hand side and the solution. Matrix must have a stride equal to 1.

Parameters
[in]namename of the output file
[in,out]p_matsystem to solve
[in,out]p_rhsright hand side
[in,out]p_solsolution
void cs_sla_bwrite ( const char *  name,
const cs_sla_matrix_t m,
const double *  rhs,
const double *  sol 
)

Write in binary format a matrix in CSR format, its righ hand side and the solution.

Parameters
[in]namename of the output file
[in]msystem to solve
[in]rhsright hand side
[in]solsolution
cs_sla_matrix_t* cs_sla_matrix_add ( double  alpha,
const cs_sla_matrix_t a,
double  beta,
const cs_sla_matrix_t b 
)

Add two sparse matrices a and b. c = alpha*a + beta*b.

Parameters
[in]alphafirst coef.
[in]afirst matrix to add
[in]betasecond coef.
[in]bsecond matrix to add
Returns
a pointer to the resulting matrix
void cs_sla_matrix_clean ( cs_sla_matrix_t m,
double  eps 
)

Remove entries in a cs_sla_matrix_t structure below a given threshold. |a(i,j)| < eps * max|a(i,j)| i Be careful when using this function since one can loose the symmetry Only available for matrices with stride = 1.

Remove entries in a cs_sla_matrix_t structure below a given threshold. |a(i,j)| < eps * max|a(i,j)| Be careful when using this function since one can loose the symmetry Only available for matrices with stride = 1.

Parameters
[in,out]mmatrix to clean
[in]epsvalue of the threshold
cs_sla_matrix_t* cs_sla_matrix_combine ( double  alpha,
const cs_sla_matrix_t a,
double  beta,
const cs_sla_matrix_t bt,
const cs_sla_matrix_t b 
)

Specific matrix multiplication. Compute Bt * beta * B + alpha * A alpha and beta are scalar.

Specific matrix multiplication. Compute Bt * beta * B + alpha * A where alpha and beta are scalar.

Parameters
[in]alphareal coefficient
[in]asquare sym. matrix
[in]betareal coefficient
[in]bmatrix (CSR or DEC)
[in]btadjoint matrix of b
Returns
the matrix corresponding to this operation in MSR storage
cs_sla_matrix_t* cs_sla_matrix_copy ( const cs_sla_matrix_t a,
bool  shared 
)

Create a new matrix structure from the copy of an existing one.

Parameters
[in]amatrix to copy
[in]sharedtrue: index information (idx, col_id) is shared
Returns
the matrix corresponding to this operation
cs_sla_matrix_t* cs_sla_matrix_create ( cs_lnum_t  n_rows,
cs_lnum_t  n_cols,
int  stride,
cs_sla_matrix_type_t  type,
bool  sym 
)

Create a cs_sla_matrix_t structure.

Parameters
[in]n_rowsnumber of rows
[in]n_colsnumber of columns
[in]stridenumber of values related to each entry
[in]typekind of matrix
[in]symtrue or false
Returns
a pointer to new allocated matrix structure
cs_sla_matrix_t* cs_sla_matrix_create_from_ref ( const cs_sla_matrix_t ref,
cs_sla_matrix_type_t  type,
int  stride 
)

Create a cs_sla_matrix_t structure from an existing one. idx, didx and col_id are shared with ref. Initialize related buffers.

Parameters
[in]refpointer to a reference matrix with the same pattern
[in]typetype of the matrix to create
[in]stridenumber of values for each entry
Returns
a pointer to new allocated matrix structure
cs_sla_matrix_t* cs_sla_matrix_create_msr_from_index ( const cs_connect_index_t connect_idx,
bool  is_symmetric,
bool  sorted_idx,
int  stride 
)

Create a cs_sla_matrix_t structure with MSR type from an existing connectivity index. Be aware of removing the diagonal entry in the connectivity index before the call to this routine.

Parameters
[in]connect_idxpointer to a connectivity index
[in]is_symmetrictrue or false
[in]sorted_idxtrue if the connectivity index is sorted
[in]stridenumber of values for each entry
Returns
a pointer to new (shared) matrix structure
void cs_sla_matrix_csr2msr ( cs_sla_matrix_t a)

Change matrix representation from CSR to MSR.

Parameters
[in,out]amatrix to transform
void cs_sla_matrix_diag_idx ( cs_sla_matrix_t m)

Build diagonal index.

Parameters
[in,out]mmatrix to work with
void cs_sla_matrix_dump ( const char *  name,
FILE *  f,
const cs_sla_matrix_t m 
)

Dump a cs_sla_matrix_t structure.

Parameters
[in]nameeither name of the file if f is NULL or description
[in]fpointer to a FILE struct.
[in]mmatrix to dump
cs_sla_matrix_t* cs_sla_matrix_free ( cs_sla_matrix_t m)

Free a cs_sla_matrix_t structure.

Parameters
[in]mmatrix to free
Returns
a NULL pointer
void cs_sla_matrix_get_diag ( const cs_sla_matrix_t m,
double *  p_diag[] 
)

Get the diagonal entries of a given matrix.

Parameters
[in]mmatrix to work with
[in,out]p_diagpointer to diag array to define (allocated if NULL)
size_t cs_sla_matrix_get_nnz ( const cs_sla_matrix_t m)

Retrieve the number of non-zeros (nnz) elements in a matrix.

Parameters
[in]mmatrix
Returns
the number of nnz
void cs_sla_matrix_msr2csr ( cs_sla_matrix_t a)

Change matrix representation from MSR to CSR.

Parameters
[in,out]amatrix to transform
cs_sla_matrix_t* cs_sla_matrix_multiply ( const cs_sla_matrix_t a,
const cs_sla_matrix_t b 
)

Main subroutine to multiply two sparse matrices a and b. c= a*b.

Parameters
[in]afirst matrix to multiply
[in]bsecond matrix to multiply
Returns
a pointer to the resulting matrix
cs_sla_matrix_t* cs_sla_matrix_pack ( cs_lnum_t  n_final_rows,
cs_lnum_t  n_final_cols,
const cs_sla_matrix_t init,
const cs_lnum_t row_z2i_ids,
const cs_lnum_t col_i2z_ids,
_Bool  keep_sym 
)

Build a new matrix resulting from the extraction of some listed rows and columns. The output is a new matrix packed (or zipped) w.r.t the initial matrix.

Parameters
[in]n_final_rowsnumber of rows to extract
[in]n_final_colsnumber of columns to extract
[in]initinit matrix to work with
[in]row_z2i_idszipped -> initial ids for rows
[in]col_i2z_idsinitial-> zipped ids for columns (-1 ==> remove)
[in]keep_symtrue or false
Returns
a pointer to the new (packed) matrix structure
void cs_sla_matrix_rmzeros ( cs_sla_matrix_t m)

Remove entries with zero values Only available for CSR and MSR matrices with stride = 1.

Parameters
[in,out]mmatrix to clean
void cs_sla_matrix_set_info ( cs_sla_matrix_t m)

Compute general information related to a cs_sla_matrix_t structure and store it into a cs_sla_matrix_info_t structure.

Parameters
[in,out]mmatrix to analyse
void cs_sla_matrix_share2own ( cs_sla_matrix_t a)

Allocate its own pattern if shared.

Parameters
[in,out]amatrix to transform
void cs_sla_matrix_sort ( cs_sla_matrix_t m)

Sort each row by increasing colomn number.

Parameters
[in]mmatrix to sort
void cs_sla_matrix_summary ( const char *  name,
FILE *  f,
cs_sla_matrix_t m 
)

Synthesis of a cs_sla_matrix_t structure.

Parameters
[in]nameeither name of the file if f is NULL or description
[in]fpointer to a FILE struct.
[in,out]mmatrix to dump (info can be computed inside)
cs_sla_matrix_t* cs_sla_matrix_transpose ( const cs_sla_matrix_t a)

Transpose a cs_sla_matrix_t structure.

Parameters
[in]amatrix to transpose
Returns
a pointer to new allocated matrix which is transposed to mat
void cs_sla_matvec ( const cs_sla_matrix_t m,
const double  v[],
double *  inout[],
bool  reset 
)

Compute a matrix vector product. If inout is not allocated, allocation is done inside this function If reset is set to true, initialization inout to 0.

Parameters
[in]mpointer to a cs_sla_matrix_t structure
[in]vpointer to an array of double
[in,out]inoutpointer to a pointer of double
[in]resetif true, first initialize inout to zero
void cs_sla_matvec_block2 ( const cs_sla_matrix_t A,
const cs_sla_matrix_t B,
const cs_sla_matrix_t C,
const cs_sla_matrix_t D,
const double  X[],
const double  Y[],
double *  F[],
double *  G[],
_Bool  reset 
)

Matrix block 2x2 multiply by a vector.

| A B | |X| = |F|= |AX + BY| | C D | |Y| |G| |CX + DY|

Parameters
[in]Apointer to a cs_sla_matrix_t block (1,1)
[in]Bpointer to a cs_sla_matrix_t block (1,2)
[in]Cpointer to a cs_sla_matrix_t block (2,1)
[in]Dpointer to a cs_sla_matrix_t block (2,2)
[in]Xupper vector
[in]Ylower vector
[in,out]Fupper result
[in,out]Glower result
[in]resetreset before computation (true/false)
cs_sla_matrix_t* cs_sla_multiply_AtDA ( const cs_sla_matrix_t At,
const double  D[],
const cs_sla_matrix_t A,
cs_lnum_t w 
)

Compute the product C = At * Diag * A.

Parameters
[in]Atpointer to a cs_sla_matrix_t struct. (DEC type)
[in]Darray standing for a diagonal operator
[in]Apointer to a cs_sla_matrix_t struct. (DEC type)
[in,out]wwork buffer
Returns
a pointer to a new cs_sla_matrix_t
void cs_sla_system_dump ( const char *  name,
FILE *  f,
const cs_sla_matrix_t m,
const double *  rhs 
)

Dump a cs_sla_matrix_t structure and its related right-hand side.

Parameters
[in]nameeither name of the file if f is NULL or description
[in]fpointer to a FILE struct.
[in]mmatrix to dump
[in]rhsright-hand side to dump

Variable Documentation

const char _sla_err_stride[]
static
Initial value:
=
" Incompatible stride value (>1).\n Stop matrix computation.\n"
const char _sla_matrix_type[CS_SLA_MAT_N_TYPES][CS_CDO_LEN_NAME]
static
Initial value:
= {
"None",
"DEC",
"CSR",
"MSR"
}