diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/include/numpy/ndarraytypes.h | 2 | ||||
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h index bb3f1065c..b38c6e6dc 100644 --- a/numpy/core/include/numpy/ndarraytypes.h +++ b/numpy/core/include/numpy/ndarraytypes.h @@ -921,6 +921,8 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *); #define NPY_BEGIN_THREADS_DEF PyThreadState *_save=NULL; #define NPY_BEGIN_THREADS do {_save = PyEval_SaveThread();} while (0); #define NPY_END_THREADS do {if (_save) PyEval_RestoreThread(_save);} while (0); +#define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) do { if (loop_size > 500) \ + { _save = PyEval_SaveThread();} } while (0); #define NPY_BEGIN_THREADS_DESCR(dtype) \ do {if (!(PyDataType_FLAGCHK(dtype, NPY_NEEDS_PYAPI))) \ diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index 2b5f38d25..6a8b14d06 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -1098,7 +1098,7 @@ trivial_two_operand_loop(PyArrayObject **op, NPY_UF_DBG_PRINT1("two operand loop count %d\n", (int)count[0]); if (!needs_api) { - NPY_BEGIN_THREADS; + NPY_BEGIN_THREADS_THRESHOLDED(count[0]); } innerloop(data, count, stride, innerloopdata); @@ -1131,7 +1131,7 @@ trivial_three_operand_loop(PyArrayObject **op, NPY_UF_DBG_PRINT1("three operand loop count %d\n", (int)count[0]); if (!needs_api) { - NPY_BEGIN_THREADS; + NPY_BEGIN_THREADS_THRESHOLDED(count[0]); } innerloop(data, count, stride, innerloopdata); |