17 |
#endif |
#endif |
18 |
#include <errno.h> |
#include <errno.h> |
19 |
|
|
20 |
/*! \brief determine the number of CPUs */ |
/*! \brief determine the number of CPUs |
21 |
bool GetNumCPUs (CPUInfo_t *info) |
* \return true if there is an error, false otherwise. |
22 |
|
*/ |
23 |
|
bool Diderot_GetNumCPUs (CPUInfo_t *info) |
24 |
{ |
{ |
25 |
#if defined(HAVE__PROC_CPUINFO) |
#if defined(HAVE__PROC_CPUINFO) |
26 |
/* Get information from /proc/cpuinfo. The interesting |
/* Get information from /proc/cpuinfo. The interesting |
65 |
info->numThdsPerCore = info->numHWThreads / info->numHWCores; |
info->numThdsPerCore = info->numHWThreads / info->numHWCores; |
66 |
#endif |
#endif |
67 |
|
|
68 |
return true; |
return false; |
69 |
} |
} |
70 |
else { |
else { |
71 |
fprintf(stderr, "unable to determine the number of processors\n"); |
fprintf(stderr, "unable to determine the number of processors\n"); |
72 |
return false; |
return true; |
73 |
} |
} |
74 |
#elif defined(__APPLE__) |
#elif defined(__APPLE__) |
75 |
size_t len = sizeof(int); |
size_t len = sizeof(int); |
82 |
} |
} |
83 |
else { |
else { |
84 |
fprintf(stderr, "unable to determine the number of nodes\n"); |
fprintf(stderr, "unable to determine the number of nodes\n"); |
85 |
return false; |
return true; |
86 |
} |
} |
87 |
} |
} |
88 |
|
|
89 |
/* the number of cores */ |
/* the number of cores */ |
90 |
if (sysctlbyname("hw.physicalcpu", &(info->numHWCores), &len, 0, 0) < 0) { |
if (sysctlbyname("hw.physicalcpu", &(info->numHWCores), &len, 0, 0) < 0) { |
91 |
fprintf(stderr, "unable to determine the number of physical CPUs\n"); |
fprintf(stderr, "unable to determine the number of physical CPUs\n"); |
92 |
return false; |
return true; |
93 |
} |
} |
94 |
|
|
95 |
/* the number of hardware threads */ |
/* the number of hardware threads */ |
100 |
} |
} |
101 |
else { |
else { |
102 |
fprintf(stderr, "unable to determine the number of logical CPUs\n"); |
fprintf(stderr, "unable to determine the number of logical CPUs\n"); |
103 |
return false; |
return true; |
104 |
} |
} |
105 |
} |
} |
106 |
|
|
107 |
info->numCoresPerNode = info->numHWCores / info->numHWNodes; |
info->numCoresPerNode = info->numHWCores / info->numHWNodes; |
108 |
info->numThdsPerCore = info->numHWThreads / info->numHWCores; |
info->numThdsPerCore = info->numHWThreads / info->numHWCores; |
109 |
|
|
|
return true; |
|
|
#else |
|
110 |
return false; |
return false; |
111 |
|
#else |
112 |
|
return true; |
113 |
#endif |
#endif |
114 |
|
|
115 |
} /* end of GetNumCPUs */ |
} /* end of GetNumCPUs */ |