Skip to content

Could sparse matrix-vector multiplication be optimized #732

@lesshaste

Description

@lesshaste

Take this simple code:

using BenchmarkTools
n = 10^7
M = convert(SparseMatrixCSC{UInt32, UInt32}, round.(10*sprand( n, n,  4*1/n)))
v = ones(UInt32, n)
@benchmark M*v

At this point M has the following property.:

10000000×10000000 SparseMatrixCSC{UInt32,UInt32} with 37999566 stored entries

The computation M*v should take exactly 37,999,566 multiplications and no more than that number of additions.

BenchmarkTools.Trial: 
   memory estimate:  38.15 MiB
  allocs estimate:  2
  --------------
  minimum time:     760.211 ms (0.00% GC)
  median time:      760.683 ms (0.00% GC)
  mean time:        762.270 ms (0.00% GC)
  maximum time:     766.944 ms (0.00% GC)
   --------------
  samples:          7
  evals/sample:     1

This seems slower than I expected given the number of multiplications and additions.

Is the problem the CSC format of the matrix? Would it be faster if M were in CSR format?

Metadata

Metadata

Assignees

No one assigned

    Labels

    sparseSparse arrays

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions