File: test46.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 (140 lines) | stat: -rw-r--r-- 2,997 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
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
function test46
%TEST46 performance test of GxB_subassign

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

fprintf ('\n--------------performance test GB_mex_subassign\n') ;

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

dt = struct ('inp0', 'tran') ;

rng ('default') ;

A = sparse (rand (3,4)) ;
I = uint64 (0:2) ;
J = uint64 (0:3) ;
C = A ;

C0 = sprandn (length(I), length (J), 0.5) ;
C1 = C ;
C1 (I+1,J+1) = C0 ;
CC = GB_mex_subassign (C, [],[], C0, I, J, []) ;
assert (isequal (C1, CC.matrix))

C0 = sprandn (length(I), length (J), 0.5)' ;
C1 = C ;
C1 (I+1,J+1) = C0' ;
CC = GB_mex_subassign (C, [],[], C0, I, J, dt) ;
assert (isequal (C1, CC.matrix))

for trial = 1:100

    for m = [1 10 100]
        for n = [1 10 100]

            C = sprandn (m, n, 0.1) ;

            ni = double (irand (1, m)) ;
            nj = double (irand (1, n)) ;
            I = randperm (m) ;
            J = randperm (n) ;
            I = I (1:ni) ;
            J = J (1:nj) ;
            I0 = uint64 (I-1) ;
            J0 = uint64 (J-1) ;

            A = sprandn (ni, nj, 0.1) ;

            C1 = C ;
            C1 (I,J) = A ;
            C2 = GB_mex_subassign (C, [], '', A, I0, J0, []) ;

            C3 = C ;
            C3 (I,J) = C3 (I,J) + A ;
            C4 = GB_mex_subassign (C, [], 'plus', A, I0, J0, []) ;

            assert (isequal (C3, C4.matrix))
        end
    end
end


Prob = ssget (2662) ;
A = Prob.A ;
% n = 2^21 ; A = A (1:n,1:n) ;
% A = A (:) ;
A = [A A ; A A] ;
A = [A A ; A A] ;
% A = [A A ; A A] ;
%A = [A A ; A A] ;
%A = [A A ; A A] ;
C = A ; 
C (1,1) = 1 ;
[m n] = size (A) ;
fprintf ('size: %d %d\n', m, n) ;

ni = min (size (A, 1), 5500) ;
nj = min (size (A, 2), 7000) ;
B = sprandn (ni, nj, 0.001) ;
% I = randperm (m) ; I = I (1:ni) ;
% J = randperm (n) ; J = J (1:nj) ;
I = randperm (m,ni) ;
J = randperm (n,nj) ;
fprintf ('nnzB: %g\n', nnz (B)) ;

fprintf ('\nC(I,J)=B, MATLAB start:\n')
tic
C (I,J) = B ;
toc

I0 = uint64 (I-1) ;
J0 = uint64 (J-1) ;

C2 = A;
C2 (1,1) =1 ;

fprintf ('GraphBLAS start:\n')

for nthreads = [1 20 40]
    nthreads_set (nthreads) ;
    C3 = GB_mex_subassign (C2, [], [], B, I0, J0, []) ;
    tg = grbresults ;
    fprintf ('%d threads, GB time: %g\n', nthreads, tg) ;
    assert (isequal (C, C3.matrix)) ;
end

% A = Prob.A ;
% A = A (:) ;
% A = [A A] ;
% n = 2^21 ; A = A (1:n,1:n) ;
C = A ;
C (1,1) = 1 ;

fprintf ('\nC(I,J)+=B, MATLAB start:\n')
tic
C (I,J) = C (I,J) + B ;
toc

C2 = A ;
C2 (1,1) = 1 ;

fprintf ('GraphBLAS start:\n')

for nthreads = [1 20 40]
    nthreads_set (nthreads) ;
    C3 = GB_mex_subassign (C2, [], 'plus', B, I0, J0, []) ;
    tg = grbresults ;
    fprintf ('%d threads, GB time: %g\n', nthreads, tg) ;
    assert (isequal (C, C3.matrix)) ;
end

nthreads_set (save, save_chunk) ;

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