|
1 |
| -# ThreadedSparseArrays |
| 1 | +# ThreadedSparseArrays.jl |
2 | 2 |
|
3 | 3 | [](https://travis-ci.com/jagot/ThreadedSparseArrays.jl)
|
4 | 4 | [](https://ci.appveyor.com/project/jagot/ThreadedSparseArrays-jl)
|
|
7 | 7 | Simple package providing a wrapper type enabling threaded sparse
|
8 | 8 | matrix–dense matrix multiplication. Based on [this
|
9 | 9 | PR](https://github.com/JuliaLang/julia/pull/29525).
|
| 10 | + |
| 11 | +## Installation |
| 12 | +ThreadedSparseArrays.jl is not yet a registered package, but you can |
| 13 | +install it with: |
| 14 | +``` |
| 15 | +] add [email protected]:jagot/ThreadedSparseArrays.jl.git |
| 16 | +``` |
| 17 | + |
| 18 | +Note that you *must* enable threading in Julia for |
| 19 | +ThreadedSparseArrays to work. You can do so by setting the |
| 20 | +[JULIA_NUM_THREADS](https://docs.julialang.org/en/v1/manual/environment-variables/#JULIA_NUM_THREADS-1) |
| 21 | +environment variable. To test that it is set properly, run |
| 22 | +```julia |
| 23 | +Threads.nthreads() |
| 24 | +``` |
| 25 | +and make sure it returns the number of threads you wanted. |
| 26 | + |
| 27 | + |
| 28 | +## Example usage |
| 29 | +To use ThreadedSparseArrays, all you need to do is to wrap your sparse |
| 30 | +matrix using the ThreadedSparseMatrixCSC type, like this: |
| 31 | +```julia |
| 32 | +using SparseArrays |
| 33 | +using ThreadedSparseArrays |
| 34 | + |
| 35 | +A = sprand(10000, 100, 0.05); # sparse |
| 36 | +X1 = randn(100, 100); # dense |
| 37 | +X2 = randn(10000, 100); # dense |
| 38 | + |
| 39 | +At = ThreadedSparseMatrixCSC(A); # threaded version |
| 40 | + |
| 41 | +# threaded sparse matrix–dense matrix multiplication |
| 42 | +B1 = At*X1; |
| 43 | +B2 = At'X2; |
| 44 | +``` |
| 45 | + |
| 46 | +## Notes |
| 47 | +* If the right hand side `X` is a `Vector`, you need to use `At'X` to |
| 48 | +get threading. `A*X` will not work. |
| 49 | +* You might only get speedups for large matrices. Use `@btime` from |
| 50 | +the [BenchmarkTools.jl](https://github.com/JuliaCI/BenchmarkTools.jl) |
| 51 | +package to check if your use case is improved. |
0 commit comments