44
Prob = UFget (f (kk)) ;
46
if (isfield (Prob, 'kind'))
47
if (~isempty (strfind (Prob.kind, 'subsequent')))
48
fprintf ('skip ...\n') ;
51
if (~isempty (strfind (Prob.kind, 'random')))
52
fprintf ('skip ...\n') ;
69
A = sprand (A) + 1i * sprand (A) ;
72
% compare with UMFPACK
74
[L,U,p,q,R1] = lu (A, 'vector') ;
78
LUnz (k) = nnz (L) + nnz (U) ;
81
% note that the scaling R1 and R2 are different with KLU and UMFPACK.
82
% UMFPACK: L*U-P*(R1\A)*Q
85
% R1 and R2 are related, via P, where R2 = P*R*P', or equivalently
88
if (any (diag (U) == 0))
89
fprintf ('skip...\n') ;
105
x = klu (F, '\', b) ;
106
y = klu (b', '/', F) ;
108
fprintf ('solve with klu %g\n', ...
109
norm (A*x-b,1)/norm(A,1)) ;
110
fprintf ('solve with klu %g transpose\n', ...
111
norm (y*A-b',1)/norm(A,1)) ;
118
b = b + 1i * rand (n, nrhs) ;
127
xt = klu (b','/',A) ;
129
% KLU backslash with precomputed LU
135
% KLU slash with precomputed LU
136
zt = klu (b','/',LU) ;
137
% fprintf ('zt err: %g Aimag %d nrhs %d bimag %d\n', ...
138
% norm (zt*A-b',1), do_imag, nrhs, do_b_imag) ;
143
y = U \ (L \ rb (p,:)) ;
150
yt = (L' \ (U' \ b (q,:))) ;
159
Tlu (k) = Tlu (k) + t3 ;
164
err1 = max (err1, norm (A*x-b,1) / norm (A,1)) ;
165
err2 = max (err2, norm (A*y-b,1) / norm (A,1)) ;
166
err4 = max (err4, norm (A*z-b,1) / norm (A,1)) ;
168
terr1 = max (terr1, norm (xt*A-b',1) / norm (A,1)) ;
169
terr2 = max (terr2, norm (yt*A-b',1) / norm (A,1)) ;
170
terr4 = max (terr4, norm (zt*A-b',1) / norm (A,1)) ;
175
fprintf ('err %g %g %g\n', err1, err2, err4) ;
176
if (err1 > 1e4*err2 | err4 > 1e4*err2) %#ok
177
fprintf ('warning: KLU inaccurate!\n')
180
fprintf ('terr %g %g %g\n', terr1, terr2, terr4) ;
181
if (terr1 > 1e4*terr2 | terr4 > 1e4*terr2) %#ok
182
fprintf ('warning: KLU T inaccurate!\n')
185
lunzmax = max (LUnz (1:k)) ;
187
LUnz (1:k), Tklu (1:k) ./ Tlu (1:k), 'o', ...
188
LUnz (1:k), Tklu2 (1:k) ./ Tlu (1:k), 'x', ...
189
[10 lunzmax], [1 1], 'r-') ;
44
h = waitbar (0, 'KLU test 4 of 5') ;
53
Prob = UFget (f (kk), index) ;
55
waitbar (kk/nmat, h) ;
58
if (isfield (Prob, 'kind'))
59
if (~isempty (strfind (Prob.kind, 'subsequent')))
60
fprintf ('skip ...\n') ;
63
if (~isempty (strfind (Prob.kind, 'random')))
64
fprintf ('skip ...\n') ;
81
A = sprand (A) + 1i * sprand (A) ;
84
% compare with UMFPACK
87
[L,U,p,q,R1] = lu (A, 'vector') ;
88
t1 = max (1e-6, toc) ;
90
% older version of MATLAB, which doesn't have 'vector' option
93
t1 = max (1e-6, toc) ;
94
[p ignore1 ignore2] = find (P') ;
95
[q ignore1 ignore2] = find (Q) ;
96
clear ignore1 ignore2 P Q
102
LUnz (k) = nnz (L) + nnz (U) ;
105
% note that the scaling R1 and R2 are different with KLU and UMFPACK
106
% UMFPACK: L*U-P*(R1\A)*Q
107
% KLU: L*U-R2\(P*A*Q)
109
% R1 and R2 are related, via P, where R2 = P*R*P', or equivalently
112
rcond = min (abs (diag (U))) / max (abs (diag (U))) ;
114
fprintf ('skip...\n') ;
130
x = klu (F, '\', b) ;
131
y = klu (b', '/', F) ;
133
fprintf ('solve with klu %g\n', ...
134
norm (A*x-b,1)/norm(A,1)) ;
135
fprintf ('solve with klu %g transpose\n', ...
136
norm (y*A-b',1)/norm(A,1)) ;
143
b = b + 1i * rand (n, nrhs) ;
149
t2 = max (1e-6, toc) ;
152
xt = klu (b','/',A) ;
154
% KLU backslash with precomputed LU
158
t4 = max (1e-6, toc) ;
160
% KLU slash with precomputed LU
161
zt = klu (b','/',LU) ;
166
y = U \ (L \ rb (p,:)) ;
168
t3 = max (1e-6, toc) ;
170
yt = (L' \ (U' \ b (q,:))) ;
176
Tlu (k) = Tlu (k) + t3 ;
181
err1 = max (err1, norm (A*x-b,1) / norm (A,1)) ;
182
err2 = max (err2, norm (A*y-b,1) / norm (A,1)) ;
183
err4 = max (err4, norm (A*z-b,1) / norm (A,1)) ;
185
terr1 = max (terr1, norm (xt*A-b',1) / norm (A,1)) ;
186
terr2 = max (terr2, norm (yt*A-b',1) / norm (A,1)) ;
187
terr4 = max (terr4, norm (zt*A-b',1) / norm (A,1)) ;
192
fprintf ('err %g %g %g\n', err1, err2, err4) ;
193
if (err1 > 1e4*err2 | err4 > 1e4*err2) %#ok
194
fprintf ('warning: KLU inaccurate!\n')
197
fprintf ('terr %g %g %g\n', terr1, terr2, terr4) ;
198
if (terr1 > 1e4*terr2 | terr4 > 1e4*terr2) %#ok
199
fprintf ('warning: KLU T inaccurate!\n')
202
lunzmax = max (LUnz (1:k)) ;
204
LUnz (1:k), Tklu (1:k) ./ Tlu (1:k), 'o', ...
205
LUnz (1:k), Tklu2 (1:k) ./ Tlu (1:k), 'x', ...
206
[10 lunzmax], [1 1], 'r-') ;
212
% out-of-memory is OK, other errors are not
214
if (isempty (strfind (lasterr, 'Out of memory')))
215
error (lasterr) ; %#ok
217
fprintf ('test terminated early, but otherwise OK\n') ;