Skip to content

Commit f6e4cf2

Browse files
authored
Merge pull request #2876 from Flamefire/omp_fork_fix
Lazyly reinit threads after a fork in OMP mode
2 parents 9828343 + 3094fc6 commit f6e4cf2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

driver/others/blas_server_omp.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@
4848

4949
#else
5050

51+
#ifndef likely
52+
#ifdef __GNUC__
53+
#define likely(x) __builtin_expect(!!(x), 1)
54+
#else
55+
#define likely(x) (x)
56+
#endif
57+
#endif
58+
#ifndef unlikely
59+
#ifdef __GNUC__
60+
#define unlikely(x) __builtin_expect(!!(x), 0)
61+
#else
62+
#define unlikely(x) (x)
63+
#endif
64+
#endif
65+
5166
#ifndef OMP_SCHED
5267
#define OMP_SCHED static
5368
#endif
@@ -350,6 +365,9 @@ static void exec_threads(blas_queue_t *queue, int buf_index){
350365

351366
int exec_blas(BLASLONG num, blas_queue_t *queue){
352367

368+
// Handle lazy re-init of the thread-pool after a POSIX fork
369+
if (unlikely(blas_server_avail == 0)) blas_thread_init();
370+
353371
BLASLONG i, buf_index;
354372

355373
if ((num <= 0) || (queue == NULL)) return 0;

0 commit comments

Comments
 (0)