summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-08-05 11:45:39 -0700
committerCharles Harris <charlesr.harris@gmail.com>2013-08-05 11:45:39 -0700
commit870d89e2b499e8ae48dec39df4962d61a0f770f1 (patch)
tree6d3068d899271385f3aa1aca5e674ce85729b445
parent3f99247298fbcd979ad0e631112e6810dca73dd0 (diff)
parent5a5e86f4fc2691064d2e36783cf0c05936cd9020 (diff)
downloadnumpy-870d89e2b499e8ae48dec39df4962d61a0f770f1.tar.gz
Merge pull request #3521 from arinkverma/gsoc_performance
ENH: Avoiding NPY_BEGIN_THREADS for small arrays can speed-up trivial_three_operand_loop by 5%
-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 968aec3b7..fc8dca950 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -922,6 +922,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 c3d804b2a..bea15c65c 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);