[SciPy-Dev] Multithreading sparse matrix to dense vector(s) multiplication

Ralf Gommers ralf.gommers at gmail.com
Mon Mar 16 13:44:14 EDT 2020


On Mon, Mar 16, 2020 at 6:25 PM Roman Yurchak <rth.yurchak at gmail.com> wrote:

> Hello Jorge,
>
> FYI there have been previous discussions about related topics in
> https://github.com/scipy/scipy/issues/10201
>
> Also see https://github.com/scipy/scipy/issues/10239 for considerations
> about supporting OpenMP. I'm not sure if there are any plans for
> supporting it in the future.
>

OpenMP is indeed not a good option, however we do have both C++
multithreading code in cKDTree and scipy.fft, and Python multiprocessing
code in the likes of differential_evolution. Those patterns can be followed
for other functions (in all cases, using a workers=1 keyword).

An issue for matvec et al. may be that they can be called from operators,
those of course cannot get a keyword. I don't see a good way around that,
since using multiple threads by default is not a good idea (this messes
with composability, multiprocessing may happen at a higher level already,
like with dask or scikit-learn).

Cheers,
Ralf


> Can't help with the pThreads implementation, but generally I think
> multi-threading sparse operations if possible would be quite useful.
>
> --
> Roman
>
> On 16/03/2020 17:56, Jorge Guerra wrote:
> > Hello everyone,
> >
> > I'm quite new to the SciPy development community. I've identified a
> > potential improvement that would be very helpful:
> >
> > in scipy/sparse/sparsetools/csr.h @ lines 1092 and 1129 in the
> > csr_matvec() and mat_vecs() methods I would like to parallelize the
> > outer for loop over the rows of the input sparse matrix. The current
> > serial code looks just about optimal, but should take advantage of a
> > multicore machine. This is a place where SciPy is deficient.
> >
> > Going through the compilation, SciPy depends on pThreads. However, my
> > proposed change would be trivial by including OpenMP, but I don't
> > necessarily want to add to the overall dependencies.
> >
> > Would anyone more familiar with pThreads be willing to collaborate with
> > me to accomplish this proposed task? Or perhaps advice on an alternative
> > to get multithreaded sparse matrix to dense vector multiplication
> > implemented?
> >
> > Thank you all!
> >
> > Jorge
> >
> > --
> > /Jorge E. Guerra, PhD./
> > /Research Scientist, CIMMS/NOAA/
> > /Earth Systems Research Laboratory, Boulder, CO/
> >
> > _______________________________________________
> > SciPy-Dev mailing list
> > SciPy-Dev at python.org
> > https://mail.python.org/mailman/listinfo/scipy-dev
> >
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20200316/187753b2/attachment.html>


More information about the SciPy-Dev mailing list