File: test23.m

package info (click to toggle)
suitesparse 1%3A5.12.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 176,720 kB
  • sloc: ansic: 1,193,914; cpp: 31,704; makefile: 6,638; fortran: 1,927; java: 1,826; csh: 765; ruby: 725; sh: 529; python: 333; perl: 225; sed: 164; awk: 35
file content (122 lines) | stat: -rw-r--r-- 2,943 bytes parent folder | download | duplicates (5)
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
function test23
%TEST23 test chol and cholmod2 on the sparse matrix used in "bench"
% Example:
%   test23
% See also cholmod_test

% Copyright 2007-2012, Timothy A. Davis, http://www.suitesparse.com

fprintf ('=================================================================\n');
fprintf ('test23: test chol & cholmod2 on the sparse matrix used in "bench"\n');

n = 120 ;
A = delsq (numgrid ('L', n)) ;
b = sum (A)' ;

fprintf ('Using each method''s internal fill-reducing ordering:\n') ;

tic ;
x = A\b ;
t1 = toc ;
e1 = norm (A*x-b) ;

tic ;
x = cholmod2 (A,b) ; 
t2 = toc ;
e2 = norm (A*x-b) ;

fprintf ('MATLAB  x=A\\b      time: %8.4f  resid: %8.0e\n', t1, e1) ;
fprintf ('CHOLMOD x=A\\b      time: %8.4f  resid: %8.0e\n', t2, e2) ;
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;

% get CHOLMOD's ordering (best of AMD and METIS)
p = analyze (A) ;
S = A (p,p) ;

tic ;
R = chol (S) ;
t1 = toc ;
x = R \ (R' \ b (p)) ;
x (p) = x ;
e1 = norm (A*x-b) ;

tic ;
L = lchol (S) ;
t2 = toc ;
x = L' \ (L \ b (p)) ;
x (p) = x ;
e2 = norm (A*x-b) ;

fprintf ('\nS = A(p,p) where p is CHOLMOD''s ordering:\n') ;
fprintf ('MATLAB  R=chol(S)  time: %8.4f  resid: %8.0e\n', t1, e1) ;
fprintf ('CHOLMOD L=lchol(S) time: %8.4f  resid: %8.0e\n', t2, e2) ;
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;

% get MATLABS's ordering (symmmd in v7.0.4).  If that fails then use amd.
% A future version of MATLAB will remove symmmd, since it is declared
% "deprecated" in v7.0.4.
try % symmmd, use amd if it fails
    method = 'symmmd' ;
    p = symmmd (A) ;
catch
    % use AMD from SuiteSparse
    method = 'amd' ;
    fprintf ('\nsymmmd not available, using amd instead.\n') ;
    p = amd2 (A) ;
end
S = A (p,p) ;

tic ;
R = chol (S) ;
t1 = toc ;
x = R \ (R' \ b (p)) ;
x (p) = x ;
e1 = norm (A*x-b) ;

tic ;
L = lchol (S) ;
t2 = toc ;
x = L' \ (L \ b (p)) ;
x (p) = x ;
e2 = norm (A*x-b) ;

fprintf ('\nS = A(p,p) where p is MATLAB''s ordering in x=A\\b (%s):\n',method);
fprintf ('MATLAB  R=chol(S)  time: %8.4f  resid: %8.0e\n', t1, e1) ;
fprintf ('CHOLMOD L=lchol(S) time: %8.4f  resid: %8.0e\n', t2, e2) ;
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;

fprintf ('\n\nWith no fill-reducing orderings:\n') ;
tic ;
R = chol (A) ;
t1 = toc ;
x = R \ (R' \ b) ;
e1 = norm (A*x-b) ;

tic ;
L = lchol (A) ;
t2 = toc ;
x = L' \ (L \ b) ;
e2 = norm (A*x-b) ;

fprintf ('MATLAB  R=chol(A)  time: %8.4f  resid: %8.0e\n', t1, e1) ;
fprintf ('CHOLMOD L=lchol(A) time: %8.4f  resid: %8.0e\n', t2, e2) ;
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;

fprintf ('\n\nWith no fill-reducing orderings (as used in "bench"):\n') ;

spparms ('autommd',0) ;
tic ;
x = A\b ;
t1 = toc ;
e1 = norm (A*x-b) ;

tic ;
x = cholmod2 (A,b,0) ; 
t2 = toc ;
e2 = norm (A*x-b) ;

fprintf ('MATLAB  x=A\\b      time: %8.4f  resid: %8.0e\n', t1, e1) ;
fprintf ('CHOLMOD x=A\\b      time: %8.4f  resid: %8.0e\n', t2, e2) ;
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;

spparms ('default') ;