3 ms·
Numpy operations release the GIL (usually at least) so you can use a threadpool and, indeed, share memory. Just try it and you may be pleasantly surprised. Das
by pletnes 6y ago
Numpy operations release the GIL (usually at least) so you can use a threadpool and, indeed, share memory. Just try it and you may be pleasantly surprised.
Dask is great if you’re processing large amounts of data, and it recommends and supports threads for this reason.
- ZuLuuuuuu 6y agoI didn't know that. So let's say I have 4 regular Python threads calling the same function, and in this function, let's say I call numpy.add on the same array (but different parts of the array), then will it actually use different cores for these 4 different threads? I will try it out, if it works, then that's actually great and would be super easy.
- pletnes 6y agoGreat, then my comment was worth it! Not sure there’s anything to prevent you from foot-shooting if you’re operating on the same array. I’d expect that this is only safe to do if, as you say, arrays are not overlapping. Let me know what you find.
- captain_price7 6y agoThe answer is No, isn't it?
- ZuLuuuuuu 6y agoI wrote a small code to test it. Unfortunately it didn't work, but I don't know if the problem is me, maybe I made a mistake...