From df500725a6d36b63a77e0fa6abf70c4aa97c55b6 Mon Sep 17 00:00:00 2001 From: Nicolas Tessore Date: Sun, 14 Apr 2024 22:23:39 +0100 Subject: [PATCH] release Python GIL in numpy loops The Python GIL is now released while numpy evaluates the inner loops of the vectorised functions. This might help in applications where other Python code runs in parallel to healpix carrying out large computations. --- python/chealpix.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/chealpix.c b/python/chealpix.c index 289626f..b3e3cdd 100644 --- a/python/chealpix.c +++ b/python/chealpix.c @@ -91,11 +91,14 @@ PyObject* vectorize(vecfunc func, void* args, npy_intp nin, npy_intp nout, npy_intp *sizeptr = NpyIter_GetInnerLoopSizePtr(iter); npy_intp *stride = NpyIter_GetInnerStrideArray(iter); char **data = NpyIter_GetDataPtrArray(iter); + NPY_BEGIN_THREADS_DEF if (!iternext) goto iterfail; + NPY_BEGIN_THREADS_THRESHOLDED(NpyIter_GetIterSize(iter)) do { func(args, *sizeptr, data, stride); } while (iternext(iter)); + NPY_END_THREADS } out = &NpyIter_GetOperandArray(iter)[nin];