Skip to content

Commit 40160ff

Browse files
authored
Use _Atomic instead of volatile for thread safety where C11 is supported
1 parent 6a99fcc commit 40160ff

File tree

2 files changed

+690
-6
lines changed

2 files changed

+690
-6
lines changed

lapack/getrf/getrf_parallel.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ static void inner_basic_thread(blas_arg_t *args, BLASLONG *range_m, BLASLONG *ra
9999
FLOAT *d = (FLOAT *)args -> b + (k + k * lda) * COMPSIZE;
100100
FLOAT *sbb = sb;
101101

102+
#if _STDC_VERSION__ >= 201112L
103+
_Atomic BLASLONG *flag = (_Atomic BLASLONG *)args -> d;
104+
#else
102105
volatile BLASLONG *flag = (volatile BLASLONG *)args -> d;
106+
#endif
103107

104108
blasint *ipiv = (blasint *)args -> c;
105109

@@ -177,7 +181,12 @@ static void inner_basic_thread(blas_arg_t *args, BLASLONG *range_m, BLASLONG *ra
177181
/* Non blocking implementation */
178182

179183
typedef struct {
180-
volatile BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
184+
#if _STDC_VERSION__ >= 201112L
185+
_Atomic
186+
#else
187+
volatile
188+
#endif
189+
BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
181190
} job_t;
182191

183192
#define ICOPY_OPERATION(M, N, A, LDA, X, Y, BUFFER) GEMM_ITCOPY(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, BUFFER);
@@ -216,9 +225,11 @@ static int inner_advanced_thread(blas_arg_t *args, BLASLONG *range_m, BLASLONG *
216225
FLOAT *sbb= sb;
217226

218227
blasint *ipiv = (blasint *)args -> c;
219-
228+
#if _STDC_VERSION__ >= 201112L
229+
_Atomic BLASLONG *flag = (_Atomic BLASLONG *)args -> d;
230+
#else
220231
volatile BLASLONG *flag = (volatile BLASLONG *)args -> d;
221-
232+
#endif
222233
if (args -> a == NULL) {
223234
TRSM_ILTCOPY(k, k, (FLOAT *)args -> b, lda, 0, sb);
224235
sbb = (FLOAT *)((((BLASULONG)(sb + k * k * COMPSIZE) + GEMM_ALIGN) & ~GEMM_ALIGN) + GEMM_OFFSET_B);
@@ -378,7 +389,12 @@ blasint CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa,
378389
#ifdef _MSC_VER
379390
BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE];
380391
#else
381-
volatile BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
392+
#if _STDC_VERSION__ >= 201112L
393+
_Atomic
394+
#else
395+
volatile
396+
#endif
397+
BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
382398
#endif
383399

384400
#ifndef COMPLEX
@@ -634,8 +650,12 @@ blasint CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa,
634650
BLASLONG range[MAX_CPU_NUMBER + 1];
635651

636652
BLASLONG width, nn, num_cpu;
637-
638-
volatile BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
653+
#if _STDC_VERSION__ >= 201112L
654+
_Atomic
655+
#else
656+
volatile
657+
#endif
658+
BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
639659

640660
#ifndef COMPLEX
641661
#ifdef XDOUBLE

0 commit comments

Comments
 (0)