Skip to content

Commit 2e6fae2

Browse files
authored
Serialize accesses to parallelized level3 functions from multiple callers
for #1851
1 parent 76a66ea commit 2e6fae2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

driver/level3/level3_thread.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ static int gemm_driver(blas_arg_t *args, BLASLONG *range_m, BLASLONG
514514
*range_n, FLOAT *sa, FLOAT *sb,
515515
BLASLONG nthreads_m, BLASLONG nthreads_n) {
516516

517+
#ifndef USE_OPENMP
518+
static pthread_mutex_t level3_lock = PTHREAD_MUTEX_INITIALIZER;
519+
#endif
520+
517521
blas_arg_t newarg;
518522

519523
#ifndef USE_ALLOC_HEAP
@@ -554,6 +558,10 @@ static int gemm_driver(blas_arg_t *args, BLASLONG *range_m, BLASLONG
554558
#endif
555559
#endif
556560

561+
#ifndef USE_OPENMP
562+
pthread_mutex_lock(&level3_lock);
563+
#endif
564+
557565
#ifdef USE_ALLOC_HEAP
558566
/* Dynamically allocate workspace */
559567
job = (job_t*)malloc(MAX_CPU_NUMBER * sizeof(job_t));
@@ -671,6 +679,10 @@ static int gemm_driver(blas_arg_t *args, BLASLONG *range_m, BLASLONG
671679
free(job);
672680
#endif
673681

682+
#ifndef USE_OPENMP
683+
pthread_mutex_unlock(&level3_lock);
684+
#endif
685+
674686
return 0;
675687
}
676688

0 commit comments

Comments
 (0)