LADEL main
Sparse LDL factorization package with rank 1 and rowadd/rowdel updates
ladel_global.h
Go to the documentation of this file.
1/**
2 * @file ladel_global.h
3 * @author Ben Hermans
4 * @brief Memory allocation routines.
5 */
6
7#ifndef LADEL_GLOBAL_H
8#define LADEL_GLOBAL_H
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include "ladel_types.h"
15#include "ladel_constants.h"
16#include "ladel_copy.h"
17#include <stdlib.h>
18
19typedef void *(calloc_sig)(size_t, size_t);
20typedef void *(malloc_sig)(size_t);
21typedef void *(realloc_sig)(void *, size_t);
22typedef void (free_sig)(void *);
23
24/** Set the `calloc` function used by LADEL. */
26/** Set the `malloc` function used by LADEL. */
28/** Set the `realloc` function used by LADEL. */
30/** Set the `free` function used by LADEL. */
32
33/**
34 * Version of malloc (for mex or for regular C).
35 *
36 * If the malloc fails, this function will return NULL.
37 *
38 * @param n Number of blocks
39 * @param size Size of block
40 * @return Pointer to the allocated memory
41 */
42void *ladel_malloc( ladel_int n,
43 size_t size);
44
45/**
46 * Version of calloc (for mex or for regular C).
47 *
48 * If the calloc fails, this function will return NULL.
49 *
50 * @param n Number of blocks
51 * @param size Size of block
52 * @return Pointer to the allocated memory
53 */
54void *ladel_calloc( ladel_int n,
55 size_t size);
56
57/**
58 * Version of free (for mex or for regular C).
59 *
60 * @param p Pointer to the memory to be freed
61 * @return NULL
62 */
63void *ladel_free(void* p);
64
65/**
66 * Version of realloc (for mex or for regular C).
67 *
68 * If the realloc fails, this function will return the original pointer.
69 *
70 * @param p Pointer to the memory
71 * @param n Number of blocks
72 * @param size Size of block
73 * @param status Status to indicate success
74 * @return Pointer to the reallocated memory (or the same in case )
75 */
76void *ladel_realloc(void *p,
77 ladel_int n,
78 size_t size,
79 ladel_int *status);
80
81#ifdef __GNUC__
82#define LADEL_ATTR_PRINTF_LIKE __attribute__((format(printf, 1, 2)))
83#else
84#define LADEL_ATTR_PRINTF_LIKE
85#endif
86
87typedef LADEL_ATTR_PRINTF_LIKE int (printf_sig)(const char *, ...);
88
89/** Set the `printf` function used by LADEL. */
91/** Get the `printf` function used by LADEL. */
93
94/**
95 * Print function.
96 */
97#define ladel_print ladel_get_print_config_printf()
98
99/**
100 * Free a sparse matrix (and return NULL).
101 *
102 * @param M Matrix to be freed
103 * @return NULL
104 */
106
107/**
108 * Allocate a sparse matrix.
109 *
110 * @param nrow Number of rows
111 * @param ncol Number of columns
112 * @param nzmax Maximum number of nonzeros
113 * @param symmetry UNSYMMETRIC, or store only UPPER part of a matrix
114 * @param values Indicate value or pattern matrix
115 * @param nz Indicate the use of the nz field to list nonzeros per column
116 * @return Allocated matrix
117 */
119 ladel_int ncol,
120 ladel_int nzmax,
121 ladel_int symmetry,
122 ladel_int values,
123 ladel_int nz);
124/**
125 * Allocate a sparse empty matrix (used in special cases).
126 *
127 * @param nrow Number of rows
128 * @param ncol Number of columns
129 * @param symmetry UNSYMMETRIC, or store only UPPER part of a matrix
130 * @param values Indicate value or pattern matrix
131 * @param nz Indicate the use of the nz field to list nonzeros per column
132 * @return Allocated empty matrix
133 */
135 ladel_int ncol,
136 ladel_int symmetry,
137 ladel_int values,
138 ladel_int nz);
139
140/**
141 * Reallocate a sparse matrix with a new size.
142 *
143 * @note If nzmax <= 0, the matrix is shrinked to fit all the current elements.
144 *
145 * @param M Sparse matrix
146 * @param nzmax New maximum number of nonzeros
147 * @return Status
148 */
150 ladel_int nzmax);
151
152/**
153 * Free a symbolics struct (and return NULL).
154 *
155 * @param sym Symbolics struct
156 * @return NULL
157 */
159
160/**
161 * Allocate a symbolics struct.
162 *
163 * @param ncol Number of columns of matrix to be analyzed
164 * @return Allocated symbolics struct
165 */
167
168/**
169 * Free a factor.
170 *
171 * @param LD Factors of an @f$LDL^T@f$ factorization
172 * @return NULL
173 */
175
176/**
177 * Allocate a factors struct.
178 *
179 * @param sym Symbolics struct
180 * @return Factors struct
181 */
183
184/**
185 * Free a set.
186 *
187 * @param set Set to be freed
188 * @return NULL
189 */
191
192/**
193 * Allocate a set struct.
194 *
195 * @param max_size Maximum size of the set
196 * @return Allocated set
197 */
199
200/**
201 * Fill in the fields of the given set.
202 *
203 * @param set Set to be filled in
204 * @param set_vals Array that represents the set
205 * @param size_set Current size of the set
206 * @param max_size_set Maximum size of the set
207 */
208void ladel_set_set( ladel_set *set,
209 ladel_int *set_vals,
210 ladel_int size_set,
211 ladel_int max_size_set);
212
213/**
214 * Free a LADEL workspace.
215 *
216 * @param work LADEL workspace to be freed
217 * @return NULL
218 */
220
221/**
222 * Allocate a LADEL workspace.
223 *
224 * @param ncol Size of the structures in the workspace (= ncol of matrix to be factorized)
225 * @return Allocated LADEL workspace
226 */
228
229
230#ifdef __cplusplus
231}
232#endif
233
234#endif /*LADEL_GLOBAL_H*/
Constants and macros used in LADEL.
Routines to copy matrices and vectors.
ladel_work * ladel_workspace_free(ladel_work *work)
Free a LADEL workspace.
Definition: ladel_global.c:254
void * ladel_calloc(ladel_int n, size_t size)
Version of calloc (for mex or for regular C).
Definition: ladel_global.c:56
void *() malloc_sig(size_t)
Definition: ladel_global.h:20
malloc_sig * ladel_set_alloc_config_malloc(malloc_sig *malloc)
Set the malloc function used by LADEL.
Definition: ladel_global.c:31
calloc_sig * ladel_set_alloc_config_calloc(calloc_sig *calloc)
Set the calloc function used by LADEL.
Definition: ladel_global.c:24
#define LADEL_ATTR_PRINTF_LIKE
Definition: ladel_global.h:84
ladel_factor * ladel_factor_free(ladel_factor *LD)
Free a factor.
Definition: ladel_global.c:183
ladel_symbolics * ladel_symbolics_free(ladel_symbolics *sym)
Free a symbolics struct (and return NULL).
Definition: ladel_global.c:153
printf_sig * ladel_set_print_config_printf(printf_sig *printf)
Set the printf function used by LADEL.
Definition: ladel_global.c:80
realloc_sig * ladel_set_alloc_config_realloc(realloc_sig *realloc)
Set the realloc function used by LADEL.
Definition: ladel_global.c:38
void() free_sig(void *)
Definition: ladel_global.h:22
void *() calloc_sig(size_t, size_t)
Definition: ladel_global.h:19
LADEL_ATTR_PRINTF_LIKE int() printf_sig(const char *,...)
Definition: ladel_global.h:87
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
void ladel_set_set(ladel_set *set, ladel_int *set_vals, ladel_int size_set, ladel_int max_size_set)
Fill in the fields of the given set.
Definition: ladel_global.c:247
ladel_symbolics * ladel_symbolics_alloc(ladel_int ncol)
Allocate a symbolics struct.
Definition: ladel_global.c:166
ladel_set * ladel_set_allocate(ladel_int max_size)
Allocate a set struct.
Definition: ladel_global.c:233
void * ladel_realloc(void *p, ladel_int n, size_t size, ladel_int *status)
Version of realloc (for mex or for regular C).
Definition: ladel_global.c:66
void * ladel_malloc(ladel_int n, size_t size)
Version of malloc (for mex or for regular C).
Definition: ladel_global.c:52
ladel_sparse_matrix * ladel_sparse_alloc_empty(ladel_int nrow, ladel_int ncol, ladel_int symmetry, ladel_int values, ladel_int nz)
Allocate a sparse empty matrix (used in special cases).
Definition: ladel_global.c:122
void * ladel_free(void *p)
Version of free (for mex or for regular C).
Definition: ladel_global.c:60
ladel_work * ladel_workspace_allocate(ladel_int ncol)
Allocate a LADEL workspace.
Definition: ladel_global.c:273
ladel_factor * ladel_factor_allocate(ladel_symbolics *sym)
Allocate a factors struct.
Definition: ladel_global.c:194
printf_sig * ladel_get_print_config_printf(void)
Get the printf function used by LADEL.
Definition: ladel_global.c:87
free_sig * ladel_set_alloc_config_free(free_sig *free)
Set the free function used by LADEL.
Definition: ladel_global.c:45
void *() realloc_sig(void *, size_t)
Definition: ladel_global.h:21
ladel_set * ladel_set_free(ladel_set *set)
Free a set.
Definition: ladel_global.c:226
ladel_int ladel_sparse_realloc(ladel_sparse_matrix *M, ladel_int nzmax)
Reallocate a sparse matrix with a new size.
Definition: ladel_global.c:141
ladel_sparse_matrix * ladel_sparse_free(ladel_sparse_matrix *M)
Free a sparse matrix (and return NULL).
Definition: ladel_global.c:91
Structures and types used in LADEL routines.
int64_t ladel_int
Type for integer numbers (default: int64_t)
Definition: ladel_types.h:24
Sparse matrix in compressed column storage.
Definition: ladel_types.h:35
Set of integers.
Definition: ladel_types.h:81
Factors of an factorization.
Definition: ladel_types.h:69
Structure capturing symbolic information used for and during the factorization.
Definition: ladel_types.h:54
Workspace required for various routines in LADEL.
Definition: ladel_types.h:109