LADEL main
Sparse LDL factorization package with rank 1 and rowadd/rowdel updates
ladel.c
Go to the documentation of this file.
1#include "ladel_types.h"
2#include "ladel_constants.h"
3#include "ladel_global.h"
5#include "ladel_ldl_numeric.h"
6#include "ladel_permutation.h"
7#include "ladel_etree.h"
8#include "ladel_debug_print.h"
9#include "ladel.h"
10
12{
13 ladel_diag d;
14 d.diag_size = 0;
15 return ladel_factorize_with_diag(M, d, sym, ordering_method, LD, work);
16}
17
19{
20 if (!M || !sym || !work) return FAIL;
21
22 ladel_int ok_symbolic, ok_numeric;
24
25 if (ordering_method != NO_ORDERING) Mpp = ladel_sparse_alloc(M->nrow, M->ncol, M->nzmax, M->symmetry, M->values, FALSE);
26 else Mpp = M;
27
28 if (!Mpp) return FAIL;
29 ok_symbolic = ladel_ldl_symbolic(M, sym, ordering_method, Mpp, work);
30 if (ok_symbolic == FAIL) return FAIL;
31
32 *LD = ladel_factor_allocate(sym);
33 if (!*LD)
34 {
35 if (ordering_method != NO_ORDERING) ladel_sparse_free(Mpp);
36 return FAIL;
37 }
38 if (!Mpp) return FAIL;
39 ok_numeric = ladel_ldl_numeric_with_diag(Mpp, d, sym, *LD, work);
40
41 if (ordering_method != NO_ORDERING) ladel_sparse_free(Mpp);
42 if (ok_symbolic && ok_numeric) return SUCCESS;
43 else return FAIL;
44}
45
47{
48 ladel_diag d;
49 d.diag_size = 0;
50 return ladel_factorize_advanced_with_diag(M, d, sym, ordering_method, LD, Mbasis, work);
51}
52
54{
55 if (!M || !sym || !Mbasis || !work) return FAIL;
56
57 ladel_int ok_symbolic, ok_numeric;
59
60 if (ordering_method != NO_ORDERING) Mpp = ladel_sparse_alloc(Mbasis->nrow, Mbasis->ncol, Mbasis->nzmax, Mbasis->symmetry, Mbasis->values, FALSE);
61 else Mpp = Mbasis;
62
63 if (!Mpp) return FAIL;
64 ok_symbolic = ladel_ldl_symbolic(Mbasis, sym, ordering_method, Mpp, work);
65 *LD = ladel_factor_allocate(sym);
66 if (!*LD)
67 {
68 if (ordering_method != NO_ORDERING) ladel_sparse_free(Mpp);
69 return FAIL;
70 }
71 if (sym->p)
72 {
74 Mpp = ladel_sparse_alloc(M->nrow, M->ncol, M->nzmax, M->symmetry, M->values, FALSE);
75 ladel_permute_symmetric_matrix(M, sym->p, Mpp, work);
76 } else
77 {
78 Mpp = M;
79 }
80
81 ladel_etree(Mpp, sym, work);
82
83 ok_numeric = ladel_ldl_numeric_with_diag(Mpp, d, sym, *LD, work);
84
85 if (ordering_method != NO_ORDERING) ladel_sparse_free(Mpp);
86 if (ok_symbolic && ok_numeric) return SUCCESS;
87 else return FAIL;
88}
89
91{
92 ladel_diag d;
93 d.diag_size = 0;
94 return ladel_factorize_with_prior_basis_with_diag(M, d, sym, LD, work);
95}
96
98{
99 if (!M || !sym || !LD || !work) return FAIL;
100
101 ladel_int ok_numeric;
103
104 if (sym->p)
105 {
106 Mpp = ladel_sparse_alloc(M->nrow, M->ncol, M->nzmax, M->symmetry, M->values, FALSE);
107 ladel_permute_symmetric_matrix(M, sym->p, Mpp, work);
108 } else
109 {
110 Mpp = M;
111 }
112
113 ladel_etree(Mpp, sym, work);
114 ok_numeric = ladel_ldl_numeric_with_diag(Mpp, d, sym, LD, work);
115
116 if (sym->p) ladel_sparse_free(Mpp);
117 return ok_numeric;
118}
119
121{
122 if (!LD || !rhs || !y || !work) return FAIL;
123
124 ladel_sparse_matrix *L = LD->L;
125 ladel_double *Dinv = LD->Dinv;
126 ladel_int index, row, ncol = LD->L->ncol;
127 if (LD->p) for (row = 0; row < ncol; row++) y[row] = rhs[LD->p[row]];
128 else for (row = 0; row < ncol; row++) y[row] = rhs[row];
129
130 for (row = 0; row < ncol; row++)
131 {
132 for (index = L->p[row]; index < L->p[row]+L->nz[row]; index++)
133 {
134 y[L->i[index]] -= L->x[index]*y[row];
135 }
136 }
137 for (row = 0; row < ncol; row++) y[row] *= Dinv[row];
138 for (row = ncol-1; row >= 0; row--)
139 {
140 for (index = L->p[row]; index < L->p[row]+L->nz[row]; index++)
141 {
142 y[row] -= L->x[index]*y[L->i[index]];
143 }
144 }
145
146 if (LD->p)
147 {
149 for (row = 0; row < ncol; row++) temp[row] = y[row];
150 for (row = 0; row < ncol; row++)
151 {
152 y[LD->p[row]] = temp[row];
153 temp[row] = 0.0; /*reset to keep the workspace consistent*/
154 }
155 }
156 return SUCCESS;
157}
#define NO_ORDERING
No ordering is performed during the symbolic part of the factorization.
#define SUCCESS
For status returns.
#define FALSE
For booleans.
#define FAIL
For status returns.
ladel_int ladel_dense_solve(const ladel_factor *LD, const ladel_double *rhs, ladel_double *y, ladel_work *work)
Computes .
Definition: ladel.c:120
ladel_int ladel_factorize_with_diag(ladel_sparse_matrix *M, ladel_diag d, ladel_symbolics *sym, ladel_int ordering_method, ladel_factor **LD, ladel_work *work)
Computes the factorization of .
Definition: ladel.c:18
ladel_int ladel_factorize(ladel_sparse_matrix *M, ladel_symbolics *sym, ladel_int ordering_method, ladel_factor **LD, ladel_work *work)
Computes the factorization of .
Definition: ladel.c:11
ladel_int ladel_factorize_with_prior_basis(ladel_sparse_matrix *M, ladel_symbolics *sym, ladel_factor *LD, ladel_work *work)
Computes the factorization of provided LD was allocated before.
Definition: ladel.c:90
ladel_int ladel_factorize_with_prior_basis_with_diag(ladel_sparse_matrix *M, ladel_diag d, ladel_symbolics *sym, ladel_factor *LD, ladel_work *work)
Computes the factorization of provided LD was allocated before.
Definition: ladel.c:97
ladel_int ladel_factorize_advanced(ladel_sparse_matrix *M, ladel_symbolics *sym, ladel_int ordering_method, ladel_factor **LD, ladel_sparse_matrix *Mbasis, ladel_work *work)
Computes the factorization of but allocates based on Mbasis.
Definition: ladel.c:46
ladel_int ladel_factorize_advanced_with_diag(ladel_sparse_matrix *M, ladel_diag d, ladel_symbolics *sym, ladel_int ordering_method, ladel_factor **LD, ladel_sparse_matrix *Mbasis, ladel_work *work)
Computes the factorization of but allocates based on Mbasis.
Definition: ladel.c:53
LADEL main include file.
Constants and macros used in LADEL.
Routines to print out matrices and vectors.
Routines to compute the elimination tree of a matrix.
ladel_int ladel_etree(ladel_sparse_matrix *M, ladel_symbolics *sym, ladel_work *work)
Computes the elimination tree of a matrix.
Definition: ladel_etree.c:6
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
ladel_factor * ladel_factor_allocate(ladel_symbolics *sym)
Allocate a factors struct.
Definition: ladel_global.c:194
ladel_sparse_matrix * ladel_sparse_free(ladel_sparse_matrix *M)
Free a sparse matrix (and return NULL).
Definition: ladel_global.c:91
The numerical part of the factorization.
ladel_int ladel_ldl_numeric_with_diag(ladel_sparse_matrix *Mpp, ladel_diag d, ladel_symbolics *sym, ladel_factor *LD, ladel_work *work)
Numerical part of the factorization of .
The symbolic part of the factorization.
ladel_int ladel_ldl_symbolic(ladel_sparse_matrix *M, ladel_symbolics *sym, ladel_int ordering_method, ladel_sparse_matrix *Mpp, ladel_work *work)
Symbolic part of the factorization.
Routines to permute vectors and matrices.
void ladel_permute_symmetric_matrix(ladel_sparse_matrix *M, ladel_int *p, ladel_sparse_matrix *Mpp, ladel_work *work)
Compute .
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 nzmax
number of nonzeros
Definition: ladel_types.h:36
ladel_int * p
column pointers (size ncol+1)
Definition: ladel_types.h:40
ladel_int * nz
(optional) number of elements in each column (size ncol)
Definition: ladel_types.h:43
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
Structure representing a multiple of the identity matrix.
Definition: ladel_types.h:100
ladel_int diag_size
Size of the matrix.
Definition: ladel_types.h:102
Factors of an factorization.
Definition: ladel_types.h:69
ladel_int * p
permutation vector
Definition: ladel_types.h:74
ladel_sparse_matrix * L
L in LDL' factorization.
Definition: ladel_types.h:71
ladel_double * Dinv
D^-1 in LDL' factorization (stored as vector)
Definition: ladel_types.h:73
Structure capturing symbolic information used for and during the factorization.
Definition: ladel_types.h:54
ladel_int * p
fill-reducing ordering (possibly AMD)
Definition: ladel_types.h:59
Workspace required for various routines in LADEL.
Definition: ladel_types.h:109
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