1function test48 2%TEST48 performance test of GrB_mxm 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7[save save_chunk] = nthreads_get ; 8chunk = 4096 ; 9nthreads = feature ('numcores') ; 10nthreads_set (nthreads, chunk) ; 11 12% d = struct ('inp1', 'tran', 'inp0', 'tran') ; 13rng ('default') ; 14 15dt_auto = struct ('inp0', 'tran') ; 16dt_dot = struct ('inp0', 'tran', 'axb', 'dot') ; 17dt_gus = struct ('inp0', 'tran', 'axb', 'gustavson') ; 18dt_hash = struct ('inp0', 'tran', 'axb', 'hash') ; 19 20da_auto = struct ; 21da_dot = struct ('axb', 'dot') ; 22da_gus = struct ('axb', 'gustavson') ; 23da_hash = struct ('axb', 'hash') ; 24 25dtn_auto = struct ('inp0', 'tran') ; 26dtn_dot = struct ('inp0', 'tran', 'axb', 'dot') ; 27dtn_gus = struct ('inp0', 'tran', 'axb', 'gustavson') ; 28dtn_hash = struct ('inp0', 'tran', 'axb', 'hash') ; 29 30dtt_auto = struct ('inp0', 'tran', 'inp1', 'tran') ; 31dtt_dot = struct ('inp0', 'tran', 'inp1', 'tran', 'axb', 'dot') ; 32dtt_gus = struct ('inp0', 'tran', 'inp1', 'tran', 'axb', 'gustavson') ; 33dtt_hash = struct ('inp0', 'tran', 'inp1', 'tran', 'axb', 'hash') ; 34 35semiring.multiply = 'times' ; 36semiring.add = 'plus' ; 37semiring.class = 'double' ; 38 39xnz_list = [0 100 1000 5000 72000 -1] ; 40 41for pp = 0:2 42 43 if (pp == 1) 44 Prob = ssget (939) 45 A = Prob.A ; 46 elseif (pp == 2) 47 Prob = ssget (2662) 48 A = Prob.A ; 49 else 50 A = sparse (rand (2000)) ; 51 end 52 53 n = size (A,1) ; 54 A (1,2) = 1 ; 55 56 for ncols = [1 2 3 4 8 16] 57 58 fprintf ('\n================ ncols %d\n', ncols) ; 59 w = sparse (n,ncols) ; 60 61 fprintf ('\n------------------------------ C = A''*x\n') ; 62 for xnz = xnz_list % [0 100:200:1000 2000:20000:72000 -1] 63 64 if (xnz == 0) 65 x = sparse (n,ncols) ; 66 x (1:ncols,1:ncols) = speye (ncols) ; 67 elseif (xnz > 0) 68 x = sprand (n, ncols, xnz/n) ; 69 else 70 x = sparse (rand (n, ncols)) ; 71 end 72 73 % tic 74 ca = GB_mex_mxm (w, [],[], semiring, A, x, dt_auto) ; 75 % t = toc ; 76 ta = grbresults ; 77 78 % tic 79 c1 = GB_mex_mxm (w, [],[], semiring, A, x, dt_dot) ; 80 % t = toc ; 81 t = grbresults ; 82 83 % tic 84 cg = GB_mex_mxm (w, [],[], semiring, A, x, dt_gus) ; 85 % t = toc ; 86 tg = grbresults ; 87 88 % tic 89 ch = GB_mex_mxm (w, [],[], semiring, A, x, dt_hash) ; 90 % t = toc ; 91 th = grbresults ; 92 93 tic 94 c0 = A'*x ; 95 t2 = toc ; 96 97 assert (isequal_roundoff (c0, ca.matrix)) ; 98 assert (isequal_roundoff (c0, cg.matrix)) ; 99 assert (isequal_roundoff (c0, c1.matrix)) ; 100 assert (isequal_roundoff (c0, ch.matrix)) ; 101 102 fprintf ('%8d : ', nnz (x)) ; 103 fprintf ('auto: %10.4f dot: %10.4f gus: %10.4f hash: %10.4f MATLAB %10.4f', ... 104 ta, t, tg, th, t2) ; 105 fprintf (' speedup auto: %10.2f dot: %10.2f gus: %10.2f hash: %10.2f\n', ... 106 t2/ta, t2/t, t2/tg, t2/th) ; 107 108 end 109 110 tic 111 c0 = A'*full(x) ; 112 toc 113 114 fprintf ('\n------------------------------ C = A*x\n') ; 115 for xnz = xnz_list % [0 100:200:1000 2000:20000:72000 -1] 116 117 if (xnz == 0) 118 x = sparse (n,ncols) ; 119 x (1:ncols,1:ncols) = speye (ncols) ; 120 elseif (xnz > 0) 121 x = sprand (n, ncols, xnz/n) ; 122 else 123 x = sparse (rand (n, ncols)) ; 124 end 125 126 % tic 127 ca = GB_mex_mxm (w, [],[], semiring, A, x, da_auto) ; 128 % t = toc ; 129 ta = grbresults ; 130 131 % tic 132 c1 = GB_mex_mxm (w, [],[], semiring, A, x, da_dot) ; 133 % t = toc ; 134 t = grbresults ; 135 136 % tic 137 cg = GB_mex_mxm (w, [],[], semiring, A, x, da_gus) ; 138 % t = toc ; 139 tg = grbresults ; 140 141 % tic 142 ch = GB_mex_mxm (w, [],[], semiring, A, x, da_hash) ; 143 % t = toc ; 144 th = grbresults ; 145 146 tic 147 c0 = A*x ; 148 t2 = toc ; 149 150 assert (isequal_roundoff (c0, ca.matrix)) ; 151 assert (isequal_roundoff (c0, cg.matrix)) ; 152 assert (isequal_roundoff (c0, c1.matrix)) ; 153 assert (isequal_roundoff (c0, ch.matrix)) ; 154 155 fprintf ('%8d : ', nnz (x)) ; 156 fprintf ('auto: %10.4f dot: %10.4f gus: %10.4f hash: %10.4f MATLAB %10.4f', ... 157 ta, t, tg, th, t2) ; 158 fprintf (' speedup auto: %10.2f dot: %10.2f gus: %10.2f hash: %10.2f\n', ... 159 t2/ta, t2/t, t2/tg, t2/th) ; 160 161 end 162 163 tic 164 c0 = A*full(x) ; 165 toc 166 167 w = sparse (ncols,n) ; 168 169 fprintf ('\n------------------------------ C = x''*A\n') ; 170 for xnz = xnz_list % [0 100:200:1000 2000:20000:72000 -1] 171 172 if (xnz == 0) 173 x = sparse (n,ncols) ; 174 x (1:ncols,1:ncols) = speye (ncols) ; 175 elseif (xnz > 0) 176 x = sprand (n, ncols, xnz/n) ; 177 else 178 x = sparse (rand (n, ncols)) ; 179 end 180 181 % tic 182 ca = GB_mex_mxm (w, [],[], semiring, x, A, dtn_auto) ; 183 % t = toc ; 184 ta = grbresults ; 185 186 % tic 187 c1 = GB_mex_mxm (w, [],[], semiring, x, A, dtn_dot) ; 188 % t = toc ; 189 t = grbresults ; 190 191 % tic 192 cg = GB_mex_mxm (w, [],[], semiring, x, A, dtn_gus) ; 193 % t = toc ; 194 tg = grbresults ; 195 196 % tic 197 ch = GB_mex_mxm (w, [],[], semiring, x, A, dtn_hash) ; 198 % t = toc ; 199 th = grbresults ; 200 201 tic 202 c0 = x'*A ; 203 t2 = toc ; 204 205 % norm (c0 - ca.matrix, 1) 206 assert (isequal_roundoff (c0, ca.matrix)) ; 207 assert (isequal_roundoff (c0, cg.matrix)) ; 208 assert (isequal_roundoff (c0, c1.matrix)) ; 209 assert (isequal_roundoff (c0, ch.matrix)) ; 210 211 fprintf ('%8d : ', nnz (x)) ; 212 fprintf ('auto: %10.4f dot: %10.4f gus: %10.4f hash: %10.4f MATLAB %10.4f', ... 213 ta, t, tg, th, t2) ; 214 fprintf (' speedup auto: %10.2f dot: %10.2f gus: %10.2f hash: %10.2f\n', ... 215 t2/ta, t2/t, t2/tg, t2/th) ; 216 217 end 218 219 tic 220 c0 = full(x')*A ; 221 toc 222 223 fprintf ('\n------------------------------ C = x''*A''\n') ; 224 for xnz = xnz_list % [0 100:200:1000 2000:20000:72000 -1] 225 226 if (xnz == 0) 227 x = sparse (n,ncols) ; 228 x (1:ncols,1:ncols) = speye (ncols) ; 229 elseif (xnz > 0) 230 x = sprand (n, ncols, xnz/n) ; 231 else 232 x = sparse (rand (n, ncols)) ; 233 end 234 235 % tic 236 ca = GB_mex_mxm (w, [],[], semiring, x, A, dtt_auto) ; 237 % t = toc ; 238 ta = grbresults ; 239 240 % tic 241 c1 = GB_mex_mxm (w, [],[], semiring, x, A, dtt_dot) ; 242 % t = toc ; 243 t = grbresults ; 244 245 % tic 246 cg = GB_mex_mxm (w, [],[], semiring, x, A, dtt_gus) ; 247 % t = toc ; 248 tg = grbresults ; 249 250 % tic 251 ch = GB_mex_mxm (w, [],[], semiring, x, A, dtt_hash) ; 252 % t = toc ; 253 th = grbresults ; 254 255 tic 256 c0 = x'*A' ; 257 t2 = toc ; 258 259 assert (isequal_roundoff (c0, ca.matrix)) ; 260 assert (isequal_roundoff (c0, cg.matrix)) ; 261 assert (isequal_roundoff (c0, c1.matrix)) ; 262 assert (isequal_roundoff (c0, ch.matrix)) ; 263 264 fprintf ('%8d : ', nnz (x)) ; 265 fprintf ('auto: %10.4f dot: %10.4f gus: %10.4f hash: %10.4f MATLAB %10.4f', ... 266 ta, t, tg, th, t2) ; 267 fprintf (' speedup auto: %10.2f dot: %10.2f gus: %10.2f hash: %10.2f\n', ... 268 t2/ta, t2/t, t2/tg, t2/th) ; 269 270 end 271 272 tic 273 c0 = full(x')*A' ; 274 toc 275 276 w = sparse (n,ncols) ; 277 278 fprintf ('\n------------------------------ C = A''*x''\n') ; 279 for xnz = xnz_list % [0 100:200:1000 2000:20000:72000 -1] 280 281 if (xnz == 0) 282 x = sparse (n,ncols) ; 283 x (1:ncols,1:ncols) = speye (ncols) ; 284 elseif (xnz > 0) 285 x = sprand (n, ncols, xnz/n) ; 286 else 287 x = sparse (rand (n, ncols)) ; 288 end 289 x=x' ; 290 291 % tic 292 ca = GB_mex_mxm (w, [],[], semiring, A, x, dtt_auto) ; 293 % t = toc ; 294 ta = grbresults ; 295 296 % tic 297 c1 = GB_mex_mxm (w, [],[], semiring, A, x, dtt_dot) ; 298 % t = toc ; 299 t = grbresults ; 300 301 % tic 302 cg = GB_mex_mxm (w, [],[], semiring, A, x, dtt_gus) ; 303 % t = toc ; 304 tg = grbresults ; 305 306 % tic 307 ch = GB_mex_mxm (w, [],[], semiring, A, x, dtt_hash) ; 308 % t = toc ; 309 th = grbresults ; 310 311 tic 312 c0 = A'*x' ; 313 t2 = toc ; 314 315 assert (isequal_roundoff (c0, ca.matrix)) ; 316 assert (isequal_roundoff (c0, cg.matrix)) ; 317 assert (isequal_roundoff (c0, c1.matrix)) ; 318 assert (isequal_roundoff (c0, ch.matrix)) ; 319 320 fprintf ('%8d : ', nnz (x)) ; 321 fprintf ('auto: %10.4f dot: %10.4f gus: %10.4f hash: %10.4f MATLAB %10.4f', ... 322 ta, t, tg, th, t2) ; 323 fprintf (' speedup auto: %10.2f dot: %10.2f gus: %10.2f hash: %10.2f\n', ... 324 t2/ta, t2/t, t2/tg, t2/th) ; 325 326 end 327 328 tic 329 c0 = A'*full(x') ; 330 toc 331 332 end 333end 334 335nthreads_set (save, save_chunk) ; 336 337fprintf ('\ntest48: all tests passed\n') ; 338 339