Deprecated tbb::task_scheduler_init replaced with std::thread and tbb::global_control

This commit is contained in:
Denis Chaplygin
2020-09-01 14:25:51 +03:00
parent 4d6272b030
commit 03d9e7a8ce
17 changed files with 85 additions and 33 deletions
+10
View File
@@ -36,7 +36,12 @@
#include <boost/assert.hpp>
#if TBB_VERSION_MAJOR == 2020
#include <tbb/global_control.h>
#else
#include <tbb/task_scheduler_init.h>
#endif
namespace osrm
{
namespace contractor
@@ -44,8 +49,13 @@ namespace contractor
int Contractor::Run()
{
#if TBB_VERSION_MAJOR == 2020
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
config.requested_num_threads);
#else
tbb::task_scheduler_init init(config.requested_num_threads);
BOOST_ASSERT(init.is_active());
#endif
if (config.core_factor != 1.0)
{
+9
View File
@@ -21,7 +21,11 @@
#include <boost/assert.hpp>
#if TBB_VERSION_MAJOR == 2020
#include <tbb/global_control.h>
#else
#include <tbb/task_scheduler_init.h>
#endif
namespace osrm
{
@@ -118,8 +122,13 @@ std::vector<CellMetric> customizeFilteredMetrics(const partitioner::MultiLevelEd
int Customizer::Run(const CustomizationConfig &config)
{
#if TBB_VERSION_MAJOR == 2020
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
config.requested_num_threads);
#else
tbb::task_scheduler_init init(config.requested_num_threads);
BOOST_ASSERT(init.is_active());
#endif
TIMER_START(loading_data);
+2 -2
View File
@@ -31,13 +31,13 @@
#include <limits>
#include <sstream>
#include <string>
#include <thread>
#include <tuple>
#include <unordered_map>
#include <tbb/blocked_range.h>
#include <tbb/parallel_for.h>
#include <tbb/pipeline.h>
#include <tbb/task_scheduler_init.h>
namespace std
{
@@ -1080,7 +1080,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
// to be balanced with the GRAINSIZE above - ideally, the pipeline puts as much work
// as possible in the `intersection_handler` step so that those parallel workers don't
// get blocked too much by the slower (io-performing) `buffer_storage`
tbb::parallel_pipeline(tbb::task_scheduler_init::default_num_threads() * 5,
tbb::parallel_pipeline(std::thread::hardware_concurrency() * 5,
generator_stage & processor_stage & output_stage);
// NOTE: buffer.delayed_data and buffer.delayed_turn_data have the same index
+14 -5
View File
@@ -55,8 +55,12 @@
#include <osmium/thread/pool.hpp>
#include <osmium/visitor.hpp>
#include <tbb/pipeline.h>
#if TBB_VERSION_MAJOR == 2020
#include <tbb/global_control.h>
#else
#include <tbb/task_scheduler_init.h>
#endif
#include <tbb/pipeline.h>
#include <cstdlib>
@@ -214,11 +218,16 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
{
util::LogPolicy::GetInstance().Unmute();
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
const unsigned recommended_num_threads = std::thread::hardware_concurrency();
const auto number_of_threads = std::min(recommended_num_threads, config.requested_num_threads);
tbb::task_scheduler_init init(number_of_threads ? number_of_threads
: tbb::task_scheduler_init::automatic);
#if TBB_VERSION_MAJOR == 2020
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
config.requested_num_threads);
#else
tbb::task_scheduler_init init(config.requested_num_threads);
BOOST_ASSERT(init.is_active());
#endif
LaneDescriptionMap turn_lane_map;
std::vector<TurnRestriction> turn_restrictions;
@@ -604,7 +613,7 @@ Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment,
// Parse OSM elements with parallel transformer
// Number of pipeline tokens that yielded the best speedup was about 1.5 * num_cores
const auto num_threads = tbb::task_scheduler_init::default_num_threads() * 1.5;
const auto num_threads = std::thread::hardware_concurrency() * 1.5;
const auto read_meta =
config.use_metadata ? osmium::io::read_meta::yes : osmium::io::read_meta::no;
+3 -2
View File
@@ -10,7 +10,8 @@
#include <tbb/blocked_range.h>
#include <tbb/pipeline.h>
#include <tbb/task_scheduler_init.h>
#include <thread>
namespace osrm
{
@@ -324,7 +325,7 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph,
// to be balanced with the GRAINSIZE above - ideally, the pipeline puts as much work
// as possible in the `intersection_handler` step so that those parallel workers don't
// get blocked too much by the slower (io-performing) `buffer_storage`
tbb::parallel_pipeline(tbb::task_scheduler_init::default_num_threads() * 5,
tbb::parallel_pipeline(std::thread::hardware_concurrency() * 5,
generator_stage & guidance_stage & guidance_output_stage);
// NOTE: EBG edges delayed_data and turns delayed_turn_data have the same index
+9
View File
@@ -28,7 +28,11 @@
#include <boost/assert.hpp>
#include <boost/filesystem/operations.hpp>
#if TBB_VERSION_MAJOR == 2020
#include <tbb/global_control.h>
#else
#include <tbb/task_scheduler_init.h>
#endif
#include "util/geojson_debug_logger.hpp"
#include "util/geojson_debug_policies.hpp"
@@ -70,8 +74,13 @@ auto getGraphBisection(const PartitionerConfig &config)
int Partitioner::Run(const PartitionerConfig &config)
{
#if TBB_VERSION_MAJOR == 2020
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
config.requested_num_threads);
#else
tbb::task_scheduler_init init(config.requested_num_threads);
BOOST_ASSERT(init.is_active());
#endif
const std::vector<BisectionID> &node_based_partition_ids = getGraphBisection(config);
+3 -4
View File
@@ -10,12 +10,11 @@
#include <boost/program_options.hpp>
#include <boost/program_options/errors.hpp>
#include <tbb/task_scheduler_init.h>
#include <cstdlib>
#include <exception>
#include <new>
#include <ostream>
#include <thread>
#include "util/meminfo.hpp"
@@ -45,7 +44,7 @@ return_code parseArguments(int argc,
config_options.add_options()(
"threads,t",
boost::program_options::value<unsigned int>(&contractor_config.requested_num_threads)
->default_value(tbb::task_scheduler_init::default_num_threads()),
->default_value(std::thread::hardware_concurrency()),
"Number of threads to use")(
"core,k",
boost::program_options::value<double>(&contractor_config.core_factor)->default_value(1.0),
@@ -171,7 +170,7 @@ int main(int argc, char *argv[]) try
return EXIT_FAILURE;
}
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
const unsigned recommended_num_threads = std::thread::hardware_concurrency();
if (recommended_num_threads != contractor_config.requested_num_threads)
{
+2 -3
View File
@@ -5,12 +5,11 @@
#include "util/meminfo.hpp"
#include "util/version.hpp"
#include <tbb/task_scheduler_init.h>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <iostream>
#include <thread>
using namespace osrm;
@@ -39,7 +38,7 @@ return_code parseArguments(int argc,
//
("threads,t",
boost::program_options::value<unsigned int>(&customization_config.requested_num_threads)
->default_value(tbb::task_scheduler_init::default_num_threads()),
->default_value(std::thread::hardware_concurrency()),
"Number of threads to use")(
"segment-speed-file",
boost::program_options::value<std::vector<std::string>>(
+2 -3
View File
@@ -4,14 +4,13 @@
#include "util/log.hpp"
#include "util/version.hpp"
#include <tbb/task_scheduler_init.h>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <cstdlib>
#include <exception>
#include <new>
#include <thread>
#include "util/meminfo.hpp"
@@ -49,7 +48,7 @@ return_code parseArguments(int argc,
"Data version. Leave blank to avoid. osmosis - to get timestamp from file")(
"threads,t",
boost::program_options::value<unsigned int>(&extractor_config.requested_num_threads)
->default_value(tbb::task_scheduler_init::default_num_threads()),
->default_value(std::thread::hardware_concurrency()),
"Number of threads to use")(
"small-component-size",
boost::program_options::value<unsigned int>(&extractor_config.small_component_size)
+2 -3
View File
@@ -7,8 +7,6 @@
#include "util/timing_util.hpp"
#include "util/version.hpp"
#include <tbb/task_scheduler_init.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
@@ -17,6 +15,7 @@
#include <iostream>
#include <iterator>
#include <regex>
#include <thread>
using namespace osrm;
@@ -86,7 +85,7 @@ return_code parseArguments(int argc,
//
("threads,t",
boost::program_options::value<unsigned int>(&config.requested_num_threads)
->default_value(tbb::task_scheduler_init::default_num_threads()),
->default_value(std::thread::hardware_concurrency()),
"Number of threads to use")
//
("balance",