1function test8 (nmat)
2%TEST8 order a large range of sparse matrices, test symbfact2
3% compare AMD and METIS
4% Example:
5%   test8(nmat)
6% See also cholmod_test
7
8% Copyright 2007, Timothy A. Davis, http://www.suitesparse.com
9
10fprintf ('=================================================================\n');
11fprintf ('test8: factorize a large range of sparse matrices\n') ;
12
13% get list of test matrices
14
15index = ssget ;
16
17% GHS posdef test set (more or less)
18f = find (...
19    ((index.numerical_symmetry == 1 & index.isBinary) | (index.posdef)) ...
20    & (index.nnzdiag == index.nrows) ...
21    & (index.nrows > 10000 | index.nrows == 9000) ...
22    & (index.nrows < 600000) & (index.nnz > index.nrows)) ;		    %#ok
23
24% include small matrices
25f = find (...
26    ((index.numerical_symmetry == 1 & index.isBinary) | (index.posdef)) ...
27    & (index.nnzdiag == index.nrows) ...
28    & (index.nrows < 600000) & (index.nnz > index.nrows)) ;
29
30for k = 1:length (f)
31    names {k} = index.Name {f(k)} ;			%#ok
32end
33
34[ignore i] = sort (names) ;
35
36f = f (i) ;
37
38% fprintf ('test matrices sorted by name:\n') ;
39% for i = f
40%     fprintf ('%4d: %-20s %-20s %12d %d\n', i,  ...
41% 	index.Group {i}, index.Name {i}, index.nrows (i), index.posdef (i)) ;
42% end
43
44[ignore i] = sort (index.nrows (f)) ;
45f = f (i) ;
46
47if (nargin > 0)
48    nmat = max (0,nmat) ;
49    nmat = min (nmat, length (f)) ;
50    f = f (1:nmat) ;
51end
52
53fprintf ('test matrices sorted by dimension:\n') ;
54for i = f
55    fprintf ('%4d: %-20s %-20s %12d %d\n', i,  ...
56	index.Group {i}, index.Name {i}, index.nrows (i), index.posdef (i)) ;
57end
58
59junk = sparse (1) ;
60
61% input ('hit enter to continue: ') ;
62
63for k = 1:length (f)
64
65    Problem = ssget (f(k)) ;
66    A = Problem.A ;
67    fprintf ('\n================== Problem: %s  n: %d nnz: %d\n', ...
68	Problem.name, size (A,1), nnz (A)) ;
69    fprintf ('title: %s\n\n', Problem.title) ;
70    clear Problem
71    n = size (A,1) ;							    %#ok
72
73    amd2 (junk) ;
74    metis (junk) ;
75
76    tic ;
77    [p1,info] = amd2 (A) ;						    %#ok
78    t1 = toc ;
79    S1 = A (p1,p1) ;
80    tic ;
81    c1 = symbfact (S1) ;
82    ts1 = toc ;
83    tic ;
84    d1 = symbfact (S1) ;
85    ts2 = toc ;
86    if (any (c1 ~= d1))
87	error ('!')
88    end
89    fprintf ('symbfact time: MATLAB %9.4f  CHOLMOD %9.4f  speedup %8.2f\n', ...
90	ts1, ts2, ts1/ts2) ;
91
92    lnz1 = sum (c1) ;
93    fl1 = sum (c1.^2) ;
94    fprintf ('time: amd     %10.4f mnnz(L) %8.1f mfl %8.0f  fl/nnz(L) %8.1f\n', ...
95	t1, lnz1/1e6, fl1 /1e6, fl1/lnz1) ;
96
97    tic ;
98    p2 = metis (A) ;
99    t2 = toc ;
100    S2 = A (p2,p2) ;
101    c2 = symbfact (S2) ;
102    lnz2 = sum (c2) ;
103    fl2 = sum (c2.^2) ;
104
105    fprintf ('time: metis   %10.4f mnnz(L) %8.1f mfl %8.0f  fl/nnz(L) %8.1f\n', ...
106	t2, lnz2/1e6, fl2/1e6, fl2/lnz2) ;
107
108    r = lnz2 / lnz1 ;							    %#ok
109    fprintf ('\nmetis/amd time: %8.4f nnz(L): %8.4f\n', t2/t1, lnz2/lnz1) ;
110
111    % save results
112    lnz (k,1) = lnz1 ;			    %#ok
113    lnz (k,2) = lnz2 ;			    %#ok
114    fl1 (k,1) = fl1 ;			    %#ok
115    fl2 (k,2) = fl2 ;			    %#ok
116    t (k,1) = t1 ;			    %#ok
117    t (k,2) = t2 ;			    %#ok
118
119end
120
121fprintf ('test8 passed\n') ;
122