summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorArink Verma <arinkverma@gmail.com>2013-07-12 17:50:00 +0530
committerArink Verma <arinkverma@gmail.com>2013-08-05 17:08:52 +0530
commit5a5e86f4fc2691064d2e36783cf0c05936cd9020 (patch)
tree40a3131ae89796f5ab4eff7fff889b5a5bc893b9 /numpy/core
parent6815f865678e88dab68c00c34fb1c9e7166f8f3c (diff)
downloadnumpy-5a5e86f4fc2691064d2e36783cf0c05936cd9020.tar.gz
ENH: For smaller array, added macro NPY_BEGIN_THREADS_THRESHOLDED in ndarraytypes.h
Avoiding NPY_BEGIN_THREADS for small arrays, can speed-up trivial_three_operand_loop by 5%. As releases of GIL, then quickly restoring just after small operation doesn't benefit.
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h2
-rw-r--r--numpy/core/src/umath/ufunc_object.c4
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);