diff options
author | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2017-05-31 20:33:56 +0000 |
---|---|---|
committer | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2017-05-31 20:33:56 +0000 |
commit | 9f5df8b02e27703b2f1febd51dac3450d6431345 (patch) | |
tree | 1ba8ea60dc3da11e407d67cf4597d14e40f9a4ee | |
parent | ac4beccaca713c8500afc8abb9630b8b38564e36 (diff) | |
download | llvm-9f5df8b02e27703b2f1febd51dac3450d6431345.zip llvm-9f5df8b02e27703b2f1febd51dac3450d6431345.tar.gz llvm-9f5df8b02e27703b2f1febd51dac3450d6431345.tar.bz2 |
Address default pinning OpenMP process with multiple processor groups
This change checks if the initial affinity mask is equal to exactly one
Windows processor group's affinity mask. If it is, then the code does not
respect the initial affinity mask and uses the entire machine instead.
The reasoning behind this is that, by default, Windows assigns exactly one
processor group as the initial affinity mask even when there are multiple
Windows processor groups available. User's typically want to use the whole
machine, so we ignore this special case and use the entire machine.
If the initial affinity mask is a proper subset of one group, or spans multiple
groups, then the initial affinity mask is respected since we can assume that the
operating system did not assign this initial affinity mask. This change only
affects machines with multiple processor groups
Differential Revision: https://reviews.llvm.org/D33210
llvm-svn: 304343
-rw-r--r-- | openmp/runtime/src/kmp_settings.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp index d8332a2..b282ffe 100644 --- a/openmp/runtime/src/kmp_settings.cpp +++ b/openmp/runtime/src/kmp_settings.cpp @@ -5063,6 +5063,33 @@ void __kmp_env_initialize(char const *string) { if (KMP_AFFINITY_CAPABLE()) { #if KMP_GROUP_AFFINITY + // This checks to see if the initial affinity mask is equal + // to a single windows processor group. If it is, then we do + // not respect the initial affinity mask and instead, use the + // entire machine. + bool exactly_one_group = false; + if (__kmp_num_proc_groups > 1) { + int group; + bool within_one_group; + // Get the initial affinity mask and determine if it is + // contained within a single group. + kmp_affin_mask_t *init_mask; + KMP_CPU_ALLOC(init_mask); + __kmp_get_system_affinity(init_mask, TRUE); + group = __kmp_get_proc_group(init_mask); + within_one_group = (group >= 0); + // If the initial affinity is within a single group, + // then determine if it is equal to that single group. + if (within_one_group) { + DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group); + int num_bits_in_mask = 0; + for (int bit = init_mask->begin(); bit != init_mask->end(); + bit = init_mask->next(bit)) + num_bits_in_mask++; + exactly_one_group = (num_bits_in_group == num_bits_in_mask); + } + KMP_CPU_FREE(init_mask); + } // Handle the Win 64 group affinity stuff if there are multiple // processor groups, or if the user requested it, and OMP 4.0 @@ -5073,7 +5100,8 @@ void __kmp_env_initialize(char const *string) { && (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default)) #endif || (__kmp_affinity_top_method == affinity_top_method_group)) { - if (__kmp_affinity_respect_mask == affinity_respect_mask_default) { + if (__kmp_affinity_respect_mask == affinity_respect_mask_default && + exactly_one_group) { __kmp_affinity_respect_mask = FALSE; } if (__kmp_affinity_type == affinity_default) { @@ -5150,7 +5178,7 @@ void __kmp_env_initialize(char const *string) { { if (__kmp_affinity_respect_mask == affinity_respect_mask_default) { #if KMP_GROUP_AFFINITY - if (__kmp_num_proc_groups > 1) { + if (__kmp_num_proc_groups > 1 && exactly_one_group) { __kmp_affinity_respect_mask = FALSE; } else #endif /* KMP_GROUP_AFFINITY */ |