SourceXtractorPlusPlus  0.15
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
28 using namespace Euclid::Configuration;
29 namespace po = boost::program_options;
30 
31 namespace SourceXtractor {
32 
33 static const std::string THREADS_NB {"thread-count"};
34 
35 MultiThreadingConfig::MultiThreadingConfig(long manager_id) : Configuration(manager_id), m_threads_nb(-1) {
36 }
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  }}};
42 }
43 
44 void MultiThreadingConfig::initialize(const UserValues& args) {
45  m_threads_nb = args.at(THREADS_NB).as<int>();
46  if (m_threads_nb == -1) {
47  m_threads_nb = boost::thread::hardware_concurrency();
48  }
49  else if (m_threads_nb < -1) {
50  throw Elements::Exception("Invalid number of threads.");
51  }
52  if (m_threads_nb > 0) {
53  m_thread_pool = std::make_shared<Euclid::ThreadPool>(m_threads_nb);
54  }
55 }
56 
57 } // SourceXtractor namespace
58 
void initialize(const UserValues &args) override
static const std::string THREADS_NB
STL class.
STL class.
std::shared_ptr< Euclid::ThreadPool > m_thread_pool
T c_str(T...args)
std::map< std::string, OptionDescriptionList > getProgramOptions() override