[openblas] 02/03: fork-handler.patch: improved version backported from upstream.
Sébastien Villemot
sebastien at debian.org
Fri Feb 21 15:50:45 UTC 2014
This is an automated email from the git hooks/post-receive script.
sebastien pushed a commit to branch master
in repository openblas.
commit b96b6eba8244705ad5d6436f2a47d17e58477869
Author: Sébastien Villemot <sebastien at debian.org>
Date: Thu Feb 20 21:42:44 2014 +0100
fork-handler.patch: improved version backported from upstream.
---
debian/patches/fork-handler.patch | 80 +++++++++++++++++++++++++++++++++------
1 file changed, 68 insertions(+), 12 deletions(-)
diff --git a/debian/patches/fork-handler.patch b/debian/patches/fork-handler.patch
index db4bba4..53d909f 100644
--- a/debian/patches/fork-handler.patch
+++ b/debian/patches/fork-handler.patch
@@ -2,35 +2,91 @@ Description: Add fork handler
This patches fixes hangs of OpenBLAS when called from a program using OpenMP.
Note that this will only work if OpenBLAS is compiled with pthreads
(i.e. no OpenMP).
-Origin: upstream, https://github.com/xianyi/OpenBLAS/issues/294#issuecomment-33536895
+Origin: upstream, https://github.com/xianyi/OpenBLAS/commit/138a8413903776242cb3c184df9838ba54d04044
Bug: https://github.com/xianyi/OpenBLAS/issues/294
Bug-Debian: http://bugs.debian.org/739331
-Last-Update: 2014-02-17
+Last-Update: 2014-02-20
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/driver/others/blas_server.c
++++ b/driver/others/blas_server.c
+@@ -74,6 +74,21 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ #include <sys/resource.h>
+ #endif
+
++#ifndef likely
++#ifdef __GNUC__
++#define likely(x) __builtin_expect(!!(x), 1)
++#else
++#define likely(x) (x)
++#endif
++#endif
++#ifndef unlikely
++#ifdef __GNUC__
++#define unlikely(x) __builtin_expect(!!(x), 0)
++#else
++#define unlikely(x) (x)
++#endif
++#endif
++
+ #ifdef SMP_SERVER
+
+ #undef MONITOR
+@@ -584,6 +599,10 @@ static BLASULONG exec_queue_lock = 0;
+
+ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
+
++#ifdef SMP_SERVER
++ // Handle lazy re-init of the thread-pool after a POSIX fork
++ if (unlikely(blas_server_avail == 0)) blas_thread_init();
++#endif
+ BLASLONG i = 0;
+ blas_queue_t *current = queue;
+ #if defined(OS_LINUX) && !defined(NO_AFFINITY) && !defined(PARAMTEST)
+@@ -708,7 +727,11 @@ int exec_blas_async_wait(BLASLONG num, b
+ /* Execute Threads */
+ int exec_blas(BLASLONG num, blas_queue_t *queue){
+
+- int (*routine)(blas_arg_t *, void *, void *, double *, double *, BLASLONG);
++#ifdef SMP_SERVER
++ // Handle lazy re-init of the thread-pool after a POSIX fork
++ if (unlikely(blas_server_avail == 0)) blas_thread_init();
++#endif
++ int (*routine)(blas_arg_t *, void *, void *, double *, double *, BLASLONG);
+
+ #ifdef TIMING_DEBUG
+ BLASULONG start, stop;
--- a/driver/others/memory.c
+++ b/driver/others/memory.c
-@@ -1260,6 +1260,14 @@ static void gotoblas_memory_init(void) {
+@@ -253,6 +253,21 @@ int goto_get_num_procs (void) {
+ return blas_cpu_number;
}
- #endif
-+static void openblas_fork_handler()
++void openblas_fork_handler()
+{
++ // This handler shuts down the OpenBLAS-managed PTHREAD pool when OpenBLAS is
++ // built with "make USE_OPENMP=0".
++ // Hanging can still happen when OpenBLAS is built against the libgomp
++ // implementation of OpenMP. The problem is tracked at:
++ // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60035
++ // In the mean time build with USE_OPENMP=0 or link against another
++ // implementation of OpenMP.
+ int err;
-+ err = pthread_atfork (BLASFUNC(blas_thread_shutdown), blas_thread_init, blas_thread_init);
++ err = pthread_atfork (BLASFUNC(blas_thread_shutdown), NULL, NULL);
+ if(err != 0)
-+ fprintf(stderr, "OpenBLAS cannot install fork handler. You may meet hang after fork.\n");
++ fprintf(stderr, "OpenBLAS Warning ... cannot install fork handler. You may meet hang after fork.\n");
+}
+
- /* Initialization for all function; this function should be called before main */
-
- static int gotoblas_initialized = 0;
-@@ -1268,6 +1276,8 @@ void CONSTRUCTOR gotoblas_init(void) {
+ int blas_get_cpu_number(void){
+ char *p;
+ #if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_DARWIN)
+@@ -1268,6 +1283,9 @@ void CONSTRUCTOR gotoblas_init(void) {
if (gotoblas_initialized) return;
++#ifdef SMP
+ openblas_fork_handler();
-+
++#endif
#ifdef PROFILE
moncontrol (0);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/openblas.git
More information about the debian-science-commits
mailing list