Skip to content

Commit f677f4f

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 c5f0dcf commit f677f4f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

driver/others/blas_server_omp.c

Lines changed: 4 additions & 0 deletions
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)
@@ -172,6 +173,9 @@ int BLASFUNC(blas_thread_shutdown)(void){
172173
}
173174
}
174175
}
176+
#if HAVE_OMP_PAUSE_RESOURCE_ALL
177+
omp_pause_resource_all(omp_pause_hard);
178+
#endif
175179

176180
return 0;
177181
}

0 commit comments

Comments
 (0)