LADEL main
Sparse LDL factorization package with rank 1 and rowadd/rowdel updates
ladel_add.c
Go to the documentation of this file.
1#include "ladel_constants.h"
2#include "ladel_global.h"
3#include "ladel_types.h"
4#include "ladel_add.h"
5
7{
8 return ladel_add_matrices_advanced(alpha, A, beta, B, TRUE, work);
9}
10
12{
13 return ladel_add_matrices_advanced(0, A, 0, B, FALSE, work);
14}
15
17{
18 /* TODO: for different symmetries this will fail. */
19 if (!A || !B) return NULL;
21 ladel_int *touched = work->array_int_ncol_flag;
22 ladel_int index, col, row, C_nnz = 0;
23 ladel_int C_nrow = LADEL_MAX(A->nrow, B->nrow);
24 ladel_int C_ncol = LADEL_MAX(A->ncol, B->ncol);
25 ladel_int C_symmetry = (A->symmetry == B->symmetry) ? A->symmetry : UNSYMMETRIC;
26 ladel_int C_values = values && (A->values || B->values);
27
28 for (col = 0; col < C_ncol; col++)
29 {
30 work->flag++;
31 LADEL_FOR(index, A, col)
32 {
33 row = A->i[index];
34 if (touched[row] != work->flag)
35 {
36 touched[row] = work->flag;
37 C_nnz++;
38 }
39
40 }
41 LADEL_FOR(index, B, col)
42 {
43 row = B->i[index];
44 if (touched[row] != work->flag)
45 {
46 touched[row] = work->flag;
47 C_nnz++;
48 }
49 }
50 }
51
52 ladel_sparse_matrix *C = ladel_sparse_alloc(C_nrow, C_ncol, C_nnz, C_symmetry, C_values, FALSE);
53 if (!C) return NULL;
54
55 C_nnz = 0;
56 C->p[0] = 0;
57 for (col = 0; col < C_ncol; col++)
58 {
59 work->flag++;
60 LADEL_FOR(index, A, col)
61 {
62 row = A->i[index];
63 if (touched[row] != work->flag)
64 {
65 touched[row] = work->flag;
66 C->i[C_nnz] = row;
67 C_nnz++;
68 }
69 if (C_values) temp[row] += A->values ? alpha*A->x[index] : 0;
70 }
71 LADEL_FOR(index, B, col)
72 {
73 row = B->i[index];
74 if (touched[row] != work->flag)
75 {
76 touched[row] = work->flag;
77 C->i[C_nnz] = row;
78 C_nnz++;
79 }
80 if (C_values) temp[row] += B->values ? beta*B->x[index] : 0;
81 }
82 C->p[col+1] = C_nnz;
83 LADEL_FOR(index, C, col)
84 {
85 if (C_values)
86 {
87 row = C->i[index];
88 C->x[index] = temp[row];
89 temp[row] = 0;
90 }
91 }
92 }
93 return C;
94}
#define UNSYMMETRIC
No symmetry is assumed in the matrix.
#define TRUE
For booleans.
#define FALSE
For booleans.
#define LADEL_FOR(index, M, col)
Loop through a column of a sparse matrix.
#define LADEL_MAX(a, b)
Return the maximum of two numbers.
ladel_sparse_matrix * ladel_add_matrices_advanced(ladel_double alpha, const ladel_sparse_matrix *A, ladel_double beta, const ladel_sparse_matrix *B, ladel_int values, ladel_work *work)
Returns a sparse matrix if values==TRUE, or a pattern matrix that includes the patterns of A and B i...
Definition: ladel_add.c:16
ladel_sparse_matrix * ladel_add_matrices_pattern(const ladel_sparse_matrix *A, const ladel_sparse_matrix *B, ladel_work *work)
Returns a pattern matrix whose pattern includes the patterns of A and B.
Definition: ladel_add.c:11
ladel_sparse_matrix * ladel_add_matrices(ladel_double alpha, const ladel_sparse_matrix *A, ladel_double beta, const ladel_sparse_matrix *B, ladel_work *work)
Returns a sparse matrix .
Definition: ladel_add.c:6
Routines to add matrices.
Constants and macros used in LADEL.
Memory allocation routines.
ladel_sparse_matrix * ladel_sparse_alloc(ladel_int nrow, ladel_int ncol, ladel_int nzmax, ladel_int symmetry, ladel_int values, ladel_int nz)
Allocate a sparse matrix.
Definition: ladel_global.c:101
Structures and types used in LADEL routines.
int64_t ladel_int
Type for integer numbers (default: int64_t)
Definition: ladel_types.h:24
double ladel_double
Type for floating point numbers (default: double)
Definition: ladel_types.h:20
Sparse matrix in compressed column storage.
Definition: ladel_types.h:35
ladel_int symmetry
type of symmetry (UNSYMMETRIC, UPPER or LOWER)
Definition: ladel_types.h:46
ladel_int ncol
number of columns
Definition: ladel_types.h:38
ladel_double * x
numerical values (size nzmax)
Definition: ladel_types.h:42
ladel_int * p
column pointers (size ncol+1)
Definition: ladel_types.h:40
ladel_int values
has numerical values
Definition: ladel_types.h:45
ladel_int nrow
number of rows
Definition: ladel_types.h:37
ladel_int * i
row pointers (size nzmax)
Definition: ladel_types.h:41
Workspace required for various routines in LADEL.
Definition: ladel_types.h:109
ladel_int flag
Flag used to mark nodes, used in conjunction with array_int_ncol_flag.
Definition: ladel_types.h:121
ladel_int * array_int_ncol_flag
An array of ncol integers, assumed to be < flag.
Definition: ladel_types.h:120
ladel_double * array_double_all_zeros_ncol1
An array of ncol doubles, on input and output this should be all zeros.
Definition: ladel_types.h:122