Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jagot/threadedsparsearrays.jl


https://github.com/jagot/threadedsparsearrays.jl

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# ThreadedSparseArrays.jl

[![Build Status](https://github.com/jagot/ThreadedSparseArrays.jl/workflows/CI/badge.svg)](https://github.com/jagot/ThreadedSparseArrays.jl/actions)
[![Codecov](https://codecov.io/gh/jagot/ThreadedSparseArrays.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/jagot/ThreadedSparseArrays.jl)

Simple package providing a wrapper type enabling threaded sparse
matrix–dense matrix multiplication. Based on [this
PR](https://github.com/JuliaLang/julia/pull/29525).

## 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](https://docs.julialang.org/en/v1/manual/environment-variables/#JULIA_NUM_THREADS-1)
environment variable. To test that it is set properly, run
```julia
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:
```julia
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](https://github.com/JuliaCI/BenchmarkTools.jl)
package to check if your use case is improved.