[Openmp-commits] [openmp] r351227 - [OpenMP] Fix for nested proc_bind affinity bug
Jonathan Peyton via Openmp-commits
openmp-commits at lists.llvm.org
Tue Jan 15 11:39:32 PST 2019
Author: jlpeyton
Date: Tue Jan 15 11:39:32 2019
New Revision: 351227
URL: http://llvm.org/viewvc/llvm-project?rev=351227&view=rev
Log:
[OpenMP] Fix for nested proc_bind affinity bug
Using proc_bind clause on a nested #pragma omp parallel region
with KMP_AFFINITY set causes an assertion error. This assertion occurs because
the place-partition-var is not properly initialized in the nested master threads.
Trying to get an intuitive result with KMP_AFFINITY + proc_bind is difficult
because of how the KMP_AFFINITY gtid-to-place mapping occurs. This
patch creates an initial place list no matter what affinity mechanism is used.
For KMP_AFFINITY, the place-partition-var is initialized to all the places.
Differential Revision: https://reviews.llvm.org/D55795
Added:
openmp/trunk/runtime/test/affinity/bug-nested.c
Modified:
openmp/trunk/runtime/src/kmp_affinity.cpp
openmp/trunk/runtime/src/kmp_ftn_entry.h
Modified: openmp/trunk/runtime/src/kmp_affinity.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_affinity.cpp?rev=351227&r1=351226&r2=351227&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_affinity.cpp (original)
+++ openmp/trunk/runtime/src/kmp_affinity.cpp Tue Jan 15 11:39:32 2019
@@ -4505,6 +4505,7 @@ static void __kmp_aux_affinity_initializ
KMP_WARNING(AffNoValidProcID);
}
__kmp_affinity_type = affinity_none;
+ __kmp_create_affinity_none_places();
return;
}
break;
@@ -4557,11 +4558,9 @@ static void __kmp_aux_affinity_initializ
KMP_WARNING(AffBalancedNotAvail, "KMP_AFFINITY");
}
__kmp_affinity_type = affinity_none;
+ __kmp_create_affinity_none_places();
return;
- } else if (__kmp_affinity_uniform_topology()) {
- break;
- } else { // Non-uniform topology
-
+ } else if (!__kmp_affinity_uniform_topology()) {
// Save the depth for further usage
__kmp_aff_depth = depth;
@@ -4602,8 +4601,9 @@ static void __kmp_aux_affinity_initializ
procarr[core * maxprocpercore + inlastcore] = proc;
}
-
- break;
+ }
+ if (__kmp_affinity_compact >= depth) {
+ __kmp_affinity_compact = depth - 1;
}
sortAddresses:
@@ -4781,6 +4781,11 @@ void __kmp_affinity_set_init_mask(int gt
th->th.th_new_place = i;
th->th.th_first_place = 0;
th->th.th_last_place = __kmp_affinity_num_masks - 1;
+ } else if (KMP_AFFINITY_NON_PROC_BIND) {
+ // When using a Non-OMP_PROC_BIND affinity method,
+ // set all threads' place-partition-var to the entire place list
+ th->th.th_first_place = 0;
+ th->th.th_last_place = __kmp_affinity_num_masks - 1;
}
if (i == KMP_PLACE_ALL) {
Modified: openmp/trunk/runtime/src/kmp_ftn_entry.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_ftn_entry.h?rev=351227&r1=351226&r2=351227&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_ftn_entry.h (original)
+++ openmp/trunk/runtime/src/kmp_ftn_entry.h Tue Jan 15 11:39:32 2019
@@ -858,9 +858,6 @@ int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_
}
if (!KMP_AFFINITY_CAPABLE())
return 0;
- if (KMP_AFFINITY_NON_PROC_BIND) {
- return 1;
- }
gtid = __kmp_entry_gtid();
thread = __kmp_thread_from_gtid(gtid);
first_place = thread->th.th_first_place;
@@ -889,10 +886,6 @@ void
return;
gtid = __kmp_entry_gtid();
thread = __kmp_thread_from_gtid(gtid);
- if (KMP_AFFINITY_NON_PROC_BIND) {
- place_nums[0] = thread->th.th_current_place;
- return;
- }
first_place = thread->th.th_first_place;
last_place = thread->th.th_last_place;
if (first_place < 0 || last_place < 0)
Added: openmp/trunk/runtime/test/affinity/bug-nested.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/test/affinity/bug-nested.c?rev=351227&view=auto
==============================================================================
--- openmp/trunk/runtime/test/affinity/bug-nested.c (added)
+++ openmp/trunk/runtime/test/affinity/bug-nested.c Tue Jan 15 11:39:32 2019
@@ -0,0 +1,33 @@
+// RUN: %libomp-compile && env KMP_AFFINITY=compact %libomp-run
+// REQUIRES: openmp-4.0
+
+#include <stdio.h>
+#include <stdint.h>
+#include <omp.h>
+#include "omp_testsuite.h"
+
+int test_nested_affinity_bug() {
+ int a = 0;
+ omp_set_nested(1);
+ #pragma omp parallel num_threads(2) shared(a)
+ {
+ #pragma omp parallel num_threads(2) shared(a) proc_bind(close)
+ {
+ #pragma omp atomic
+ a++;
+ }
+ }
+ return 1;
+}
+
+int main() {
+ int i;
+ int num_failed = 0;
+
+ for (i = 0; i < REPETITIONS; i++) {
+ if (!test_nested_affinity_bug()) {
+ num_failed++;
+ }
+ }
+ return num_failed;
+}
More information about the Openmp-commits
mailing list