File: test58.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (155 lines) | stat: -rw-r--r-- 3,669 bytes parent folder | download | duplicates (3)
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
function test58 (cover)
%TEST58 test GrB_eWiseAdd

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

if (nargin < 1)
    cover = 1 ;
end

fprintf ('\ntest58: ----- quick performance for GB_mex_Matrix_eWiseAdd\n') ;

[save save_chunk] = nthreads_get ;
chunk = 4096 ;
nthreads = feature_numcores ;
nthreads_set (nthreads, chunk) ;


add = 'plus' ;
Mask = [ ] ;
accum = 'plus' ;

if (~cover)
    Prob = ssget (939) ;
    A = Prob.A ;
    B = 2*A ;
    Cin = A .* (A < 0) ;

    tic
    C = Cin + (A+B) ;
    t1 =toc ;

    tic
    C2 = GB_mex_Matrix_eWiseAdd (Cin, Mask, accum, add, A, B, [ ]) ;
    t2 = toc ;
    assert (isequal (C2.matrix,  C))

    fprintf ('built-in: %g GB: %g  speedup: %g\n', t1, t2, t1/t2) ;
end

if (cover)
    nn = [10 100 ] ;
else
    nn = [10 100 1000 10000 50000] ;
end

for m = nn
    for n = nn
        A = sprandn (m, n, 0.01) ;
        B = sprandn (m, n, 0.01) ;
        Cin = sprandn (m, n, 0.01) ;
        AT = A' ;
        BT = B' ;

        if (min (m,n) >= 10000)
            trials = 1 ;
        else
            trials = 20 ;
        end

        Dnn = struct ;
        Dtn = struct ('inp0', 'tran') ;
        Dnt = struct ('inp1', 'tran') ;
        Dtt = struct ('inp0', 'tran', 'inp1', 'tran') ;

        % C += A+B
        tic
        for k = 1:trials
            C1 = Cin + (A+B) ;
        end
        t1 = toc / trials ;

        tic
        for k = 1:trials
            C2 = GB_mex_Matrix_eWiseAdd (Cin, [ ], accum, add, A, B, [ ]) ;
        end
        tg = toc ;
        t2 = tg /trials ;
        assert (isequal (C1, C2.matrix)) ;

        fprintf ('A+B:   ') ;
        fprintf ('m %6d n %6d nz %8d: built-in %8.4f GrB %8.4f', ...
            m, n, nnz (C1), t1, t2) ;
        % fprintf (' Cs: %8.4f', t3) ;
        fprintf (' speedup %g\n', t1/t2) ;

        % C += A+B'
        tic
        for k = 1:trials
            C1 = Cin + (A+BT') ;
        end
        t1 = toc / trials ;

        tic ;
        for k = 1:trials
            C2 = GB_mex_Matrix_eWiseAdd (Cin, [ ], accum, add, A, BT, Dnt) ;
        end
        tg = toc ;
        t2 = tg /trials ;
        assert (isequal (C1, C2.matrix)) ;

        fprintf ('A+B'':  ') ;
        fprintf ('m %6d n %6d nz %8d: built-in %8.4f GrB %8.4f', ...
            m, n, nnz (C1), t1, t2) ;
        % fprintf (' Cs: %8.4f', t3) ;
        fprintf (' speedup %g\n', t1/t2) ;

        % C += A'+B
        tic
        for k = 1:trials
            C1 = Cin + (AT'+B) ;
        end
        t1 = toc / trials  ;

        tic
        for k = 1:trials
            C2 = GB_mex_Matrix_eWiseAdd (Cin, [ ], accum, add, AT, B, Dtn) ;
        end
        tg = toc ;
        t2 = tg /trials ;
        assert (isequal (C1, C2.matrix)) ;

        fprintf ('A''+B:  ') ;
        fprintf ('m %6d n %6d nz %8d: built-in %8.4f GrB %8.4f', ...
            m, n, nnz (C1), t1, t2) ;
        % fprintf (' Cs: %8.4f', t3) ;
        fprintf (' speedup %g\n', t1/t2) ;

        % C += A'+B'
        tic
        for k = 1:trials
            C1 = Cin + (AT'+BT') ;
        end
        t1 = toc / trials ;

        tic ;
        for k = 1:trials
            C2 = GB_mex_Matrix_eWiseAdd (Cin, [ ], accum, add, AT, BT, Dtt) ;
        end
        tg = toc ;
        t2 = tg /trials ;
        assert (isequal (C1, C2.matrix)) ;

        fprintf ('A''+B'': ') ;
        fprintf ('m %6d n %6d nz %8d: built-in %8.4f GrB %8.4f', ...
            m, n, nnz (C1), t1, t2) ;
        % fprintf (' Cs: %8.4f', t3) ;
        fprintf (' speedup %g\n', t1/t2) ;

    end
end

fprintf ('\ntest58: all tests passed\n') ;

nthreads_set (save, save_chunk) ;