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