LADEL main
Sparse LDL factorization package with rank 1 and rowadd/rowdel updates
ladel_postorder.c
Go to the documentation of this file.
1#include "ladel_types.h"
2#include "ladel_global.h"
3
4#define STACK_NOT_EMPTY (top >= 0)
5
6static ladel_int ladel_depth_first_search( ladel_int root,
7 ladel_int post_index,
8 ladel_int *first_child,
9 ladel_int *next_child,
10 ladel_int *stack,
11 ladel_int *postorder)
12{
13 ladel_int current_node, current_child, top = 0;
14
15 stack[top] = root;
16 while (STACK_NOT_EMPTY)
17 {
18 current_node = stack[top];
19 current_child = first_child[current_node];
20 if (current_child == NONE)
21 {
22 top--;
23 postorder[post_index] = current_node;
24 post_index++;
25 } else
26 {
27 first_child[current_node] = next_child[current_child];
28 top++;
29 stack[top] = current_child;
30 }
31 }
32 return post_index;
33}
34
36{
37 if (!M || !sym || !sym->etree || !work) return FAIL;
38
39 ladel_int *etree = sym->etree, *postorder = sym->postorder;
40
41 ladel_int col, ncol = M->ncol, prev_root = NONE, post_index = 0;
42 ladel_int *first_child, *next_child, *stack, *roots;
43 first_child = work->array_int_ncol1;
44 next_child = work->array_int_ncol2;
45 stack = work->array_int_ncol3;
46 roots = work->array_int_ncol4;
47
48 for (col = 0; col < ncol; col++) first_child[col] = NONE;
49 for (col = ncol-1; col >= 0; col--)
50 {
51 if (IS_ROOT(col, etree))
52 {
53 roots[col] = prev_root;
54 prev_root = col;
55 } else
56 {
57 next_child[col] = first_child[etree[col]];
58 first_child[etree[col]] = col;
59 }
60 }
61 for (col = prev_root; col != NONE; col = roots[col])
62 {
63 post_index = ladel_depth_first_search(col, post_index, first_child, next_child, stack, postorder);
64 }
65
66 return SUCCESS;
67}
#define NONE
Indicates a root (a node without parent), or an untouched node.
#define SUCCESS
For status returns.
#define FAIL
For status returns.
#define IS_ROOT(col, etree)
Check whether a node is a root (i.e.
Memory allocation routines.
ladel_int ladel_postorder(ladel_sparse_matrix *M, ladel_symbolics *sym, ladel_work *work)
Compute the postordering of the elimination tree.
#define STACK_NOT_EMPTY
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
ladel_int ncol
number of columns
Definition: ladel_types.h:38
Structure capturing symbolic information used for and during the factorization.
Definition: ladel_types.h:54
ladel_int * etree
eliminations tree
Definition: ladel_types.h:56
ladel_int * postorder
postordiring of the elimination tree
Definition: ladel_types.h:57
Workspace required for various routines in LADEL.
Definition: ladel_types.h:109
ladel_int * array_int_ncol2
An array of ncol integers.
Definition: ladel_types.h:117
ladel_int * array_int_ncol1
An array of ncol integers.
Definition: ladel_types.h:116
ladel_int * array_int_ncol3
An array of ncol integers.
Definition: ladel_types.h:118
ladel_int * array_int_ncol4
An array of ncol integers.
Definition: ladel_types.h:119