File: sstest2.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (165 lines) | stat: -rw-r--r-- 3,935 bytes parent folder | download | duplicates (2)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
function sstest2
%SSTEST2 exhaustive performance test for SSMULT.  Requires ssget.
% ssget is available at http://www.suitesparse.com 
%
% Example
%   sstest2
%
% See also ssmult, ssmultsym, ssmult_install, sstest, ssget, mtimes.

% SSMULT, Copyright (c) 2007-2011, Timothy A Davis. All Rights Reserved.
% SPDX-License-Identifier: GPL-2.0+

help sstest2

try
    index = ssget ;
catch
    fprintf ('\nsstest2 requires ssget.\n') ;
    fprintf ('see http://www.suitesparse.com\n') ;
    return ;
end
[ignore, f] = sort (index.nnz) ;                                            %#ok

nmat = length (f) ;
TM = zeros (nmat, 4) ;
T1 = zeros (nmat, 4) ;
tlim = 0.01 ;

tmin = 1 ;
tmax = 0 ;

check = 1 ;
rand ('state', 0)

for k = 1:nmat

    Prob = ssget (f (k), index) ;
    A = Prob.A ;
    clear Prob

    for kind = 1:4

        try
            if (~isreal (A))
                A = spones (A) ;
            end
            B = A' ;

            if (kind == 2)
                A = sprand (A) + 1i*sprand(A) ;
                B = sprand (B) ;
            elseif (kind == 3)
                A = sprand (A) ;
                B = sprand (B) + 1i*sprand(B) ;
            elseif (kind == 4)
                A = sprand (A) + 1i*sprand(A) ;
                B = sprand (B) + 1i*sprand(B) ;
            end

            C = A*B     ; % warmup

            if (check)

                D = ssmult (A,B) ;
                err = norm (C-D,1) ;
                if (err > 0)
                    fprintf ('err: %g\n', err) ;
                    error ('!')
                end
                clear D

            else

                % warmup, for accurate timings
                C = ssmult (A,B) ;                                          %#ok
                clear C

            end

            tr = 0 ;
            tm = 0 ;
            tic
            while (tm < tlim)
                C = A*B ;                                                   %#ok
                clear C
                tr = tr + 1 ;
                tm = toc ;
            end
            tm = tm / tr ;

            tr = 0 ;
            t1 = 0 ;
            tic
            while (t1 < tlim)
                C = ssmult (A,B) ;                                          %#ok
                clear C
                tr = tr + 1 ;
                t1 = toc ;
            end
            t1 = t1 / tr ;

            fprintf ('%4d: %4d ', k, f(k)) ;
            fprintf (...
            'MATLAB %12.6f SSMULT %12.6f  speedup %12.3f', ....
                tm, t1, tm / t1) ;
            
            if (tm < t1)
                fprintf (' ****') ;
            end
            fprintf ('\n') ;

            TM (k,kind) = tm ;
            T1 (k,kind) = t1 ;

            tmin = min (tmin, tm) ;
            tmax = max (tmax, tm) ;

        catch me
            disp (me.message)
            TM (k,kind) = 1 ;
            T1 (k,kind) = 1 ;
        end

    end

    for kind = 1:4

        subplot (2,4,kind) ;
        r = TM (1:k,kind) ./ T1 (1:k,kind) ;
        rmin = min (r) ;
        rmax = max (r) ;
        loglog (TM (1:k,kind), r, 'o', ...
            [tmin tmax], [1 1], 'r-', ...
            [tmin tmax], [1.1 1.1], 'r-', ...
            [tmin tmax], [1/1.1 1/1.1], 'r-', ...
            [tmin tmax], [2 2], 'g-', ...
            [tmin tmax], [1.5 1.5], 'g-', ...
            [tmin tmax], [1/1.5 1/1.5], 'g-', ...
            [tmin tmax], [.5 .5], 'g-' );
        if (k > 2)
            axis ([tmin tmax rmin rmax]) ;
        end
        xlabel ('MATLAB time') ; 
        ylabel ('MATLAB/SM time') ; 
        if (kind == 1)
            title ('real*real') ;
        elseif (kind == 2)
            title ('complex*real') ;
        elseif (kind == 3)
            title ('real*complex') ;
        elseif (kind == 4)
            title ('complex*complex') ;
        end

    end

    drawnow

    clear A B C
    save sstest2_results.mat TM T1 f
    diary off
    diary on

end