https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86146

            Bug ID: 86146
           Summary: OpenMP not seeing more than 64 cores on Windows
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
          Assignee: unassigned at gcc dot gnu.org
          Reporter: karolina1980 at realemail dot net
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

Created attachment 44273
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44273&action=edit
Support Systems That Have More Than 64 Processors

Libgomp can't see more than 64 processors on Windows. Sample program:

#include <stdio.h>
#include <omp.h>

int main(void) {
    printf("number of CPUs: %d\n", omp_get_num_procs());
    return 0;
}

command line:
gcc -fopenmp -test_cpu.c -o test_cpu


This is relevant for dual CPU systems which have more than 64 logical
processors total. I've looked into libgomp implementation, proc.c file contains
this:

static unsigned int
count_avail_process_cpus ()
{
  DWORD_PTR process_cpus;
  DWORD_PTR system_cpus;

  if (GetProcessAffinityMask (GetCurrentProcess (),
                              &process_cpus, &system_cpus))
    {
      unsigned int count;
      for (count = 0; process_cpus != 0; process_cpus >>= 1)  
        if (process_cpus & 1)
          count++;
      return count;
    }
  return 1;
}

This is sadly incorrect way to count CPUs on Windows. As GetProcessAffinityMask
gets mask only for current processor group not all CPUs on the system.

See:
https://blogs.technet.microsoft.com/hardtofind/2018/01/29/windows-server-with-more-than-64-logical-processors/

https://msdn.microsoft.com/en-us/library/dd405527(VS.85).aspx

(also see attachment which contains explanation from Microsoft)

Clang 5.0.2 does counting correctly. It's done in kmp_affinity.cpp in Clang
source. Function:
void __kmp_affinity_entire_machine_mask(kmp_affin_mask_t *mask)

Sadly it seems omp is no longer included in Clang for Windows in 6.0.
I have no experience working on gcc or openmp. I am unable to diagnose how many
other functions need to be re-written to support more than 64 CPUs.

Reply via email to