Skip to content

Commit f72fdf5

Browse files
authored
Merge pull request #1875 from martin-frbg/issue1851
Serialize accesses to parallelized level3 functions from multiple cal…
2 parents 5393759 + 113cb00 commit f72fdf5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

driver/level3/level3_thread.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,15 @@ static int gemm_driver(blas_arg_t *args, BLASLONG *range_m, BLASLONG
528528
*range_n, FLOAT *sa, FLOAT *sb,
529529
BLASLONG nthreads_m, BLASLONG nthreads_n) {
530530

531+
#ifndef USE_OPENMP
532+
#ifndef OS_WINDOWS
533+
static pthread_mutex_t level3_lock = PTHREAD_MUTEX_INITIALIZER;
534+
#else
535+
CRITICAL_SECTION level3_lock;
536+
InitializeCriticalSection((PCRITICAL_SECTION)&level3_lock);
537+
#endif
538+
#endif
539+
531540
blas_arg_t newarg;
532541

533542
#ifndef USE_ALLOC_HEAP
@@ -568,6 +577,14 @@ static int gemm_driver(blas_arg_t *args, BLASLONG *range_m, BLASLONG
568577
#endif
569578
#endif
570579

580+
#ifndef USE_OPENMP
581+
#ifndef OS_WINDOWS
582+
pthread_mutex_lock(&level3_lock);
583+
#else
584+
EnterCriticalSection((PCRITICAL_SECTION)&level3_lock);
585+
#endif
586+
#endif
587+
571588
#ifdef USE_ALLOC_HEAP
572589
/* Dynamically allocate workspace */
573590
job = (job_t*)malloc(MAX_CPU_NUMBER * sizeof(job_t));
@@ -693,6 +710,14 @@ static int gemm_driver(blas_arg_t *args, BLASLONG *range_m, BLASLONG
693710
free(job);
694711
#endif
695712

713+
#ifndef USE_OPENMP
714+
#ifndef OS_WINDOWS
715+
pthread_mutex_unlock(&level3_lock);
716+
#else
717+
LeaveCriticalSection((PCRITICAL_SECTION)&level3_lock);
718+
#endif
719+
#endif
720+
696721
return 0;
697722
}
698723

0 commit comments

Comments
 (0)