% Run the GraphBLAS demo2

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
% SPDX-License-Identifier: GPL-3.0-or-later

% reset to the default number of threads
clear all
maxNumCompThreads ('automatic') ;
GrB.clear ;

gbdemo2
 GBDEMO2 Extreme performance differences: GraphBLAS vs MATLAB.
 
  Usage:
 
        gbdemo2             % uses a default bnz = 6000
        gbdemo2 (20000)     % uses bnz = 20000
 
  Many of the GraphBLAS operations used in gbdemo are perhaps 3x to
  50x faster than the corresponding MATLAB operations, depending on how
  many cores your computer has.  Here's an example where GraphBLAS is
  asymptotically far faster than MATLAB R2019a: a simple assignment
  for a large matrix C:
 
        C(I,J) = A
 
  The matrix C is constructed via C = kron (B,B) where nnz (B) is
  roughly the bnz provided on input (with a default of bnz = 6000),
  so that C will have about bnz^2 entries, or 36 million by default.
  I and J are chosen randomly, and A is 5000-by-5000.
 
  When the problem becomes large, MATLAB will take a very long time.
  If you have enough memory, and want to see higher speedups in
  GraphBLAS, increase bnz (and be prepared to wait even longer).
  With the default bnz = 6000, this test takes about 4GB of RAM.
 
  On my Dell XPS 4-core laptop (Intel(R) Core(TM) i7-8565U, 16GB
  RAM), using MATLAB R2019a, when C becomes 9 million by 9 million,
  the computation C(I,J)=A for MATLAB matrices C, I, J, and A takes
  several minutes, whereas GraphBLAS takes less than a second, or
  about 500x faster than MATLAB.  On a desktop with an Intel(R)
  Xeon(R) CPU E5-2698 v4 @ 2.20GHz with 20 hardware cores, the
  speedup over MATLAB is even more dramatic (up to 2,660x has been
  observed).
 
  See also GrB.assign, subsasgn.


# of threads used in GraphBLAS: 4


C(I,J)=A where C is 1 million -by- 1 million
with 35.7126 million entries:

    A is 5000-by-5000 with 49947 entries
    setup time:     0.277711 sec
    GraphBLAS time: 0.320164 sec
    Starting MATLAB ... please wait ... 
    MATLAB time:    0.320659 sec
    Speedup of GraphBLAS over MATLAB: 1.00155
    check time:     0.348989 sec
    all tests passed

C(I,J)=A where C is 4 million -by- 4 million
with 35.8202 million entries:

    A is 5000-by-5000 with 49947 entries
    setup time:     0.310457 sec
    GraphBLAS time: 0.322529 sec
    Starting MATLAB ... please wait ... 
    MATLAB time:    0.32423 sec
    Speedup of GraphBLAS over MATLAB: 1.00527
    check time:     0.293382 sec
    all tests passed

C(I,J)=A where C is 9 million -by- 9 million
with 35.928 million entries:

    A is 5000-by-5000 with 49947 entries
    setup time:     0.35514 sec
    GraphBLAS time: 0.404934 sec
    Starting MATLAB ... please wait ... 
    MATLAB time:    185.019 sec
    Speedup of GraphBLAS over MATLAB: 456.911
    check time:     0.321051 sec
    all tests passed

C(I,J)=A where C is 16 million -by- 16 million
with 35.916 million entries:

    A is 5000-by-5000 with 49947 entries
    setup time:     0.408315 sec
    GraphBLAS time: 0.508977 sec
    Starting MATLAB ... please wait ... 
    MATLAB time:    203.05 sec
    Speedup of GraphBLAS over MATLAB: 398.937
    check time:     0.372925 sec
    all tests passed

C(I,J)=A where C is 25 million -by- 25 million
with 35.964 million entries:

    A is 5000-by-5000 with 49947 entries
    setup time:     0.462268 sec
    GraphBLAS time: 0.4611 sec
    Starting MATLAB ... please wait ... 
    MATLAB time:    224.621 sec
    Speedup of GraphBLAS over MATLAB: 487.141
    check time:     0.431299 sec
    all tests passed

C(I,J)=A where C is 36 million -by- 36 million
with 35.976 million entries:

    A is 5000-by-5000 with 49947 entries
    setup time:     0.522331 sec
    GraphBLAS time: 0.809015 sec
    Starting MATLAB ... please wait ... 
    MATLAB time:    250.601 sec
    Speedup of GraphBLAS over MATLAB: 309.761
    check time:     0.4963 sec
    all tests passed