File: test91.m

package info (click to toggle)
suitesparse 1%3A5.8.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 152,716 kB
  • sloc: ansic: 774,385; cpp: 24,213; makefile: 6,310; fortran: 1,927; java: 1,826; csh: 1,686; ruby: 725; sh: 535; perl: 225; python: 209; sed: 164; awk: 60
file content (85 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download
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 test91
%TEST91 test subref performance on dense vectors

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved.
% http://suitesparse.com   See GraphBLAS/Doc/License.txt for license.

fprintf ('\n------------------------------ testing GB_mex_Matrix_subref\n') ;

[save save_chunk] = nthreads_get ;
chunk = 4096 ;
nthreads = feature ('numcores') ;
nthreads_set (nthreads, chunk) ;

ntrials = 10 ;

% addpath old
rng ('default')

n = 10 * 1e6 ;
A = sparse (rand (n,1)) ;
fprintf ('A is a sparse %d-by-1 vector, all nonzero\n', n) ;
F = full (A) ;


for ilen = [1 10 100 1000 10000 100000 1e6]

    fprintf ('\n----- C(I) = A (I), I is random with length(I) = %d\n', ilen) ;

    I  = irand (1, n, ilen, 1) ;
    I0 = uint64 (I-1) ;

    tic
    for trials = 1:ntrials
        C1 = A (I) ;
    end
    tm = toc ;
    fprintf ('MATLAB sparse: %g sec\n', tm) ;

    tic
    for trials = 1:ntrials
        Cfull = F (I) ;
    end
    tf = toc ;
    fprintf ('MATLAB full:   %g sec\n', tf) ;

    J0 = uint64 (0) ;

    tic
    for trials = 1:ntrials
        C3 = GB_mex_Matrix_subref (A, I0, J0) ;
    end
    tg = toc ;
    fprintf ('GraphBLAS:     %g sec speedup %g\n', tg, tm/tg) ;
    assert (isequal (C1, C3)) ;

end

fprintf ('\n----- C(:) = A (:)\n') ;

tic
for trials = 1:ntrials
    C1 = A (:) ;
end
tm = toc ;
fprintf ('MATLAB:        %g\n', tm) ;

tic
for trials = 1:ntrials
    C3 = GB_mex_Matrix_subref (A, [ ], J0) ;
end
tg = toc ;
assert (isequal (C1, C3)) ;
fprintf ('GraphBLAS:     %g sec speedup %g\n', tg, tm/tg) ;

F = full (A) ;

tic
for trials = 1:ntrials
    C0 = F (:) ;
    C0 (1) = 1 ;    % make sure the copy gets done, not a lazy copy
end
tf = toc ;
fprintf ('\nMATLAB (full): %g\n', tf) ;

nthreads_set (save, save_chunk) ;