From 7053d97d2d627c1f2bbd019953748b09af99c1e2 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 18 Jul 2018 22:32:44 +0200 Subject: [PATCH] s/xbt_os_get_numcores()/std::thread::hardware_concurrency()/ --- include/xbt/xbt_os_thread.h | 2 -- src/simix/smx_context.cpp | 16 ++++++++-------- src/xbt/xbt_os_thread.c | 25 ------------------------- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/include/xbt/xbt_os_thread.h b/include/xbt/xbt_os_thread.h index e1591c7f97..d555995c1a 100644 --- a/include/xbt/xbt_os_thread.h +++ b/include/xbt/xbt_os_thread.h @@ -24,8 +24,6 @@ SG_BEGIN_DECL() * @{ */ -XBT_PUBLIC int xbt_os_get_numcores(void); - /** @brief Thread data type (opaque structure) */ typedef struct xbt_os_thread_ *xbt_os_thread_t; XBT_PUBLIC xbt_os_thread_t xbt_os_thread_create(const char* name, pvoid_f_pvoid_t start_routine, void* param, diff --git a/src/simix/smx_context.cpp b/src/simix/smx_context.cpp index 4fb8c473ab..5dbbfb2900 100644 --- a/src/simix/smx_context.cpp +++ b/src/simix/smx_context.cpp @@ -5,12 +5,6 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include -#include - -#include -#include - #include #include #include @@ -23,6 +17,12 @@ #include "xbt/log.h" #include "xbt/xbt_os_thread.h" +#include +#include +#include +#include +#include + #ifdef _WIN32 #include #include @@ -259,8 +259,8 @@ int SIMIX_context_get_nthreads() { */ void SIMIX_context_set_nthreads(int nb_threads) { if (nb_threads<=0) { - nb_threads = xbt_os_get_numcores(); - XBT_INFO("Auto-setting contexts/nthreads to %d",nb_threads); + nb_threads = std::thread::hardware_concurrency(); + XBT_INFO("Auto-setting contexts/nthreads to %d", nb_threads); } #if !HAVE_THREAD_CONTEXTS xbt_assert(nb_threads == 1, "Parallel runs are impossible when the pthreads are missing."); diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index 79242cdf5a..d4515ad27a 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -366,31 +366,6 @@ void xbt_os_sem_destroy(xbt_os_sem_t sem) xbt_free(sem); } -/** @brief Returns the amount of cores on the current host */ -int xbt_os_get_numcores(void) { -#ifdef WIN32 - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; -#elif defined(__APPLE__) && defined(__MACH__) - int nm[2]; - size_t len = 4; - uint32_t count; - - nm[0] = CTL_HW; nm[1] = HW_AVAILCPU; - sysctl(nm, 2, &count, &len, NULL, 0); - - if(count < 1) { - nm[1] = HW_NCPU; - sysctl(nm, 2, &count, &len, NULL, 0); - if(count < 1) { count = 1; } - } - return count; -#else - return sysconf(_SC_NPROCESSORS_ONLN); -#endif -} - void xbt_os_thread_set_extra_data(void *data) { xbt_os_thread_self()->extra_data = data; -- 2.20.1