Repository navigation
Description
The combination of thread pools + fork is unfortunate: it tends to lead to random freezes. Unfortunately, the best way to achieve high-level parallelism in Python is to use fork (via the multiprocessing module).
Fundamentally the problem is that if you spawn a thread pool, and then fork, then the child ends up thinking that it has a thread pool, and dispatching work to it, but there aren't actually any threads running. This doesn't end well.
When using OMP for threading, dealing with this is the responsibility of the OMP implementation, and out-of-scope for BLIS itself. But when using pthreads, this should be handled by using pthread_atfork to register a pre-fork callback that shuts down the thread pool.
The equivalent issue in OpenBLAS was fixed in OpenMathLib/OpenBLAS#343, specifically with this code (which should probably actually be called openblas_install_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.
+#ifndef OS_WINDOWS
+ int err;
+ err = pthread_atfork (BLASFUNC(blas_thread_shutdown), NULL, NULL);
+ if(err != 0)
+ openblas_warning(0, "OpenBLAS Warning ... cannot install fork handler. You may meet hang after fork.\n");
+#endif
+}
The attached test case can also probably be re-used with trivial tweaks to use the BLIS API instead of cblas: https://github.com/ogrisel/OpenBLAS/blob/49bd98f410369c9604031296f8ff47c5c20052bb/utest/test_fork.c
Activity
devinamatthews commentedon Nov 2, 2016
BLIS doesn't have it's own thread pool implementation at this point, so this isn't an issue. If we ever get around to implementing one we will take this into consideration, though.
njsmith commentedon Nov 2, 2016
Huh, interesting. Do you only support omp now, or how does that work?
On Nov 2, 2016 11:34 AM, "Devin Matthews" [email protected] wrote:
devinamatthews commentedon Nov 2, 2016
We also support pthreads, but spawn new ones each time (yuck, I know).
On 11/2/16 2:31 PM, Nathaniel J. Smith wrote:
jeffhammond commentedon Nov 2, 2016
@njsmith
git grep pthread_is your friend 😉njsmith commentedon Nov 2, 2016
I promise that my notebook is covered in little "njs + git grep" doodles
with hearts around them, but in this case Devin's answer was more helpful
:-)
On Nov 2, 2016 12:43 PM, "Jeff Hammond" [email protected] wrote:
fgvanzee commentedon Nov 2, 2016
Wait, there's a
git-grepcommand? Where have I been?jeffhammond commentedon Nov 2, 2016
@fgvanzee I initialize git repos in directories from tarballs for no other reason than the speedup associated with
git grep.njsmith commentedon Nov 2, 2016
@jeffhammond: getting off-topic, but you might want to check out ripgrep
jeffhammond commentedon Nov 2, 2016
@njsmith I think it's fine to digress on a closed ticket, because sitting four inches to the right of this box is a magically button that allows the uninterested to terminate notifications related to this thread 😃
I read about
ripgrepbut I am satisfied with the performance of the default version, at least with thegitprefix, sincegitmagically elides a lot of the filesystem overhead (or something along those lines).Update to blis v0.7.0 (flame#30)
Delete kernels/x280 (flame#30)