Skip to content

Commit

Permalink
Release GIL before calling C subroutines
Browse files Browse the repository at this point in the history
The MSIS C-functions don't interact with python, so we can declare them
thread-safe and make the code release the GIL for them.
Should not harm normal use cases but may help with multi-threaded
calculations as every MSIS grid point can be calculated completely
independently.

See also:
https://docs.python.org/3/c-api/init.html#releasing-the-gil-from-extension-code
  • Loading branch information
st-bender committed Sep 26, 2023
1 parent 6d97734 commit 6cdefba
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/nrlmsise00/nrlmsise00module.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ static PyObject *nrlmsise00_gtd7(PyObject *self, PyObject *args, PyObject *kwarg

msis_input.ap_a = &ap_arr;

Py_BEGIN_ALLOW_THREADS
gtd7(&msis_input, &msis_flags, &msis_output);
Py_END_ALLOW_THREADS

return Py_BuildValue("[ddddddddd][dd]",
msis_output.d[0], msis_output.d[1], msis_output.d[2],
Expand Down Expand Up @@ -268,7 +270,9 @@ static PyObject *nrlmsise00_gtd7d(PyObject *self, PyObject *args, PyObject *kwar

msis_input.ap_a = &ap_arr;

Py_BEGIN_ALLOW_THREADS
gtd7d(&msis_input, &msis_flags, &msis_output);
Py_END_ALLOW_THREADS

return Py_BuildValue("[ddddddddd][dd]",
msis_output.d[0], msis_output.d[1], msis_output.d[2],
Expand Down

0 comments on commit 6cdefba

Please sign in to comment.