Is it possible to know which SciPy / NumPy functions run on multiple cores?
Asked Answered
B

1

5

I am trying to figure out explicitly which of the functions in SciPy/NumPy run on multiple processors. I can e.g. read in the SciPy reference manual that SciPy uses this, but I am more interested in exactly which functions do run parallel computations, because not all of them do. The dream scenario would of course be if it is included when you type help(SciPy.foo), but this does not seem to be the case.

Any help will be much appreciated.

Best,

Matias

Bramlett answered 4/8, 2011 at 12:33 Comment(3)
That's a bit tricky to answer since to some extent it's up to the BLAS/LAPACK library rather than to numpy/scipy. For example, MKL (software.intel.com/en-us/articles/intel-mkl) might use multiple cores where other libraries might not.Hearthstone
Is there a certain type of functions that you have in mind?Hearthstone
@aix I was thinking about SciPy in general, but maybe more focus on Linear algebra functions. I see that e.g. scipy.linalg.solve uses multiple cores (by just checking my system-monitor to see the activity of the cores).Bramlett
H
5

I think the question is better addressed to the BLAS/LAPACK libraries you use rather than to SciPy/NumPy.

Some BLAS/LAPACK libraries, such as MKL, use multiple cores natively where other implementations might not.

To take scipy.linalg.solve as an example, here's its source code (with some error handling code omitted for clarity):

def solve(a, b, sym_pos=0, lower=0, overwrite_a=0, overwrite_b=0,
          debug = 0):
    if sym_pos:
        posv, = get_lapack_funcs(('posv',),(a1,b1))
        c,x,info = posv(a1,b1,
                        lower = lower,
                        overwrite_a=overwrite_a,
                        overwrite_b=overwrite_b)
    else:
        gesv, = get_lapack_funcs(('gesv',),(a1,b1))
        lu,piv,x,info = gesv(a1,b1,
                             overwrite_a=overwrite_a,
                             overwrite_b=overwrite_b)

    if info==0:
        return x
    if info>0:
        raise LinAlgError, "singular matrix"
    raise ValueError,\
          'illegal value in %-th argument of internal gesv|posv'%(-info)

As you can see, it's just a thin wrapper around two families of LAPACK functions (exemplified by DPOSV and DGESV).

There is no parallelism going on at the SciPy level, yet you observe the function using multiple cores on your system. The only possible explanation is that your LAPACK library is capable of using multiple cores, without NumPy/SciPy doing anything to make this happen.

Hearthstone answered 4/8, 2011 at 13:43 Comment(2)
Thanks for a useful answer. I have Enthoughts 2.7.1 python which uses MKL, so I am in good shape.Bramlett
and how can we find out which BLAS/LAPACK functions run in parallel?Subgenus

© 2022 - 2024 — McMap. All rights reserved.