ThreadedSparseArrays.jl

Author jagot
Popularity
10 Stars
Updated Last
1 Year Ago
Started In
March 2020

ThreadedSparseArrays.jl

Build Status Codecov

Simple package providing a wrapper type enabling threaded sparse matrix–dense matrix multiplication. Based on this PR.

Installation

Install with:

] add ThreadedSparseArrays

Note that you must enable threading in Julia for ThreadedSparseArrays to work. You can do so by setting the JULIA_NUM_THREADS environment variable. To test that it is set properly, run

Threads.nthreads()

and make sure it returns the number of threads you wanted.

Example usage

To use ThreadedSparseArrays, all you need to do is to wrap your sparse matrix using the ThreadedSparseMatrixCSC type, like this:

using SparseArrays
using ThreadedSparseArrays

A = sprand(10000, 100, 0.05); # sparse
X1 = randn(100, 100); # dense
X2 = randn(10000, 100); # dense

At = ThreadedSparseMatrixCSC(A); # threaded version

# threaded sparse matrix–dense matrix multiplication
B1 = At*X1;
B2 = At'X2;

Notes

  • If the right hand side X is a Vector, you need to use At'X to get threading. At*X will not work.
  • You might only get speedups for large matrices. Use @btime from the BenchmarkTools.jl package to check if your use case is improved.

Required Packages

Used By Packages