programmer's documentation
Data Structures | Macros | Enumerations | Functions
cs_sla.h File Reference
#include <stdio.h>
#include "cs_base.h"
#include "cs_cdo.h"
#include "cs_cdo_toolbox.h"
#include "cs_param.h"
Include dependency graph for cs_sla.h:

Go to the source code of this file.

Data Structures

struct  cs_sla_matrix_info_t
 
struct  cs_sla_matrix_t
 
struct  cs_sla_sumup_t
 

Macros

#define CS_SLA_MATRIX_SYM   (1 << 0) /* 1: symmetric */
 
#define CS_SLA_MATRIX_SORTED   (1 << 1) /* 2: sorted */
 
#define CS_SLA_MATRIX_SHARED   (1 << 2) /* 4: share pattern */
 
#define CS_SLA_MATRIX_INFO   (1 << 3) /* 8: info struct. is set */
 

Enumerations

enum  cs_sla_matrix_type_t {
  CS_SLA_MAT_NONE, CS_SLA_MAT_DEC, CS_SLA_MAT_CSR, CS_SLA_MAT_MSR,
  CS_SLA_MAT_N_TYPES
}
 

Functions

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 *mat)
 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)| 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 where 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_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_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_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...
 

Macro Definition Documentation

#define CS_SLA_MATRIX_INFO   (1 << 3) /* 8: info struct. is set */
#define CS_SLA_MATRIX_SHARED   (1 << 2) /* 4: share pattern */
#define CS_SLA_MATRIX_SORTED   (1 << 1) /* 2: sorted */
#define CS_SLA_MATRIX_SYM   (1 << 0) /* 1: symmetric */

Enumeration Type Documentation

Enumerator
CS_SLA_MAT_NONE 
CS_SLA_MAT_DEC 
CS_SLA_MAT_CSR 
CS_SLA_MAT_MSR 
CS_SLA_MAT_N_TYPES 

Function Documentation

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)| 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

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 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

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: only pointer are copied other allocated
Returns
the matrix corresponding to this operation
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]matmatrix to transpose
Returns
a pointer to new allocated matrix which is transposed to mat
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