This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: omp_get_num_procs() not working on macintosh?



If so, someone familiar with Darwin needs to provide (a tested) darwin specific
proc.c implementation which can be added to libgomp/config/darwin/proc.c
to replace the libgomp/config/posix/proc.c version.

Here is code that does so:


  #include <sys/types.h>
  #include <sys/sysctl.h>

  int main()
  {
    int mib[2] = { CTL_HW, HW_AVAILCPU };
    int result, len;
    len = sizeof (result);
    sysctl (mib, 2, &result, &len, NULL, 0);
    printf ("%d\n", result);
  }

If you need to retrieve the number of processors in the system (i.e. the upper bound to HW_AVAILCPU, because the latter may change if a different power management modes is activated), you should use HW_NCPU instead.

Paolo


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]