Skip to content

Commit 78160c0

Browse files
author
Denis Chapligin
authored
Merge pull request #5813 from woltapp/tbbdeprecation
Partially fixes use of deprecated TBB features
2 parents a35961c + 933e361 commit 78160c0

File tree

18 files changed

+90
-34
lines changed

18 files changed

+90
-34
lines changed

include/updater/csv_file_parser.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <boost/spirit/include/phoenix.hpp>
1818
#include <boost/spirit/include/qi.hpp>
1919

20+
#include <exception>
21+
#include <stdexcept>
2022
#include <vector>
2123

2224
namespace osrm
@@ -80,7 +82,9 @@ template <typename Key, typename Value> struct CSVFilesParser
8082

8183
return LookupTable<Key, Value>{lookup};
8284
}
83-
catch (const tbb::captured_exception &e)
85+
catch (const std::exception &e)
86+
// TBB should capture to std::exception_ptr and automatically rethrow in this thread.
87+
// https://software.intel.com/en-us/node/506317
8488
{
8589
throw util::exception(e.what() + SOURCE_REF);
8690
}

src/contractor/contractor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,26 @@
3636

3737
#include <boost/assert.hpp>
3838

39+
#if TBB_VERSION_MAJOR == 2020
40+
#include <tbb/global_control.h>
41+
#else
3942
#include <tbb/task_scheduler_init.h>
43+
#endif
44+
4045
namespace osrm
4146
{
4247
namespace contractor
4348
{
4449

4550
int Contractor::Run()
4651
{
52+
#if TBB_VERSION_MAJOR == 2020
53+
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
54+
config.requested_num_threads);
55+
#else
4756
tbb::task_scheduler_init init(config.requested_num_threads);
4857
BOOST_ASSERT(init.is_active());
58+
#endif
4959

5060
if (config.core_factor != 1.0)
5161
{

src/customize/customizer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121

2222
#include <boost/assert.hpp>
2323

24+
#if TBB_VERSION_MAJOR == 2020
25+
#include <tbb/global_control.h>
26+
#else
2427
#include <tbb/task_scheduler_init.h>
28+
#endif
2529

2630
namespace osrm
2731
{
@@ -118,8 +122,13 @@ std::vector<CellMetric> customizeFilteredMetrics(const partitioner::MultiLevelEd
118122

119123
int Customizer::Run(const CustomizationConfig &config)
120124
{
125+
#if TBB_VERSION_MAJOR == 2020
126+
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
127+
config.requested_num_threads);
128+
#else
121129
tbb::task_scheduler_init init(config.requested_num_threads);
122130
BOOST_ASSERT(init.is_active());
131+
#endif
123132

124133
TIMER_START(loading_data);
125134

src/extractor/edge_based_graph_factory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
#include <limits>
3232
#include <sstream>
3333
#include <string>
34+
#include <thread>
3435
#include <tuple>
3536
#include <unordered_map>
3637

3738
#include <tbb/blocked_range.h>
3839
#include <tbb/parallel_for.h>
3940
#include <tbb/pipeline.h>
40-
#include <tbb/task_scheduler_init.h>
4141

4242
namespace std
4343
{
@@ -1080,7 +1080,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
10801080
// to be balanced with the GRAINSIZE above - ideally, the pipeline puts as much work
10811081
// as possible in the `intersection_handler` step so that those parallel workers don't
10821082
// get blocked too much by the slower (io-performing) `buffer_storage`
1083-
tbb::parallel_pipeline(tbb::task_scheduler_init::default_num_threads() * 5,
1083+
tbb::parallel_pipeline(std::thread::hardware_concurrency() * 5,
10841084
generator_stage & processor_stage & output_stage);
10851085

10861086
// NOTE: buffer.delayed_data and buffer.delayed_turn_data have the same index

src/extractor/extractor.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@
5555
#include <osmium/thread/pool.hpp>
5656
#include <osmium/visitor.hpp>
5757

58-
#include <tbb/pipeline.h>
58+
#if TBB_VERSION_MAJOR == 2020
59+
#include <tbb/global_control.h>
60+
#else
5961
#include <tbb/task_scheduler_init.h>
62+
#endif
63+
#include <tbb/pipeline.h>
6064

6165
#include <cstdlib>
6266

@@ -214,11 +218,16 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
214218
{
215219
util::LogPolicy::GetInstance().Unmute();
216220

217-
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
221+
const unsigned recommended_num_threads = std::thread::hardware_concurrency();
218222
const auto number_of_threads = std::min(recommended_num_threads, config.requested_num_threads);
219-
tbb::task_scheduler_init init(number_of_threads ? number_of_threads
220-
: tbb::task_scheduler_init::automatic);
223+
224+
#if TBB_VERSION_MAJOR == 2020
225+
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
226+
config.requested_num_threads);
227+
#else
228+
tbb::task_scheduler_init init(config.requested_num_threads);
221229
BOOST_ASSERT(init.is_active());
230+
#endif
222231

223232
LaneDescriptionMap turn_lane_map;
224233
std::vector<TurnRestriction> turn_restrictions;
@@ -604,7 +613,7 @@ Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment,
604613

605614
// Parse OSM elements with parallel transformer
606615
// Number of pipeline tokens that yielded the best speedup was about 1.5 * num_cores
607-
const auto num_threads = tbb::task_scheduler_init::default_num_threads() * 1.5;
616+
const auto num_threads = std::thread::hardware_concurrency() * 1.5;
608617
const auto read_meta =
609618
config.use_metadata ? osmium::io::read_meta::yes : osmium::io::read_meta::no;
610619

src/guidance/guidance_processing.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
#include <tbb/blocked_range.h>
1212
#include <tbb/pipeline.h>
13-
#include <tbb/task_scheduler_init.h>
13+
14+
#include <thread>
1415

1516
namespace osrm
1617
{
@@ -324,7 +325,7 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph,
324325
// to be balanced with the GRAINSIZE above - ideally, the pipeline puts as much work
325326
// as possible in the `intersection_handler` step so that those parallel workers don't
326327
// get blocked too much by the slower (io-performing) `buffer_storage`
327-
tbb::parallel_pipeline(tbb::task_scheduler_init::default_num_threads() * 5,
328+
tbb::parallel_pipeline(std::thread::hardware_concurrency() * 5,
328329
generator_stage & guidance_stage & guidance_output_stage);
329330

330331
// NOTE: EBG edges delayed_data and turns delayed_turn_data have the same index

src/partitioner/partitioner.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
#include <boost/assert.hpp>
2929
#include <boost/filesystem/operations.hpp>
3030

31+
#if TBB_VERSION_MAJOR == 2020
32+
#include <tbb/global_control.h>
33+
#else
3134
#include <tbb/task_scheduler_init.h>
35+
#endif
3236

3337
#include "util/geojson_debug_logger.hpp"
3438
#include "util/geojson_debug_policies.hpp"
@@ -70,8 +74,13 @@ auto getGraphBisection(const PartitionerConfig &config)
7074

7175
int Partitioner::Run(const PartitionerConfig &config)
7276
{
77+
#if TBB_VERSION_MAJOR == 2020
78+
tbb::global_control gc(tbb::global_control::max_allowed_parallelism,
79+
config.requested_num_threads);
80+
#else
7381
tbb::task_scheduler_init init(config.requested_num_threads);
7482
BOOST_ASSERT(init.is_active());
83+
#endif
7584

7685
const std::vector<BisectionID> &node_based_partition_ids = getGraphBisection(config);
7786

src/tools/contract.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
#include <boost/program_options.hpp>
1111
#include <boost/program_options/errors.hpp>
1212

13-
#include <tbb/task_scheduler_init.h>
14-
1513
#include <cstdlib>
1614
#include <exception>
1715
#include <new>
1816
#include <ostream>
17+
#include <thread>
1918

2019
#include "util/meminfo.hpp"
2120

@@ -45,7 +44,7 @@ return_code parseArguments(int argc,
4544
config_options.add_options()(
4645
"threads,t",
4746
boost::program_options::value<unsigned int>(&contractor_config.requested_num_threads)
48-
->default_value(tbb::task_scheduler_init::default_num_threads()),
47+
->default_value(std::thread::hardware_concurrency()),
4948
"Number of threads to use")(
5049
"core,k",
5150
boost::program_options::value<double>(&contractor_config.core_factor)->default_value(1.0),
@@ -171,7 +170,7 @@ int main(int argc, char *argv[]) try
171170
return EXIT_FAILURE;
172171
}
173172

174-
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
173+
const unsigned recommended_num_threads = std::thread::hardware_concurrency();
175174

176175
if (recommended_num_threads != contractor_config.requested_num_threads)
177176
{

src/tools/customize.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
#include "util/meminfo.hpp"
66
#include "util/version.hpp"
77

8-
#include <tbb/task_scheduler_init.h>
9-
108
#include <boost/filesystem.hpp>
119
#include <boost/program_options.hpp>
1210

1311
#include <iostream>
12+
#include <thread>
1413

1514
using namespace osrm;
1615

@@ -39,7 +38,7 @@ return_code parseArguments(int argc,
3938
//
4039
("threads,t",
4140
boost::program_options::value<unsigned int>(&customization_config.requested_num_threads)
42-
->default_value(tbb::task_scheduler_init::default_num_threads()),
41+
->default_value(std::thread::hardware_concurrency()),
4342
"Number of threads to use")(
4443
"segment-speed-file",
4544
boost::program_options::value<std::vector<std::string>>(

src/tools/extract.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
#include "util/log.hpp"
55
#include "util/version.hpp"
66

7-
#include <tbb/task_scheduler_init.h>
8-
97
#include <boost/filesystem.hpp>
108
#include <boost/program_options.hpp>
119

1210
#include <cstdlib>
1311
#include <exception>
1412
#include <new>
13+
#include <thread>
1514

1615
#include "util/meminfo.hpp"
1716

@@ -49,7 +48,7 @@ return_code parseArguments(int argc,
4948
"Data version. Leave blank to avoid. osmosis - to get timestamp from file")(
5049
"threads,t",
5150
boost::program_options::value<unsigned int>(&extractor_config.requested_num_threads)
52-
->default_value(tbb::task_scheduler_init::default_num_threads()),
51+
->default_value(std::thread::hardware_concurrency()),
5352
"Number of threads to use")(
5453
"small-component-size",
5554
boost::program_options::value<unsigned int>(&extractor_config.small_component_size)

0 commit comments

Comments
 (0)