Skip to content

Commit

Permalink
[OpenMP] Fix potential division by 0
Browse files Browse the repository at this point in the history
This patch fixes potential division by 0 in case hwloc does not
recognize cores (or architecture has no cores).

Patch by Andrey Churbanov

Differential Revision: https://reviews.llvm.org/D90954
  • Loading branch information
nawrinsu committed Nov 6, 2020
1 parent c955989 commit 0820319
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openmp/runtime/src/kmp_affinity.cpp
Expand Up @@ -589,6 +589,8 @@ static int __kmp_affinity_create_hwloc_map(AddrUnsPair **address2os,
else
__kmp_nThreadsPerCore = 1; // no CORE found
__kmp_ncores = __kmp_xproc / __kmp_nThreadsPerCore;
if (nCoresPerPkg == 0)
nCoresPerPkg = 1; // to prevent possible division by 0
nPackages = (__kmp_xproc + nCoresPerPkg - 1) / nCoresPerPkg;
if (__kmp_affinity_verbose) {
KMP_INFORM(AffNotCapableUseLocCpuidL11, "KMP_AFFINITY");
Expand Down

0 comments on commit 0820319

Please sign in to comment.