Skip to content

Commit 2e37160

Browse files
committed
Using hardware_concurrency() to detect the number of threads for the pool (or 4 as fallback)
1 parent 41fd608 commit 2e37160

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/superviseddescent/superviseddescent.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ class SupervisedDescentOptimiser
150150
for (size_t regressorLevel = 0; regressorLevel < regressors.size(); ++regressorLevel) {
151151
// 1) Project current parameters x to feature space:
152152
// Enqueue all tasks in a thread pool:
153-
utils::ThreadPool threadPool(4);
153+
auto concurentThreadsSupported = std::thread::hardware_concurrency();
154+
if (concurentThreadsSupported == 0) {
155+
concurentThreadsSupported = 4;
156+
}
157+
utils::ThreadPool threadPool(concurentThreadsSupported);
154158
std::vector<std::future<typename std::result_of<H(Mat, size_t, int)>::type>> results; // will be float or Mat. I might remove float for the sake of code clarity, as it's only useful for very simple examples.
155159
results.reserve(currentX.rows);
156160
for (int sampleIndex = 0; sampleIndex < currentX.rows; ++sampleIndex) {

0 commit comments

Comments
 (0)