From 7b2ca53f3f65e84d9dbe77f3bf673a31f1eecc15 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sat, 2 Nov 2013 16:39:59 +0100 Subject: [PATCH] Added function to calculate the number threads from the number of cores. This function is a cubic spline that resembles the current benchmarking results. --- src/Config.h | 2 +- src/Thread_Initialization.cpp | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Config.h b/src/Config.h index fa4e6f72..4af7be98 100644 --- a/src/Config.h +++ b/src/Config.h @@ -35,7 +35,7 @@ #define VER_LAMEXP_MINOR_LO 9 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 7 -#define VER_LAMEXP_BUILD 1449 +#define VER_LAMEXP_BUILD 1450 #define VER_LAMEXP_CONFG 1348 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index f4ace8e6..0912e276 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -50,6 +50,33 @@ static const size_t EXPECTED_TOOL_COUNT = 27; /* benchmark */ #undef ENABLE_BENCHMARK +/* number of CPU cores -> number of threads */ +static unsigned int cores2threads(const unsigned int cores) +{ + static const size_t LUT_LEN = 4; + + static const struct + { + const unsigned int upperBound; + const double coeffs[4]; + } + LUT[LUT_LEN] = + { + { 4, { -0.052695810565, 0.158087431694, 4.982841530055, -1.088233151184 } }, + { 8, { 0.042431693989, -0.983442622951, 9.548961748634, -7.176393442623 } }, + { 12, { -0.006277322404, 0.185573770492, 0.196830601093, 17.762622950820 } }, + { 32, { 0.000673497268, -0.064655737705, 3.199584699454, 5.751606557377 } } + }; + + size_t index = 0; + while((cores > LUT[index].upperBound) && (index < (LUT_LEN-1))) index++; + + const double x = qBound(1.0, double(cores), double(LUT[LUT_LEN-1].upperBound)); + const double y = (LUT[index].coeffs[0] * pow(x, 3.0)) + (LUT[index].coeffs[1] * pow(x, 2.0)) + (LUT[index].coeffs[2] * x) + LUT[index].coeffs[3]; + + return qRound(abs(y)); +} + //////////////////////////////////////////////////////////// // ExtractorTask class //////////////////////////////////////////////////////////// @@ -286,8 +313,9 @@ double InitializationThread::doInit(const size_t threadCount) QDir appDir = QDir(QCoreApplication::applicationDirPath()).canonicalPath(); QThreadPool *pool = new QThreadPool(); - pool->setMaxThreadCount((threadCount > 0) ? threadCount : qBound(2U, (m_cpuFeatures.count * 3U), EXPECTED_TOOL_COUNT)); - + pool->setMaxThreadCount((threadCount > 0) ? threadCount : qBound(2U, cores2threads(m_cpuFeatures.count), EXPECTED_TOOL_COUNT)); + //qWarning("Using %u threads for extraction.", pool->maxThreadCount()); + LockedFile::selfTest(); ExtractorTask::clearFlags(); -- 2.11.4.GIT