umf_ltsolve.c
6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* ========================================================================== */
/* === UMF_ltsolve ========================================================== */
/* ========================================================================== */
/* -------------------------------------------------------------------------- */
/* UMFPACK Copyright (c) Timothy A. Davis, CISE, */
/* Univ. of Florida. All Rights Reserved. See ../Doc/License for License. */
/* web: http://www.cise.ufl.edu/research/sparse/umfpack */
/* -------------------------------------------------------------------------- */
/* Solves L'x = b or L.'x=b, where L is the lower triangular factor of a */
/* matrix. B is overwritten with the solution X. */
/* Returns the floating point operation count */
#include "umf_internal.h"
GLOBAL double
#ifdef CONJUGATE_SOLVE
UMF_lhsolve /* solve L'x=b (complex conjugate transpose) */
#else
UMF_ltsolve /* solve L.'x=b (array transpose) */
#endif
(
NumericType *Numeric,
Entry X [ ], /* b on input, solution x on output */
Int Pattern [ ] /* a work array of size n */
)
{
Entry xk ;
Entry *xp, *Lval ;
Int k, deg, *ip, j, row, *Lpos, *Lilen, kstart, kend, *Lip, llen,
lp, pos, npiv, n1, *Li ;
/* ---------------------------------------------------------------------- */
if (Numeric->n_row != Numeric->n_col) return (0.) ;
npiv = Numeric->npiv ;
Lpos = Numeric->Lpos ;
Lilen = Numeric->Lilen ;
Lip = Numeric->Lip ;
kstart = npiv ;
n1 = Numeric->n1 ;
#ifndef NDEBUG
DEBUG4 (("Ltsolve start:\n")) ;
for (j = 0 ; j < Numeric->n_row ; j++)
{
DEBUG4 (("Ltsolve start "ID": ", j)) ;
EDEBUG4 (X [j]) ;
DEBUG4 (("\n")) ;
}
#endif
/* ---------------------------------------------------------------------- */
/* non-singletons */
/* ---------------------------------------------------------------------- */
for (kend = npiv-1 ; kend >= n1 ; kend = kstart-1)
{
/* ------------------------------------------------------------------ */
/* find the start of this Lchain */
/* ------------------------------------------------------------------ */
/* for (kstart = kend ; kstart >= 0 && Lip [kstart] > 0 ; kstart--) ; */
kstart = kend ;
while (kstart >= 0 && Lip [kstart] > 0)
{
kstart-- ;
}
/* the Lchain goes from kstart to kend */
/* ------------------------------------------------------------------ */
/* scan the whole chain to find the pattern of the last column of L */
/* ------------------------------------------------------------------ */
deg = 0 ;
DEBUG4 (("start of chain for column of L\n")) ;
for (k = kstart ; k <= kend ; k++)
{
ASSERT (k >= 0 && k < npiv) ;
/* -------------------------------------------------------------- */
/* make column k of L in Pattern [0..deg-1] */
/* -------------------------------------------------------------- */
/* remove pivot row */
pos = Lpos [k] ;
if (pos != EMPTY)
{
DEBUG4 ((" k "ID" removing row "ID" at position "ID"\n",
k, Pattern [pos], pos)) ;
ASSERT (k != kstart) ;
ASSERT (deg > 0) ;
ASSERT (pos >= 0 && pos < deg) ;
ASSERT (Pattern [pos] == k) ;
Pattern [pos] = Pattern [--deg] ;
}
/* concatenate the pattern */
lp = Lip [k] ;
if (k == kstart)
{
lp = -lp ;
}
ASSERT (lp > 0) ;
ip = (Int *) (Numeric->Memory + lp) ;
llen = Lilen [k] ;
for (j = 0 ; j < llen ; j++)
{
row = *ip++ ;
DEBUG4 ((" row "ID" k "ID"\n", row, k)) ;
ASSERT (row > k) ;
Pattern [deg++] = row ;
}
}
/* Pattern [0..deg-1] is now the pattern of column kend */
/* ------------------------------------------------------------------ */
/* solve using this chain, in reverse order */
/* ------------------------------------------------------------------ */
DEBUG4 (("Unwinding Lchain\n")) ;
for (k = kend ; k >= kstart ; k--)
{
/* -------------------------------------------------------------- */
/* use column k of L */
/* -------------------------------------------------------------- */
ASSERT (k >= 0 && k < npiv) ;
lp = Lip [k] ;
if (k == kstart)
{
lp = -lp ;
}
ASSERT (lp > 0) ;
llen = Lilen [k] ;
xp = (Entry *) (Numeric->Memory + lp + UNITS (Int, llen)) ;
xk = X [k] ;
for (j = 0 ; j < deg ; j++)
{
DEBUG4 ((" row "ID" k "ID" value", Pattern [j], k)) ;
EDEBUG4 (*xp) ;
DEBUG4 (("\n")) ;
#ifdef CONJUGATE_SOLVE
/* xk -= X [Pattern [j]] * conjugate (*xp) ; */
MULT_SUB_CONJ (xk, X [Pattern [j]], *xp) ;
#else
/* xk -= X [Pattern [j]] * (*xp) ; */
MULT_SUB (xk, X [Pattern [j]], *xp) ;
#endif
xp++ ;
}
X [k] = xk ;
/* -------------------------------------------------------------- */
/* construct column k-1 of L */
/* -------------------------------------------------------------- */
/* un-concatenate the pattern */
deg -= llen ;
/* add pivot row */
pos = Lpos [k] ;
if (pos != EMPTY)
{
DEBUG4 ((" k "ID" adding row "ID" at position "ID"\n",
k, k, pos)) ;
ASSERT (k != kstart) ;
ASSERT (pos >= 0 && pos <= deg) ;
Pattern [deg++] = Pattern [pos] ;
Pattern [pos] = k ;
}
}
}
/* ---------------------------------------------------------------------- */
/* singletons */
/* ---------------------------------------------------------------------- */
for (k = n1 - 1 ; k >= 0 ; k--)
{
DEBUG4 (("Singleton k "ID"\n", k)) ;
deg = Lilen [k] ;
if (deg > 0)
{
xk = X [k] ;
lp = Lip [k] ;
Li = (Int *) (Numeric->Memory + lp) ;
lp += UNITS (Int, deg) ;
Lval = (Entry *) (Numeric->Memory + lp) ;
for (j = 0 ; j < deg ; j++)
{
DEBUG4 ((" row "ID" k "ID" value", Li [j], k)) ;
EDEBUG4 (Lval [j]) ;
DEBUG4 (("\n")) ;
#ifdef CONJUGATE_SOLVE
/* xk -= X [Li [j]] * conjugate (Lval [j]) ; */
MULT_SUB_CONJ (xk, X [Li [j]], Lval [j]) ;
#else
/* xk -= X [Li [j]] * Lval [j] ; */
MULT_SUB (xk, X [Li [j]], Lval [j]) ;
#endif
}
X [k] = xk ;
}
}
#ifndef NDEBUG
for (j = 0 ; j < Numeric->n_row ; j++)
{
DEBUG4 (("Ltsolve done "ID": ", j)) ;
EDEBUG4 (X [j]) ;
DEBUG4 (("\n")) ;
}
DEBUG4 (("Ltsolve done.\n")) ;
#endif
return (MULTSUB_FLOPS * ((double) Numeric->lnz)) ;
}