~ubuntu-branches/ubuntu/natty/suitesparse/natty

« back to all changes in this revision

Viewing changes to CHOLMOD/MATLAB/Test/test23.m

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2006-12-22 10:16:15 UTC
  • Revision ID: james.westby@ubuntu.com-20061222101615-2ohaj8902oix2rnk
Tags: upstream-2.3.1
ImportĀ upstreamĀ versionĀ 2.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function test23
 
2
% test23: test chol and cholmod on the sparse matrix used in "bench"
 
3
fprintf ('=================================================================\n');
 
4
fprintf ('test23: test chol & cholmod on the sparse matrix used in "bench"\n');
 
5
 
 
6
n = 120 ;
 
7
A = delsq (numgrid ('L', n)) ;
 
8
b = sum (A)' ;
 
9
 
 
10
fprintf ('Using each method''s internal fill-reducing ordering:\n') ;
 
11
 
 
12
tic ;
 
13
x = A\b ;
 
14
t1 = toc ;
 
15
e1 = norm (A*x-b) ;
 
16
 
 
17
tic ;
 
18
x = cholmod (A,b) ; 
 
19
t2 = toc ;
 
20
e2 = norm (A*x-b) ;
 
21
 
 
22
fprintf ('MATLAB  x=A\\b      time: %8.4f  resid: %8.0e\n', t1, e1) ;
 
23
fprintf ('CHOLMOD x=A\\b      time: %8.4f  resid: %8.0e\n', t2, e2) ;
 
24
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;
 
25
 
 
26
% get CHOLMOD's ordering (best of AMD and METIS)
 
27
p = analyze (A) ;
 
28
S = A (p,p) ;
 
29
 
 
30
tic ;
 
31
R = chol (S) ;
 
32
t1 = toc ;
 
33
x = R \ (R' \ b (p)) ;
 
34
x (p) = x ;
 
35
e1 = norm (A*x-b) ;
 
36
 
 
37
tic ;
 
38
L = lchol (S) ;
 
39
t2 = toc ;
 
40
x = L' \ (L \ b (p)) ;
 
41
x (p) = x ;
 
42
e2 = norm (A*x-b) ;
 
43
 
 
44
fprintf ('\nS = A(p,p) where p is CHOLMOD''s ordering:\n') ;
 
45
fprintf ('MATLAB  R=chol(S)  time: %8.4f  resid: %8.0e\n', t1, e1) ;
 
46
fprintf ('CHOLMOD L=lchol(S) time: %8.4f  resid: %8.0e\n', t2, e2) ;
 
47
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;
 
48
 
 
49
% get MATLABS's ordering (symmmd in v7.0.4).  If that fails then use amd.
 
50
% A future version of MATLAB will remove symmmd, since it is declared
 
51
% "deprecated" in v7.0.4.
 
52
try % symmmd, use amd if it fails
 
53
    method = 'symmmd' ;
 
54
    p = symmmd (A) ;
 
55
catch
 
56
    method = 'amd' ;
 
57
    fprintf ('\nsymmmd not available, using amd instead.\n') ;
 
58
    p = amd (A) ;
 
59
end
 
60
S = A (p,p) ;
 
61
 
 
62
tic ;
 
63
R = chol (S) ;
 
64
t1 = toc ;
 
65
x = R \ (R' \ b (p)) ;
 
66
x (p) = x ;
 
67
e1 = norm (A*x-b) ;
 
68
 
 
69
tic ;
 
70
L = lchol (S) ;
 
71
t2 = toc ;
 
72
x = L' \ (L \ b (p)) ;
 
73
x (p) = x ;
 
74
e2 = norm (A*x-b) ;
 
75
 
 
76
fprintf ('\nS = A(p,p) where p is MATLAB''s ordering in x=A\\b (%s):\n',method);
 
77
fprintf ('MATLAB  R=chol(S)  time: %8.4f  resid: %8.0e\n', t1, e1) ;
 
78
fprintf ('CHOLMOD L=lchol(S) time: %8.4f  resid: %8.0e\n', t2, e2) ;
 
79
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;
 
80
 
 
81
fprintf ('\n\nWith no fill-reducing orderings:\n') ;
 
82
tic ;
 
83
R = chol (A) ;
 
84
t1 = toc ;
 
85
x = R \ (R' \ b) ;
 
86
e1 = norm (A*x-b) ;
 
87
 
 
88
tic ;
 
89
L = lchol (A) ;
 
90
t2 = toc ;
 
91
x = L' \ (L \ b) ;
 
92
e2 = norm (A*x-b) ;
 
93
 
 
94
fprintf ('MATLAB  R=chol(A)  time: %8.4f  resid: %8.0e\n', t1, e1) ;
 
95
fprintf ('CHOLMOD L=lchol(A) time: %8.4f  resid: %8.0e\n', t2, e2) ;
 
96
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;
 
97
 
 
98
fprintf ('\n\nWith no fill-reducing orderings (as used in "bench"):\n') ;
 
99
 
 
100
spparms ('autommd',0) ;
 
101
tic ;
 
102
x = A\b ;
 
103
t1 = toc ;
 
104
e1 = norm (A*x-b) ;
 
105
 
 
106
tic ;
 
107
x = cholmod (A,b,0) ; 
 
108
t2 = toc ;
 
109
e2 = norm (A*x-b) ;
 
110
 
 
111
fprintf ('MATLAB  x=A\\b      time: %8.4f  resid: %8.0e\n', t1, e1) ;
 
112
fprintf ('CHOLMOD x=A\\b      time: %8.4f  resid: %8.0e\n', t2, e2) ;
 
113
fprintf ('CHOLMOD speedup: %8.2f\n', t1/t2) ;
 
114
 
 
115
spparms ('default') ;