Parallelize generation of the edge-expanded-edges.
This commit is contained in:
committed by
Patrick Niklaus
parent
b68d79407e
commit
35550d8c0a
@@ -18,6 +18,7 @@
|
||||
#include "extractor/query_node.hpp"
|
||||
#include "extractor/restriction_map.hpp"
|
||||
|
||||
#include "util/concurrent_id_map.hpp"
|
||||
#include "util/deallocating_vector.hpp"
|
||||
#include "util/guidance/bearing_class.hpp"
|
||||
#include "util/guidance/entry_class.hpp"
|
||||
@@ -41,6 +42,9 @@
|
||||
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#include <tbb/concurrent_unordered_map.h>
|
||||
#include <tbb/concurrent_vector.h>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
@@ -167,9 +171,9 @@ class EdgeBasedGraphFactory
|
||||
std::size_t skipped_uturns_counter;
|
||||
std::size_t skipped_barrier_turns_counter;
|
||||
|
||||
std::unordered_map<util::guidance::BearingClass, BearingClassID> bearing_class_hash;
|
||||
util::ConcurrentIDMap<util::guidance::BearingClass, BearingClassID> bearing_class_hash;
|
||||
std::vector<BearingClassID> bearing_class_by_node_based_node;
|
||||
std::unordered_map<util::guidance::EntryClass, EntryClassID> entry_class_hash;
|
||||
util::ConcurrentIDMap<util::guidance::EntryClass, EntryClassID> entry_class_hash;
|
||||
};
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
@@ -65,12 +65,16 @@ const constexpr char *scenario_names[] = {"Simple",
|
||||
|
||||
class TurnLaneHandler
|
||||
{
|
||||
using UpgradableMutex = boost::interprocess::interprocess_upgradable_mutex;
|
||||
using ScopedReaderLock = boost::interprocess::sharable_lock<UpgradableMutex>;
|
||||
using ScopedWriterLock = boost::interprocess::scoped_lock<UpgradableMutex>;
|
||||
|
||||
public:
|
||||
typedef std::vector<TurnLaneData> LaneDataVector;
|
||||
|
||||
TurnLaneHandler(const util::NodeBasedDynamicGraph &node_based_graph,
|
||||
std::vector<std::uint32_t> &turn_lane_offsets,
|
||||
std::vector<TurnLaneType::Mask> &turn_lane_masks,
|
||||
const std::vector<std::uint32_t> &turn_lane_offsets,
|
||||
const std::vector<TurnLaneType::Mask> &turn_lane_masks,
|
||||
LaneDescriptionMap &lane_description_map,
|
||||
const TurnAnalysis &turn_analysis,
|
||||
util::guidance::LaneDataIdMap &id_map);
|
||||
@@ -86,8 +90,8 @@ class TurnLaneHandler
|
||||
// we need to be able to look at previous intersections to, in some cases, find the correct turn
|
||||
// lanes for a turn
|
||||
const util::NodeBasedDynamicGraph &node_based_graph;
|
||||
std::vector<std::uint32_t> &turn_lane_offsets;
|
||||
std::vector<TurnLaneType::Mask> &turn_lane_masks;
|
||||
const std::vector<std::uint32_t> &turn_lane_offsets;
|
||||
const std::vector<TurnLaneType::Mask> &turn_lane_masks;
|
||||
LaneDescriptionMap &lane_description_map;
|
||||
const TurnAnalysis &turn_analysis;
|
||||
util::guidance::LaneDataIdMap &id_map;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include "util/concurrent_id_map.hpp"
|
||||
#include "util/json_container.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
@@ -93,9 +94,9 @@ struct TurnLaneDescription_hash
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::unordered_map<guidance::TurnLaneDescription,
|
||||
LaneDescriptionID,
|
||||
guidance::TurnLaneDescription_hash>
|
||||
typedef util::ConcurrentIDMap<guidance::TurnLaneDescription,
|
||||
LaneDescriptionID,
|
||||
guidance::TurnLaneDescription_hash>
|
||||
LaneDescriptionMap;
|
||||
|
||||
} // guidance
|
||||
|
||||
@@ -31,6 +31,15 @@ void write(storage::io::FileWriter &writer,
|
||||
const detail::TurnDataContainerImpl<Ownership> &turn_data);
|
||||
}
|
||||
|
||||
struct TurnData
|
||||
{
|
||||
extractor::guidance::TurnInstruction turn_instruction;
|
||||
LaneDataID lane_data_id;
|
||||
EntryClassID entry_class_id;
|
||||
util::guidance::TurnBearing pre_turn_bearing;
|
||||
util::guidance::TurnBearing post_turn_bearing;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <storage::Ownership Ownership> class TurnDataContainerImpl
|
||||
@@ -75,17 +84,20 @@ template <storage::Ownership Ownership> class TurnDataContainerImpl
|
||||
|
||||
// Used by EdgeBasedGraphFactory to fill data structure
|
||||
template <typename = std::enable_if<Ownership == storage::Ownership::Container>>
|
||||
void push_back(extractor::guidance::TurnInstruction turn_instruction,
|
||||
LaneDataID lane_data_id,
|
||||
EntryClassID entry_class_id,
|
||||
util::guidance::TurnBearing pre_turn_bearing,
|
||||
util::guidance::TurnBearing post_turn_bearing)
|
||||
void push_back(const TurnData &data)
|
||||
{
|
||||
turn_instructions.push_back(turn_instruction);
|
||||
lane_data_ids.push_back(lane_data_id);
|
||||
entry_class_ids.push_back(entry_class_id);
|
||||
pre_turn_bearings.push_back(pre_turn_bearing);
|
||||
post_turn_bearings.push_back(post_turn_bearing);
|
||||
turn_instructions.push_back(data.turn_instruction);
|
||||
lane_data_ids.push_back(data.lane_data_id);
|
||||
entry_class_ids.push_back(data.entry_class_id);
|
||||
pre_turn_bearings.push_back(data.pre_turn_bearing);
|
||||
post_turn_bearings.push_back(data.post_turn_bearing);
|
||||
}
|
||||
|
||||
template <typename = std::enable_if<Ownership == storage::Ownership::Container>>
|
||||
void append(const std::vector<TurnData> &others)
|
||||
{
|
||||
std::for_each(
|
||||
others.begin(), others.end(), [this](const TurnData &other) { push_back(other); });
|
||||
}
|
||||
|
||||
friend void serialization::read<Ownership>(storage::io::FileReader &reader,
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#ifndef CONCURRENT_ID_MAP_HPP
|
||||
#define CONCURRENT_ID_MAP_HPP
|
||||
|
||||
#include <boost/interprocess/sync/interprocess_upgradable_mutex.hpp>
|
||||
#include <boost/interprocess/sync/scoped_lock.hpp>
|
||||
#include <boost/interprocess/sync/sharable_lock.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
/**
|
||||
* This is a special purpose map for caching incrementing IDs
|
||||
*/
|
||||
template <typename KeyType, typename ValueType, typename HashType = std::hash<KeyType>>
|
||||
struct ConcurrentIDMap
|
||||
{
|
||||
static_assert(std::is_unsigned<ValueType>::value, "Only unsigned integer types are supported.");
|
||||
|
||||
using UpgradableMutex = boost::interprocess::interprocess_upgradable_mutex;
|
||||
using ScopedReaderLock = boost::interprocess::sharable_lock<UpgradableMutex>;
|
||||
using ScopedWriterLock = boost::interprocess::scoped_lock<UpgradableMutex>;
|
||||
|
||||
std::unordered_map<KeyType, ValueType, HashType> data;
|
||||
mutable UpgradableMutex mutex;
|
||||
|
||||
const ValueType ConcurrentFindOrAdd(const KeyType &key)
|
||||
{
|
||||
{
|
||||
ScopedReaderLock sentry{mutex};
|
||||
const auto result = data.find(key);
|
||||
if (result != data.end())
|
||||
{
|
||||
return result->second;
|
||||
}
|
||||
}
|
||||
{
|
||||
ScopedWriterLock sentry{mutex};
|
||||
const auto result = data.find(key);
|
||||
if (result != data.end())
|
||||
{
|
||||
return result->second;
|
||||
}
|
||||
const auto id = static_cast<ValueType>(data.size());
|
||||
data[key] = id;
|
||||
return id;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // util
|
||||
} // osrm
|
||||
|
||||
#endif // CONCURRENT_ID_MAP_HPP
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "util/concurrent_id_map.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
@@ -97,7 +98,7 @@ class LaneTupleIdPair
|
||||
}
|
||||
};
|
||||
|
||||
using LaneDataIdMap = std::unordered_map<LaneTupleIdPair, LaneDataID, boost::hash<LaneTupleIdPair>>;
|
||||
using LaneDataIdMap = ConcurrentIDMap<LaneTupleIdPair, LaneDataID, boost::hash<LaneTupleIdPair>>;
|
||||
|
||||
} // namespace guidance
|
||||
} // namespace util
|
||||
|
||||
Reference in New Issue
Block a user