[Numpy-discussion] IDL vs Python parallel computing

Julian Taylor jtaylor.debian at googlemail.com
Wed May 7 14:27:48 EDT 2014


On 07.05.2014 20:11, Sturla Molden wrote:
> On 03/05/14 23:56, Siegfried Gonzi wrote:
> 
> A more technical answer is that NumPy's internals does not play very 
> nicely with multithreading. For examples the array iterators used in 
> ufuncs store an internal state. Multithreading would imply an excessive 
> contention for this state, as well as induce false sharing of the 
> iterator object. Therefore, a multithreaded NumPy would have performance 
> problems due to synchronization as well as hierachical memory 
> collisions. Adding multithreading support to the current NumPy core 
> would just degrade the performance. NumPy will not be able to use 
> multithreading efficiently unless we redesign the iterators in NumPy 
> core. That is a massive undertaking which prbably means rewriting most 
> of NumPy's core C code. A better strategy would be to monkey-patch some 
> of the more common ufuncs with multithreaded versions.


I wouldn't say that the iterator is a problem, the important iterator
functions are threadsafe and there is support for multithreaded
iteration using NpyIter_Copy so no data is shared between threads.

I'd say the main issue is that there simply aren't many functions worth
parallelizing in numpy. Most the commonly used stuff is already memory
bandwidth bound with only one or two threads.
The only things I can think of that would profit is sorting/partition
and the special functions like sqrt, exp, log, etc.

Generic efficient parallelization would require merging of operations
improve the FLOPS/loads ratio. E.g. numexpr and theano are able to do so
and thus also has builtin support for multithreading.

That being said you can use Python threads with numpy as (especially in
1.9) most expensive functions release the GIL. But unless you are doing
very flop intensive stuff you will probably have to manually block your
operations to the last level cache size if you want to scale beyond one
or two threads.



More information about the NumPy-Discussion mailing list