Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find a list of numpy functions which release the GIL?

Tags:

python

numpy

gil

I have found several SO questions asking about this in one way or another, but none of them actually either give a list or refer to one.

This question refers to a wiki page, but while the wiki page talks about the GIL and multi-threading, it doesn't give a list of GIL releasing functions.

This mailing list post indicates that the only way to find out is to read the numpy source. Really?

like image 898
DanielSank Avatar asked Jun 03 '14 18:06

DanielSank


People also ask

Does NumPy release the GIL?

According to this scipy cookbook, if you are using numpy to do array operations then Python will release the GIL, meaning that if you write your code in a numpy style, much of the calculations will be done in a few array operations, providing you with a speedup by using multiple threads.

Which of the following functionalities is performed by NumPy?

NumPy provides familiar mathematical functions such as sin, cos, and exp. In NumPy, these are called “universal functions” ( ufunc ). Within NumPy, these functions operate elementwise on an array, producing an array as output.

What is Python GIL stackoverflow?

In CPython, the global interpreter lock, or GIL, is a mutex that protects access to Python objects, preventing multiple threads from executing Python bytecodes at once. The GIL prevents race conditions and ensures thread safety. A nice explanation of how the Python GIL helps in these areas can be found here.

What is GIL in CPython?

In CPython, the Global Interpreter Lock (GIL) is a mutex that allows only one thread at a time to have the control of the Python interpreter. In other words, the lock ensures that only one thread is running at any given time. Therefore, it is impossible to take advantage of multiple processors with threads.


1 Answers

It's not guaranteed to catch everything, but I just ran:

git grep nogil

in my clone of the numpy repository. It turns up 82 usages in 2 files:

  • random/mtrand/mtrand.pyx
  • random/mtrand/numpy.pxd
like image 145
perimosocordiae Avatar answered Sep 20 '22 13:09

perimosocordiae