File: trysuperlu.m

package info (click to toggle)
superlu 5.3.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,976 kB
  • sloc: ansic: 59,420; makefile: 405; fortran: 185; csh: 141
file content (219 lines) | stat: -rw-r--r-- 7,590 bytes parent folder | download | duplicates (7)
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
function failed = trysuperlu(A);
% TRYSUPERLU : Test the Matlab interface to superlu.
%
% failed = trysuperlu;  
%          This runs several tests on superlu, using a matrix with the
%          structure of "smallmesh".  It returns a list of failed tests.
%
% failed = trysuperlu(A);
%          This just times the factorization of A.
%
% Copyright (c) 1995 by Xerox Corporation.  All rights reserved.
% HELP COPYRIGHT for complete copyright and licensing notice.

disp(' ');
disp(['Testing SUPERLU on ' time]);
disp(' ');

resetrandoms;
if nargin == 0
    A = hbo('smallmesh');
end;
[n,m] = size(A);
if n~=m, error('matrix must be square'), end;

failed = [];
ntest = 0;
tol = 100 * eps * n^2;

if nargin == 1 % Just try to factor the given input matrix.
    ntest=ntest+1;
    fprintf('Matrix size: %d by %d with %d nonzeros.\n',n,m,nnz(A));
    r = trytime(A);
    if r > tol, disp('*** FAILED ***'); failed = [failed ntest]; end;
    return;
end;

% With no input argument, try several tests on the small mesh.

PivPostA = sprandn(A);
A = (n+1)*speye(n) - spones(A); % Diagonally dominant
[t,post] = etree(A'*A);

if post == [1:n], disp('note: column etree already in postorder'), end;

NoPivPostA = A(post,:);
NoPivNoPostA = A(post,post);
PivNoPostA = sprandn(NoPivNoPostA);
p = randperm(n);
pinv = zeros(1,n);
pinv(p) = 1:n;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, no pivot, no postorder, 4 outputs.\n',ntest);
r = try4(NoPivNoPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, no pivot, no postorder, 3 outputs.\n',ntest);
r = try3(NoPivNoPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, no pivot, no postorder, 2 outputs.\n',ntest);
r = try2(NoPivNoPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, pivot, no postorder, 4 outputs.\n',ntest);
r = try4(PivNoPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, pivot, no postorder, 3 outputs.\n',ntest);
r = try3(PivNoPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, pivot, no postorder, 2 outputs.\n',ntest);
r = try2(PivNoPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, no pivot, postorder, 4 outputs.\n',ntest);
r = try4(NoPivPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, no pivot, postorder, 3 outputs.\n',ntest);
r = try3(NoPivPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, no pivot, postorder, 2 outputs.\n',ntest);
r = try2(NoPivPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, pivot, postorder, 4 outputs.\n',ntest);
r = try4(PivPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, pivot, postorder, 3 outputs.\n',ntest);
r = try3(PivPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm 0, pivot, postorder, 2 outputs.\n',ntest);
r = try2(PivPostA,0);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, no pivot, no postorder, 4 outputs.\n',ntest);
r = try4(NoPivNoPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, no pivot, no postorder, 3 outputs.\n',ntest);
r = try3(NoPivNoPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, no pivot, no postorder, 2 outputs.\n',ntest);
r = try2(NoPivNoPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, pivot, no postorder, 4 outputs.\n',ntest);
r = try4(PivNoPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, pivot, no postorder, 3 outputs.\n',ntest);
r = try3(PivNoPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, pivot, no postorder, 2 outputs.\n',ntest);
r = try2(PivNoPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, no pivot, postorder, 4 outputs.\n',ntest);
r = try4(NoPivPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, no pivot, postorder, 3 outputs.\n',ntest);
r = try3(NoPivPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, no pivot, postorder, 2 outputs.\n',ntest);
r = try2(NoPivPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, pivot, postorder, 4 outputs.\n',ntest);
r = try4(PivPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, pivot, postorder, 3 outputs.\n',ntest);
r = try3(PivPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given, pivot, postorder, 2 outputs.\n',ntest);
r = try2(PivPostA(:,pinv),p);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: No input perm (colamd done internally), pivot, postorder, 4 outputs.\n',ntest);
r = try4(PivPostA);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: No input perm, pivot, postorder, 3 outputs.\n',ntest);
r = try3(PivPostA);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: No input perm, pivot, postorder, 2 outputs.\n',ntest);
r = try3(PivPostA);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Input perm given as matrix, pivot, postorder, 4 outputs.\n',ntest);
P = speye(n);
P = P(p,:);
r = try4(PivPostA*P,P);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

ntest=ntest+1;
fprintf('Test %d: Empty matrix.\n',ntest);
[L,U,PROW,PCOL] = superlu([]);
disp(' ');
if max([size(L) size(U) size(PROW) size(PCOL)])
    L, U, PROW, PCOL
    disp('*** FAILED ***^G'), disp(' ');
    failed = [failed ntest];
end;

ntest=ntest+1;
fprintf('Test %d: Timing versus LU on the 3-element airfoil matrix.\n',ntest);
A = hbo('airfoil2');
n = max(size(A));
A = sprandn(A);
pmmd = colamd(A);
A = A(:,pmmd);
r = trytime(A);
if r > tol, disp('*** FAILED ***'), disp(' '), failed = [failed ntest]; end;

nfailed = length(failed);
if nfailed
    fprintf('\n%d tests failed.\n\n',nfailed);
else
    fprintf('\nAll tests passed.\n\n',nfailed);
end;