File: test89.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 (85 lines) | stat: -rw-r--r-- 2,110 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
function test89
%TEST89 performance test of complex A*B

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

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

rng ('default') ;
Prob = ssget (936) 
A = Prob.A ;
% A = sprandn (1000, 1000, 0.3) ;
[i j x] = find (A) ;
n = size (A,1) ;
nz = length (x) ;
x = x .* (rand (nz,1) + 1i * rand (nz,1)) ;
y = x .* (rand (nz,1) + 1i * rand (nz,1)) ;
A = sparse (i,j,x,n,n) ;
B = sparse (i,j,y,n,n) ;
clear x y i j

for do_real = 0:1

    if (do_real)
        fprintf ('real:\n') ;
        A = real (A) ;
        B = real (B) ;
    else
        fprintf ('complex:\n') ;
    end

    fprintf ('start built-in\n') ;
    tic
    C1 = A*B ;
    tm = toc ;
    fprintf ('built-in %g\n', tm) ;

        % 1001: Gustavson
        % 1003: dot

    for k = [false true]
        GB_builtin_complex_set (k) ;

        if (k)
            % GraphBLAS is fast
            fprintf ('\nbuilt-in GxB_FC64 complex type:\n') ;
        else
            % GraphBLAS is slower than it could be because the complex type is
            % user-defined.
            fprintf ('\nuser-defined Complex type:\n') ;
        end

        % This uses the default method, which selects Gustavson's method:

        tic
        C2 = GB_mex_AxB (A, B) ;
        tg = toc ;
        err = norm (C1-C2,1) ;
        fprintf ('GraphBLAS %g speedup %g err: %g\n', tg, tm/tg, err) ;

        % these are expected to be slower still; they do not use the default
        % method (Gustavson) which is selected by the auto-strategy.

        tic 
        C2 = GB_mex_AxB (A, B, 0, 0, 1004) ;
        tg = toc ;
        err = norm (C1-C2,1) ;
        fprintf ('GraphBLAS %g speedup %g (hash) err: %g\n', tg, tm/tg, err) ;

        tic
        C2 = GB_mex_AxB (A, B, 0, 0, 1003) ;
        tg = toc ;
        err = norm (C1-C2,1) ;
        fprintf ('GraphBLAS %g speedup %g (dot) err: %g\n', tg, tm/tg, err) ;

    end

end

GB_builtin_complex_set (true) ;
nthreads_set (save, save_chunk) ;