1function test116
2%TEST116 performance tests for GrB_assign
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('test116:---------------- C(I,J)=A and C=A(I,J) performance\n') ;
8
9[save save_chunk] = nthreads_get ;
10chunk = 4096 ;
11
12million = 1e6 ;
13
14rng ('default') ;
15n = million ;
16nz = 100 * million ;
17d = nz / n^2 ;
18C0 = sprand (n, n, d) ;
19
20k = n/10 ;
21nz = 10 * million ;
22d = nz / k^2 ;
23A = sprand (k, k, d) ;
24
25I.begin = 0 ;
26I.inc = 1 ;
27I.end = k-1 ;
28
29ncores = feature ('numcores') ;
30
31% warmup
32C1 = C0 ;
33C1 (1:k,1:k) = A ;
34
35fprintf ('\n--------------------------------------\n') ;
36fprintf ('C(I,J) = A:\n') ;
37tic
38C1 = C0 ;
39C1 (1:k,1:k) = A ;
40tm = toc ;
41
42for nthreads = [1 2 4 8 16 20 32 40 64]
43    if (nthreads > 2*ncores)
44        break ;
45    end
46    nthreads_set (nthreads, chunk) ;
47
48    % warmup
49    C2 = GB_mex_assign (C0, [ ], [ ], A, I, I) ;
50    C2 = GB_mex_assign (C0, [ ], [ ], A, I, I) ;
51    tg = grbresults ;
52
53    if (nthreads == 1)
54        t1 = tg ;
55    end
56
57    fprintf ('%3d : MATLAB: %10.4f GB: %10.4f speedup %10.4f %10.4f\n', ...
58        nthreads, tm, tg, tm / tg, t1/tg) ;
59
60    assert (isequal (C1, C2.matrix)) ;
61end
62
63
64fprintf ('\n--------------------------------------\n') ;
65fprintf ('B = C(I,J):\n') ;
66
67% warmup
68B1 = C1 (1:k,1:k) ;
69
70tic
71B1 = C1 (1:k,1:k) ;
72tm = toc ;
73S = sparse (k,k) ;
74
75for nthreads = [1 2 4 8 16 20 32 40 64]
76    if (nthreads > 2*ncores)
77        break ;
78    end
79    nthreads_set (nthreads, chunk) ;
80
81    % warmup
82    B2 = GB_mex_Matrix_extract (S, [ ], [ ], C1, I, I) ;
83
84    B2 = GB_mex_Matrix_extract (S, [ ], [ ], C1, I, I) ;
85    tg = grbresults ;
86
87    if (nthreads == 1)
88        t1 = tg ;
89    end
90
91    fprintf ('%3d : MATLAB: %10.4f GB: %10.4f speedup %10.4f %10.4f\n', ...
92        nthreads, tm, tg, tm / tg, t1/tg) ;
93
94    assert (isequal (B1, B2.matrix)) ;
95end
96
97nthreads_set (save, save_chunk) ;
98