SourceXtractorPlusPlus
0.16
Please provide a description of the project.
SEImplementation
src
lib
Configuration
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
26
#include "
SEImplementation/Configuration/MultiThreadingConfig.h
"
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
static
const
std::string
MAX_QUEUE_SIZE
{
"thread-max-queue-size"
};
35
36
MultiThreadingConfig::MultiThreadingConfig(
long
manager_id) :
Configuration
(manager_id), m_threads_nb(-1), m_max_queue_size(1000) {}
37
38
auto
MultiThreadingConfig::getProgramOptions
() ->
std::map<std::string, OptionDescriptionList>
{
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
45
void
MultiThreadingConfig::initialize
(
const
UserValues
& args) {
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) {
54
m_thread_pool
= std::make_shared<Euclid::ThreadPool>(
m_threads_nb
);
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
MultiThreadingConfig.h
std::map::at
T at(T... args)
std::string
std::string::c_str
T c_str(T... args)
Elements::Exception
Euclid::Configuration::Configuration
SourceXtractor::MultiThreadingConfig::getProgramOptions
std::map< std::string, OptionDescriptionList > getProgramOptions() override
Definition:
MultiThreadingConfig.cpp:38
SourceXtractor::MultiThreadingConfig::initialize
void initialize(const UserValues &args) override
Definition:
MultiThreadingConfig.cpp:45
SourceXtractor::MultiThreadingConfig::m_thread_pool
std::shared_ptr< Euclid::ThreadPool > m_thread_pool
Definition:
MultiThreadingConfig.h:56
SourceXtractor::MultiThreadingConfig::m_threads_nb
int m_threads_nb
Definition:
MultiThreadingConfig.h:55
SourceXtractor::MultiThreadingConfig::m_max_queue_size
int m_max_queue_size
Definition:
MultiThreadingConfig.h:55
std::map
Euclid::Configuration
SourceXtractor
Definition:
Aperture.h:30
SourceXtractor::MAX_QUEUE_SIZE
static const std::string MAX_QUEUE_SIZE
Definition:
MultiThreadingConfig.cpp:34
SourceXtractor::THREADS_NB
static const std::string THREADS_NB
Definition:
MultiThreadingConfig.cpp:33
Generated by
1.9.1