Serialize accesses to parallelized level3 functions from multiple callers
for
@@ -514,6 +514,10 @@ static int gemm_driver(blas_arg_t *args, BLASLONG *range_m, BLASLONG
*range_n, FLOAT *sa, FLOAT *sb,
BLASLONG nthreads_m, BLASLONG nthreads_n) {
+#ifndef USE_OPENMP
+static pthread_mutex_t level3_lock = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
blas_arg_t newarg;
#ifndef USE_ALLOC_HEAP
@@ -554,6 +558,10 @@ static int gemm_driver(blas_arg_t *args, BLASLONG *range_m, BLASLONG
#endif
#endif
+#ifndef USE_OPENMP
+pthread_mutex_lock(&level3_lock);
+#endif
+
#ifdef USE_ALLOC_HEAP
/* Dynamically allocate workspace */
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
free(job);
#endif
+#ifndef USE_OPENMP
+ pthread_mutex_unlock(&level3_lock);
+#endif
+
return 0;
}
