Browse Source

Refs #294. Used pthread_atfork to avoid hang after a Unix fork.

The problem is the mutex we used in blas_server. Thus, we must clear
the mutex before the fork and re-init them at parent and child process.

If you used OpenMP, GOMP has the same problem by now. Please try other OpenMP
implemantation.
tags/v0.2.9.rc2^2
Zhang Xianyi 11 years ago
parent
commit
3617c22a56
4 changed files with 29 additions and 1 deletions
  1. +14
    -0
      driver/others/blas_server.c
  2. +5
    -0
      driver/others/blas_server_omp.c
  3. +5
    -0
      driver/others/blas_server_win32.c
  4. +5
    -1
      driver/others/memory.c

+ 14
- 0
driver/others/blas_server.c View File

@@ -83,6 +83,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#define ATTRIBUTE_SIZE 128

extern void openblas_warning(int verbose, const char * msg);

/* This is a thread server model implementation. The threads are */
/* spawned at first access to blas library, and still remains until */
/* destruction routine is called. The number of threads are */
@@ -921,5 +923,17 @@ int BLASFUNC(blas_thread_shutdown)(void){
return 0;
}

/*
https://github.com/xianyi/OpenBLAS/issues/294
Use pthread_atfork to close blas_thread_server before fork.
Then, re-init blas_thread_server after fork at child and parent.
*/
void openblas_fork_handler()
{
int err;
err = pthread_atfork (BLASFUNC(blas_thread_shutdown), blas_thread_init, blas_thread_init);
if(err != 0)
openblas_warning(0, "OpenBLAS cannot install fork handler. You may meet hang after fork.\n");
}
#endif


+ 5
- 0
driver/others/blas_server_omp.c View File

@@ -315,4 +315,9 @@ int exec_blas(BLASLONG num, blas_queue_t *queue){
return 0;
}

void openblas_fork_handler()
{

}

#endif

+ 5
- 0
driver/others/blas_server_win32.c View File

@@ -498,3 +498,8 @@ void openblas_set_num_threads(int num)
{
goto_set_num_threads(num);
}

void openblas_fork_handler()
{

}

+ 5
- 1
driver/others/memory.c View File

@@ -1288,7 +1288,11 @@ void CONSTRUCTOR gotoblas_init(void) {
#ifdef SMP
if (blas_cpu_number == 0) blas_get_cpu_number();
#ifdef SMP_SERVER
if (blas_server_avail == 0) blas_thread_init();
if (blas_server_avail == 0) {
blas_thread_init();
//deal with pthread and fork.
openblas_fork_handler();
}
#endif
#endif



Loading…
Cancel
Save