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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
function test39(use_ssget)
%TEST39 performance test for GrB_transpose
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved.
% http://suitesparse.com See GraphBLAS/Doc/License.txt for license.
fprintf ('\ntest39 performance tests : GrB_transpose \n') ;
if (nargin < 1)
use_ssget = true ;
end
[save save_chunk] = nthreads_get ;
chunk = 4096 ;
nthreads = feature ('numcores') ;
nthreads_set (nthreads, chunk) ;
rng ('default') ;
if (use_ssget)
try
Prob = ssget (939)
A = Prob.A ;
catch
use_ssget = false ;
end
end
if (~use_ssget)
fprintf ('not using ssget\n') ;
n = 72000 ;
nz = 29e6 ;
A = sprandn (n, n, nz/n^2) ;
end
[m n] = size (A) ;
Cin = sprandn (n, m, 0.000001) ;
A (1,2) =1 ;
Empty = sparse (n, m) ;
fprintf ('\n===============================================================n') ;
fprintf ('\nC = A''\n') ;
tic
C1 = A' ;
toc
tm = toc ;
fprintf ('GraphBLAS, transpose :\n') ;
tic
C = GB_mex_transpose (Empty, [ ], [ ], A) ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg) ;
assert (isequal (C1, C.matrix)) ;
fprintf ('speedup over MATLAB: %g\n\n', tm/tg) ;
fprintf ('\n===============================================================n') ;
fprintf ('\nGraphBLAS: C = (single) A'' compared with C=A'' in MATLAB\n') ;
clear Empty_struct
Empty_struct.matrix = sparse (n, m) ;
Empty_struct.class = 'single' ;
tic
C1 = A' ;
toc
tm = toc ;
fprintf ('GraphBLAS, transpose:\n') ;
% C = A'
tic
C2 = GB_mex_transpose (Empty_struct, [ ], '', A) ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg) ;
fprintf ('speedup over MATLAB: %g\n\n', tm/tg) ;
[I1, J1, X1] = find (C1) ;
[I2, J2, X2] = find (C2.matrix) ;
clear C2
assert (isequal (I1, I2)) ;
assert (isequal (J1, J2)) ;
assert (isequal (single(X1), X2)) ;
fprintf ('\n===============================================================n') ;
fprintf ('\nC = Cin + A''\n') ;
tic
C1 = Cin + A' ;
toc
tm = toc ;
fprintf ('GraphBLAS, transpose and then accum with GB_add:\n') ;
% C = Cin + A'
tic
C = GB_mex_transpose (Cin, [ ], 'plus', A) ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg) ;
assert (isequal (C1, C.matrix)) ;
fprintf ('speedup over MATLAB: %g\n\n', tm/tg) ;
fprintf ('\n===============================================================n') ;
fprintf ('\nC = A + B\n') ;
B = sprandn (m, n, 0.00001) ;
fprintf ('nnz (A) = %d nnz (B) = %d\n', nnz (A), nnz (B)) ;
tic
C1 = A + B ;
toc
tm = toc ;
D = struct ('inp0', 'tran') ;
fprintf ('\nusing accum and subassign, then GB_Matrix_wait:\n') ;
tic
C2 = GB_mex_transpose (A, [ ], 'plus', B, D) ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg) ;
fprintf ('speedup over MATLAB: %g\n\n', tm/tg) ;
assert (isequal (C1, C2.matrix)) ;
fprintf ('\nusing accum and GB_add:\n') ;
tic
C2 = GB_mex_transpose (B, [ ], 'plus', A, D) ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg) ;
fprintf ('speedup over MATLAB: %g\n\n', tm/tg) ;
assert (isequal (C1, C2.matrix)) ;
fprintf ('\nvia GB_add and then accum:\n') ;
clear Cin
Cin = sparse (m,n) ;
tic
C3 = GB_mex_Matrix_eWiseAdd (Cin, [ ], '', 'plus', A, B) ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg) ;
fprintf ('speedup over MATLAB: %g\n\n', tm/tg) ;
assert (isequal (C1, C3.matrix)) ;
fprintf ('\nvia GB_add:\n') ;
tic
C4 = GB_mex_AplusB (A, B, 'plus') ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg) ;
fprintf ('speedup over MATLAB: %g\n\n', tm/tg) ;
assert (isequal (C1, C4)) ;
fprintf ('\nvia GB_add:\n') ;
tic
C4 = GB_mex_AplusB (B, A, 'plus') ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg) ;
fprintf ('speedup over MATLAB: %g\n\n', tm/tg) ;
assert (isequal (C1, C4)) ;
fprintf ('\n===============================================================n') ;
fprintf ('\nC = Cin + A + B\n') ;
Cin = sprandn (m, n, 0.0001) ;
tic
C1 = Cin + A + B ;
toc
tm1 = toc ;
tic
C1 = (Cin + A) + B ;
toc
tm2 = toc ;
tic
C1 = Cin + (A + B) ;
toc
tm3 = toc ;
tic
C1 = (Cin + B) + A ;
toc
tm5 = toc ;
tic
C3 = GB_mex_Matrix_eWiseAdd (Cin, [ ], 'plus', 'plus', A, B) ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg) ;
fprintf ('speedup over MATLAB: %g\n\n', tm1/tg) ;
assert (isequal (C1, C3.matrix)) ;
fprintf ('\nvia two GB_add: (Cin+A)+B:\n') ;
tic
C4 = GB_mex_AplusB (Cin, A, 'plus') ;
tg1 = grbresults ;
C4 = GB_mex_AplusB (C4, B, 'plus') ;
toc
tg2 = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg1+tg2) ;
fprintf ('speedup over MATLAB: %g\n\n', tm2/(tg1+tg2)) ;
assert (isequal (C1, C4)) ;;
fprintf ('\nvia two GB_add: (Cin+(A+B)):\n') ;
tic
C4 = GB_mex_AplusB (A, B, 'plus') ;
tg1 = grbresults ;
C4 = GB_mex_AplusB (C4, Cin, 'plus') ;
tg2 = grbresults ;
toc
tg = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg1+tg2) ;
fprintf ('speedup over MATLAB: %g\n\n', tm3/(tg1+tg2)) ;
assert (isequal (C1, C4))
fprintf ('\nvia two GB_add: (Cin+B)+A)):\n') ;
tstart = tic ;
C4 = GB_mex_AplusB (Cin, B, 'plus') ;
tg1 = grbresults ;
C4 = GB_mex_AplusB (C4, A, 'plus') ;
toc (tstart)
tg2 = grbresults ;
fprintf ('GraphBLAS time: %g\n', tg1+tg2) ;
fprintf ('speedup over MATLAB: %g\n\n', tm5/(tg1+tg2)) ;
assert (isequal (C1, C4)) ;;
nthreads_set (save, save_chunk) ;
fprintf ('\ntest39: all tests passed\n') ;
|