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.
This commit is contained in:
Ivan K 2023-06-10 20:35:59 +03:00
parent 0f41a4664f
commit ef015a6830
1 changed files with 4 additions and 0 deletions

View File

@ -48,6 +48,7 @@
#else
#include <omp.h>
#ifndef likely
#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
@ -147,6 +148,9 @@ int BLASFUNC(blas_thread_shutdown)(void){
}
}
}
#if defined(_OPENMP) && _OPENMP >= 201811
omp_pause_resource_all(omp_pause_hard);
#endif
return 0;
}