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
|
function test11 (nmat)
%TEST11 compare CHOLMOD and MATLAB, save results in Results.mat
% also tests analyze
% Example:
% test11(nmat)
% See also cholmod_test
% Copyright 2007, Timothy A. Davis, http://www.suitesparse.com
fprintf ('=================================================================\n');
fprintf ('test11 : compare CHOLMOD and MATLAB, save results in Results.mat\n');
rand ('state',0) ;
randn ('state',0) ;
index = ssget ;
f = find (index.posdef) ;
[ignore i] = sort (index.nrows (f)) ;
f = f (i) ;
clear ignore
% start after nd6k
% f = f ((find (f == 937) + 1):end) ;
skip = [937:939 1202:1211] ;
if (nargin > 0)
nmat = max (0,nmat) ;
nmat = min (nmat, length (f)) ;
f = f (1:nmat) ;
end
fprintf ('test matrices sorted by dimension:\n') ;
for i = f
if (any (i == skip))
continue
end
fprintf ('%4d: %-20s %-20s %12d %d\n', i, ...
index.Group {i}, index.Name {i}, index.nrows (i), index.posdef (i)) ;
end
kk = 0 ;
nmat = length (f) ;
T1 = zeros (1,nmat) ; % matlab time
T2 = zeros (1,nmat) ; % cholmod2 time
E1 = zeros (1,nmat) ; % matlab residual
E2 = zeros (1,nmat) ; % cholmod2 residual
FL = zeros (1,nmat) ; % cholmod2 flop count
LNZ = zeros (1,nmat) ; % cholmod2 lnz
for kkk = 1:length(f)
nn = f (kkk) ;
if (any (nn == skip))
continue
end
% try
fprintf ('\n%3d: %s/%s\n', nn, index.Group {nn}, index.Name {nn}) ;
Prob = ssget (nn) ;
A = Prob.A ;
clear Prob
n = size (A,1) ;
b = rand (n,1) ;
% analyze
[p count] = analyze (A) ;
% LDL' flop count
% fl = sum ((count-1).*(count-1) + 2*(count-1)) ;
% LL' flop count
fl = sum (count.^2) ;
lnz = sum (count) ;
fprintf ('n %d lnz %g fl %g\n', n, lnz, fl) ;
clear p count
% try
k2 = 0 ;
t2 = 0 ;
while (t2 < 1)
tic
x = cholmod2 (A,b) ;
t = toc ;
t2 = t2 + t ;
k2 = k2 + 1 ;
end
t2 = t2 / k2 ;
e2 = norm (A*x-b,1) ;
% catch
% e2 = Inf ;
% k2 = Inf ;
% t2 = Inf ;
% end
fprintf ('cholmod2: t: %10.5f e: %6.1e mflop %6.0f\n', ...
t2, e2, 1e-6 * fl / t2) ;
% try
k1 = 0 ;
t1 = 0 ;
while (t1 < 1)
tic
x = A\b ;
t = toc ;
t1 = t1 + t ;
k1 = k1 + 1 ;
end
t1 = t1 / k1 ;
e1 = norm (A*x-b,1) ;
% catch
% e1 = Inf ;
% k1 = Inf ;
% t1 = Inf ;
% end
fprintf ('matlab: t: %10.5f e: %6.1e mflop %6.0f', ...
t1, e1, 1e-6 * fl / t1) ;
fprintf (' cholmod2 speedup: %5.1f\n', t1/t2) ;
kk = kk + 1 ;
T1 (kk) = t1 ;
T2 (kk) = t2 ;
E1 (kk) = e1 ;
E2 (kk) = e2 ;
FL (kk) = fl ;
LNZ (kk) = lnz ;
%%% save Results T1 T2 E1 E2 FL LNZ f kkk
% catch
% fprintf (' failed\n') ;
% end
clear A x b
end
% test11results
fprintf ('test11 passed\n') ;
|