SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
MultiThreadingConfig.cpp
Go to the documentation of this file.
1
17/*
18 * MultiThreadingConfig.cpp
19 *
20 * Created on: May 22, 2018
21 * Author: mschefer
22 */
23
24#include <boost/thread.hpp>
25
27
28using namespace Euclid::Configuration;
29namespace po = boost::program_options;
30
31namespace SourceXtractor {
32
33static const std::string THREADS_NB {"thread-count"};
34static const std::string MAX_QUEUE_SIZE {"thread-max-queue-size"};
35
36MultiThreadingConfig::MultiThreadingConfig(long manager_id) : Configuration(manager_id), m_threads_nb(-1), m_max_queue_size(1000) {}
37
39 return { {"Multi-threading", {
40 {THREADS_NB.c_str(), po::value<int>()->default_value(-1), "Number of worker threads (-1=automatic, 0=disable all multithreading)"},
41 {MAX_QUEUE_SIZE.c_str(), po::value<int>()->default_value(1000), "Limit the size of the internal queues"}
42 }}};
43}
44
46 m_threads_nb = args.at(THREADS_NB).as<int>();
47 if (m_threads_nb == -1) {
48 m_threads_nb = boost::thread::hardware_concurrency();
49 }
50 else if (m_threads_nb < -1) {
51 throw Elements::Exception("Invalid number of threads.");
52 }
53 if (m_threads_nb > 0) {
55 }
56
57 m_max_queue_size = args.at(MAX_QUEUE_SIZE).as<int>();
58 if (m_max_queue_size <= 0) {
59 throw Elements::Exception(MAX_QUEUE_SIZE + " must be strictly positive");
60 }
61}
62
63} // SourceXtractor namespace
64
std::map< std::string, OptionDescriptionList > getProgramOptions() override
void initialize(const UserValues &args) override
std::shared_ptr< Euclid::ThreadPool > m_thread_pool
static const std::string MAX_QUEUE_SIZE
static const std::string THREADS_NB