Skip to content

Commit

Permalink
blas_thread_shutdown: release OpenMP resources too
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aitap committed Feb 19, 2025
1 parent c5f0dcf commit f677f4f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions driver/others/blas_server_omp.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

#else

#include <omp.h>
#ifndef likely
#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
Expand Down Expand Up @@ -172,6 +173,9 @@ int BLASFUNC(blas_thread_shutdown)(void){
}
}
}
#if HAVE_OMP_PAUSE_RESOURCE_ALL
omp_pause_resource_all(omp_pause_hard);
#endif

return 0;
}
Expand Down

0 comments on commit f677f4f

Please sign in to comment.