1function test95 2%TEST95 performance test for GrB_transpose 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7fprintf ('\ntest95: performance tests : GrB_transpose \n') ; 8 9[save save_chunk] = nthreads_get ; 10chunk = 4096 ; 11nthreads = feature ('numcores') ; 12nthreads_set (nthreads, chunk) ; 13 14rng ('default') ; 15tol = 1e-12 ; 16 17Prob = ssget (2662) 18A = Prob.A ; 19% A = sparse (rand (6000)) ; 20[m n] = size (A) ; 21Cin = sparse (n, m) ; 22A (1,2) =1 ; 23 24ntrials = 10 ; 25 26tic 27for trial = 1:ntrials 28 C1 = A' ; 29end 30tmsum = toc ; 31fprintf ('MATLAB transpose time: %g\n', tmsum / ntrials) ; 32 33% C = 0 ; C += A' 34for trial = 1:ntrials 35 C = GB_mex_transpose (Cin, [ ], 'plus', A) ; 36 tg (trial) = grbresults ; 37end 38tgsum = sum (tg) ; 39fprintf ('GraphBLAS transpose time: %g (for C=0 ; C+=A'')\n', tgsum / ntrials) ; 40assert (isequal (C1, C.matrix)) ; 41fprintf ('speedup over MATLAB: %g\n', tmsum / tgsum) ; 42 43% C = A' 44for trial = 1:ntrials 45 C = GB_mex_transpose (Cin, [ ], [ ], A) ; 46 tg (trial) = grbresults ; 47end 48tgsum = sum (tg) ; 49fprintf ('GraphBLAS transpose time: %g (for C=A'')\n', tgsum / ntrials) ; 50assert (isequal (C1, C.matrix)) ; 51fprintf ('speedup over MATLAB: %g\n', tmsum / tgsum) ; 52 53% sum across the rows 54yin = sparse (rand (m,1)) ; 55fprintf ('row sum (with accum):\n') ; 56tic 57y2 = yin + (sum (A,2)) ; 58t1 = toc ; 59 60y = GB_mex_reduce_to_vector (yin, [ ], 'plus', 'plus', A) ; 61t2 = grbresults ; 62fprintf ('MATLAB: %g GraphBLAS %g speedup %g\n', t1, t2, t1/t2) ; 63err = norm (1*(y.matrix) - y2, 1) ; 64if (norm (y2) ~= 0) 65 err = err / norm (y2) ; 66end 67assert (err < tol) 68% assert (isequal (y.matrix, y2)) 69 70% sum across the rows, no accum 71yin = sparse (rand (m,1)) ; 72fprintf ('row sum (no accum):\n') ; 73tic 74y2 = (sum (A,2)) ; 75t1 = toc ; 76 77y = GB_mex_reduce_to_vector (yin, [ ], [ ], 'plus', A) ; 78t2 = grbresults ; 79fprintf ('MATLAB: %g GraphBLAS %g speedup %g\n', t1, t2, t1/t2) ; 80err = norm (1*(y.matrix) - y2, 1) ; 81if (norm (y2) ~= 0) 82 err = err / norm (y2) ; 83end 84assert (err < tol) 85% assert (isequal (1*(y.matrix), y2)) 86 87% sum down the columns, no accum 88yin = sparse (rand (m,1)) ; 89fprintf ('col sum (no accum):\n') ; 90tic 91y2 = (sum (A,1)) ; 92t1 = toc ; 93 94desc.inp0 = 'tran' ; 95 96y = GB_mex_reduce_to_vector (yin, [ ], [ ], 'plus', A, desc) ; 97t2 = grbresults ; 98fprintf ('MATLAB: %g GraphBLAS %g speedup %g\n', t1, t2, t1/t2) ; 99err = norm (1*(y.matrix) - y2', 1) ; 100if (norm (y2) ~= 0) 101 err = err / norm (y2) ; 102end 103assert (err < tol) 104% assert (isequal (1*(y.matrix), y2')) 105 106nthreads_set (save, save_chunk) ; 107