From 6751f7b9a793e9080396b1fec1739953017e3b8c Mon Sep 17 00:00:00 2001 From: Zhang Xianyi Date: Tue, 13 Nov 2012 15:48:57 +0800 Subject: [PATCH] Fixed #157. Only detect the number of physical CPU cores on Mac OSX. --- driver/others/memory.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/driver/others/memory.c b/driver/others/memory.c index d897fe7e0..2070adf5d 100644 --- a/driver/others/memory.c +++ b/driver/others/memory.c @@ -185,7 +185,7 @@ int get_num_procs(void) { #endif -#if defined(OS_FREEBSD) || defined(OS_DARWIN) +#if defined(OS_FREEBSD) int get_num_procs(void) { @@ -206,6 +206,18 @@ int get_num_procs(void) { #endif +#if defined(OS_DARWIN) +int get_num_procs(void) { + static int nums = 0; + size_t len; + if (nums == 0){ + len = sizeof(int); + sysctlbyname("hw.physicalcpu", &nums, &len, NULL, 0); + } + return nums; +} +#endif + /* OpenBLAS uses the numbers of CPU cores in multithreading. It can be set by openblas_set_num_threads(int num_threads);