Skip to content

Commit ef015a6

Browse files
committed
blas_thread_shutdown: release OpenMP resources too
OpenMP 5.0 introduced the function omp_pause_resource_all that instructs the runtime to "relinquish resources used by OpenMP on all devices". In practice, these resources include the locks that would otherwise trip up the runtime after a fork(). Releasing these resources in a function called by pthread_atfork() makes it possible for the child process to continue functioning after the runtime automatically re-acquires its resources. Thread safety: blas_thread_shutdown doesn't check whether there are other BLAS operations running in parallel, so this isn't any less safe than before with respect to OpenBLAS function calls. On the other hand, if there are other OpenMP operations in progress, asking the runtime to pause may result in unspecified behaviour. A hard pause is allowed to deallocate threadprivate variables too.
1 parent 0f41a46 commit ef015a6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

driver/others/blas_server_omp.c

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
#else
5050

51+
#include <omp.h>
5152
#ifndef likely
5253
#ifdef __GNUC__
5354
#define likely(x) __builtin_expect(!!(x), 1)
@@ -147,6 +148,9 @@ int BLASFUNC(blas_thread_shutdown)(void){
147148
}
148149
}
149150
}
151+
#if defined(_OPENMP) && _OPENMP >= 201811
152+
omp_pause_resource_all(omp_pause_hard);
153+
#endif
150154

151155
return 0;
152156
}

0 commit comments

Comments
 (0)