1function test89
2%TEST89 performance test of complex A*B
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7[save save_chunk] = nthreads_get ;
8chunk = 4096 ;
9nthreads = feature ('numcores') ;
10nthreads_set (nthreads, chunk) ;
11
12rng ('default') ;
13Prob = ssget (936)
14A = Prob.A ;
15% A = sprandn (1000, 1000, 0.3) ;
16[i j x] = find (A) ;
17n = size (A,1) ;
18nz = length (x) ;
19x = x .* (rand (nz,1) + 1i * rand (nz,1)) ;
20y = x .* (rand (nz,1) + 1i * rand (nz,1)) ;
21A = sparse (i,j,x,n,n) ;
22B = sparse (i,j,y,n,n) ;
23clear x y i j
24
25for do_real = 0:1
26
27    if (do_real)
28        fprintf ('real:\n') ;
29        A = real (A) ;
30        B = real (B) ;
31    else
32        fprintf ('complex:\n') ;
33    end
34
35    fprintf ('start MATLAB\n') ;
36    tic
37    C1 = A*B ;
38    tm = toc ;
39    fprintf ('MATLAB %g\n', tm) ;
40
41        % 1001: Gustavson
42        % 1003: dot
43
44    for k = [false true]
45        GB_builtin_complex_set (k) ;
46
47        if (k)
48            % GraphBLAS is fast
49            fprintf ('\nbuilt-in GxB_FC64 complex type:\n') ;
50        else
51            % GraphBLAS is slower than it could be because the complex type is
52            % user-defined.
53            fprintf ('\nuser-defined Complex type:\n') ;
54        end
55
56        % This uses the default method, which selects Gustavson's method:
57
58        C2 = GB_mex_AxB (A, B) ;
59        tg = grbresults ;
60        err = norm (C1-C2,1) ;
61        fprintf ('GraphBLAS %g speedup %g err: %g\n', tg, tm/tg, err) ;
62
63        % these are expected to be slower still; they do not use the default method
64        % (Gustavson) which is selected by the auto-strategy.
65
66        C2 = GB_mex_AxB (A, B, 0, 0, 1004) ;
67        tg = grbresults ;
68        err = norm (C1-C2,1) ;
69        fprintf ('GraphBLAS %g speedup %g (hash) err: %g\n', tg, tm/tg, err) ;
70
71        C2 = GB_mex_AxB (A, B, 0, 0, 1003) ;
72        tg = grbresults ;
73        err = norm (C1-C2,1) ;
74        fprintf ('GraphBLAS %g speedup %g (dot) err: %g\n', tg, tm/tg, err) ;
75
76    end
77
78end
79nthreads_set (save, save_chunk) ;
80