File: test68.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 (97 lines) | stat: -rw-r--r-- 2,203 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
function test68(n)
%TEST68 performance tests for eWiseMult

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

fprintf ('\ntest68 --------------------------- quick test of GrB_eWiseMult\n') ;

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

rng ('default') ;

if (nargin < 1)
    n = 3000 ;
end

A = sparse (rand (n)) ;
B = sparse (rand (n)) ;
C = sparse (n,n) ;

for trial = 1:2
    % C = A.*B, no mask
    Afull = full (A) ;
    Bfull = full (B) ;

    tic
    C0 = Afull .* Bfull ;
    tf = toc ;
    fprintf ('built-in, full: %0.4f\n', tf) ;

    tic
    C0 = A .* B ;
    t0 = toc ;

    tic
    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
    t1 = toc ;
    fprintf ('built-in %0.4f  GB %0.4f speedup %g\n', t0, t1, t0/t1) ;
    assert (isequal (C0, C1.matrix)) ;
end

A = sprand (n, n, 0.001) ;

    % C = A.*B, no mask
    tic
    C0 = A .* B ;
    t0 = toc ;
    tic
    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
    t1 = toc ;
    fprintf ('built-in %0.4f  GB %0.4f speedup %g\n', t0, t1, t0/t1) ;
    assert (isequal (C0, C1.matrix)) ;

A = sparse (n, n) ;
A (n,:) = 1 ;

    % C = A.*B, no mask
    tic
    C0 = A .* B ;
    t0 = toc ;
    tic
    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
    t1 = toc ;
    fprintf ('built-in %0.4f  GB %0.4f speedup %g\n', t0, t1, t0/t1) ;
    assert (isequal (C0, C1.matrix)) ;

A = sparse (n, n) ;
A (1,:) = 1 ;

    % C = A.*B, no mask
    tic
    C0 = A .* B ;
    t0 = toc ;
    tic
    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
    t1 = toc ;
    fprintf ('built-in %0.4f  GB %0.4f speedup %g\n', t0, t1, t0/t1) ;
    assert (isequal (C0, C1.matrix)) ;

for d =  [0.000:0.002:0.1]
    A = sprand (n, n, d) ;

    % C = A.*B, no mask
    tic
    C0 = A .* B ;
    t0 = toc ;
    tic
    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
    t1 = toc ;
    fprintf ('d %8.3f built-in %0.4f  GB %0.4f speedup %g\n', d, t0, t1, t0/t1) ;
    assert (isequal (C0, C1.matrix)) ;
end

nthreads_set (save, save_chunk) ;