From 0c60ce13b2148b3b13c75e1d99625b2d94701df3 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Mon, 27 Nov 2017 17:34:55 +0000 Subject: Merging r318848: ------------------------------------------------------------------------ r318848 | hahnfeld | 2017-11-22 09:15:20 -0800 (Wed, 22 Nov 2017) | 7 lines Fix for OMP doacross implementation on Power Power has a weak consistency model so we need memory barriers to make writes (both from runtime and from user code) available for all threads. Differential Revision: https://reviews.llvm.org/D40175 ------------------------------------------------------------------------ llvm-svn: 319057 --- openmp/runtime/src/kmp_csupport.cpp | 9 ++++++++- openmp/runtime/test/worksharing/for/kmp_doacross_check.c | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/openmp/runtime/src/kmp_csupport.cpp b/openmp/runtime/src/kmp_csupport.cpp index 1f61870..d6e4ff5 100644 --- a/openmp/runtime/src/kmp_csupport.cpp +++ b/openmp/runtime/src/kmp_csupport.cpp @@ -3108,7 +3108,9 @@ void __kmpc_doacross_init(ident_t *loc, int gtid, int num_dims, if (flags == NULL) { // we are the first thread, allocate the array of flags size_t size = trace_count / 8 + 8; // in bytes, use single bit per iteration - sh_buf->doacross_flags = (kmp_uint32 *)__kmp_thread_calloc(th, size, 1); + flags = (kmp_uint32 *)__kmp_thread_calloc(th, size, 1); + KMP_MB(); + sh_buf->doacross_flags = flags; } else if (flags == (kmp_uint32 *)1) { #if KMP_32_BIT_ARCH // initialization is still in progress, need to wait @@ -3117,6 +3119,9 @@ void __kmpc_doacross_init(ident_t *loc, int gtid, int num_dims, while (*(volatile kmp_int64 *)&sh_buf->doacross_flags == 1LL) #endif KMP_YIELD(TRUE); + KMP_MB(); + } else { + KMP_MB(); } KMP_DEBUG_ASSERT(sh_buf->doacross_flags > (kmp_uint32 *)1); // check ptr value pr_buf->th_doacross_flags = @@ -3212,6 +3217,7 @@ void __kmpc_doacross_wait(ident_t *loc, int gtid, long long *vec) { while ((flag & pr_buf->th_doacross_flags[iter_number]) == 0) { KMP_YIELD(TRUE); } + KMP_MB(); KA_TRACE(20, ("__kmpc_doacross_wait() exit: T#%d wait for iter %lld completed\n", gtid, (iter_number << 5) + shft)); @@ -3264,6 +3270,7 @@ void __kmpc_doacross_post(ident_t *loc, int gtid, long long *vec) { shft = iter_number % 32; // use 32-bit granularity iter_number >>= 5; // divided by 32 flag = 1 << shft; + KMP_MB(); if ((flag & pr_buf->th_doacross_flags[iter_number]) == 0) KMP_TEST_THEN_OR32(&pr_buf->th_doacross_flags[iter_number], flag); KA_TRACE(20, ("__kmpc_doacross_post() exit: T#%d iter %lld posted\n", gtid, diff --git a/openmp/runtime/test/worksharing/for/kmp_doacross_check.c b/openmp/runtime/test/worksharing/for/kmp_doacross_check.c index c0ee201..a088965 100644 --- a/openmp/runtime/test/worksharing/for/kmp_doacross_check.c +++ b/openmp/runtime/test/worksharing/for/kmp_doacross_check.c @@ -24,7 +24,7 @@ int main() dims.lo = 1; dims.up = N-1; dims.st = 1; - #pragma omp parallel + #pragma omp parallel num_threads(4) { int i, gtid; long long vec; -- cgit v1.1