Skip to content

Commit 802cf6b

Browse files
authored
Merge pull request #1486 from martin-frbg/atomic
Use _Atomic instead of volatile for thread safety where C11 is supported
2 parents 954f183 + 20c6c38 commit 802cf6b

File tree

5 files changed

+709
-11
lines changed

5 files changed

+709
-11
lines changed

driver/level3/level3_gemm3m_thread.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@
9191
#endif
9292

9393
typedef struct {
94-
volatile BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
94+
#if _STDC_VERSION__ >= 201112L
95+
_Atomic
96+
#else
97+
volatile
98+
#endif
99+
BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
95100
} job_t;
96101

97102

driver/level3/level3_syrk_threaded.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@
6767
#endif
6868

6969
typedef struct {
70-
volatile BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
70+
#if _STDC_VERSION__ >= 201112L
71+
_Atomic
72+
#else
73+
volatile
74+
#endif
75+
BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
7176
} job_t;
7277

7378

driver/level3/level3_thread.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@
9191
#endif
9292

9393
typedef struct {
94-
volatile BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
94+
#if _STDC_VERSION__ >= 201112L
95+
_Atomic
96+
#else
97+
volatile
98+
#endif
99+
BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
95100
} job_t;
96101

97102

lapack/getrf/getrf_parallel.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ static void inner_basic_thread(blas_arg_t *args, BLASLONG *range_m, BLASLONG *ra
119119
FLOAT *d = (FLOAT *)args -> b + (k + k * lda) * COMPSIZE;
120120
FLOAT *sbb = sb;
121121

122+
#if _STDC_VERSION__ >= 201112L
123+
_Atomic BLASLONG *flag = (_Atomic BLASLONG *)args -> d;
124+
#else
122125
volatile BLASLONG *flag = (volatile BLASLONG *)args -> d;
126+
#endif
123127

124128
blasint *ipiv = (blasint *)args -> c;
125129

@@ -197,7 +201,12 @@ static void inner_basic_thread(blas_arg_t *args, BLASLONG *range_m, BLASLONG *ra
197201
/* Non blocking implementation */
198202

199203
typedef struct {
200-
volatile BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
204+
#if _STDC_VERSION__ >= 201112L
205+
_Atomic
206+
#else
207+
volatile
208+
#endif
209+
BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
201210
} job_t;
202211

203212
#define ICOPY_OPERATION(M, N, A, LDA, X, Y, BUFFER) GEMM_ITCOPY(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, BUFFER);
@@ -236,11 +245,12 @@ static int inner_advanced_thread(blas_arg_t *args, BLASLONG *range_m, BLASLONG *
236245
FLOAT *sbb= sb;
237246

238247
blasint *ipiv = (blasint *)args -> c;
239-
240-
BLASLONG jw;
241-
248+
BLASLONG jw;
249+
#if _STDC_VERSION__ >= 201112L
250+
_Atomic BLASLONG *flag = (_Atomic BLASLONG *)args -> d;
251+
#else
242252
volatile BLASLONG *flag = (volatile BLASLONG *)args -> d;
243-
253+
#endif
244254
if (args -> a == NULL) {
245255
TRSM_ILTCOPY(k, k, (FLOAT *)args -> b, lda, 0, sb);
246256
sbb = (FLOAT *)((((BLASULONG)(sb + k * k * COMPSIZE) + GEMM_ALIGN) & ~GEMM_ALIGN) + GEMM_OFFSET_B);
@@ -442,7 +452,12 @@ blasint CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa,
442452
#ifdef _MSC_VER
443453
BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE];
444454
#else
445-
volatile BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
455+
#if _STDC_VERSION__ >= 201112L
456+
_Atomic
457+
#else
458+
volatile
459+
#endif
460+
BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
446461
#endif
447462

448463
#ifndef COMPLEX
@@ -713,8 +728,12 @@ blasint CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa,
713728
BLASLONG range[MAX_CPU_NUMBER + 1];
714729

715730
BLASLONG width, nn, num_cpu;
716-
717-
volatile BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
731+
#if _STDC_VERSION__ >= 201112L
732+
_Atomic
733+
#else
734+
volatile
735+
#endif
736+
BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
718737

719738
#ifndef COMPLEX
720739
#ifdef XDOUBLE

0 commit comments

Comments
 (0)