Skip to content

Commit

Permalink
Using useTwoThreads instead of twoThreadsReady in some cases. And pas…
Browse files Browse the repository at this point in the history
…sing useTwoThreads for testing.
  • Loading branch information
bykoianko committed Nov 18, 2020
1 parent e24acc7 commit f184f1d
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 40 deletions.
2 changes: 1 addition & 1 deletion routing/async_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void AsyncRouter::CalculateRoute()
absentFetcher->GenerateRequest(checkpoints);

// Run basic request.
code = router->CalculateRoute(checkpoints, startDirection, adjustToPrevRoute,
code = router->CalculateRoute(checkpoints, startDirection, true /* useTwoThreads */, adjustToPrevRoute,
delegateProxy->GetDelegate(), *route);
router->SetGuides({});
elapsedSec = timer.ElapsedSeconds(); // routing time
Expand Down
5 changes: 3 additions & 2 deletions routing/base/astar_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ class AStarAlgorithm
/// If the decision is made to use two thread version it should be taken into account:
/// - |isOutgoing| flag in each method specified which thread calls the method
/// - All callbacks which are called from |wave| lambda such as |params.m_onVisitedVertexCallback|
/// or |params.m_checkLengthCallback| should be ready for calling from two threads
/// or |params.m_checkLengthCallback| should be ready for calling from two threads.
template <typename P>
Result FindPathBidirectional(P & params, RoutingResult<Vertex, Weight> & result) const;


// Adjust route to the previous one.
// Expects |params.m_checkLengthCallback| to check wave propagation limit.
template <typename P>
Expand Down Expand Up @@ -630,6 +629,8 @@ AStarAlgorithm<Vertex, Edge, Weight>::FindPathBidirectional(P & params,
auto const & startVertex = params.m_startVertex;

auto const useTwoThreads = graph.IsTwoThreadsReady();
LOG(LINFO,
(useTwoThreads ? "Bidirectional A* in two threads." : "Bidirectional A* in one thread."));
std::optional<std::mutex> mtx;

BidirectionalStepContext forward(mtx, true /* forward */, startVertex, finalVertex, graph);
Expand Down
20 changes: 4 additions & 16 deletions routing/index_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ bool IndexRouter::FindClosestProjectionToRoad(m2::PointD const & point,
void IndexRouter::SetGuides(GuidesTracks && guides) { m_guides = GuidesConnections(guides); }

RouterResultCode IndexRouter::CalculateRoute(Checkpoints const & checkpoints,
m2::PointD const & startDirection,
m2::PointD const & startDirection, bool useTwoThreads,
bool adjustToPrevRoute,
RouterDelegate const & delegate, Route & route)
{
Expand Down Expand Up @@ -407,19 +407,7 @@ RouterResultCode IndexRouter::CalculateRoute(Checkpoints const & checkpoints,
}
}

RouterResultCode lastReturn = RouterResultCode::InternalError;
for (auto twoThreadsReady : {false, true, true, false})
{
LOG(LINFO, ("---------------------", twoThreadsReady ? "Two threads" : "One threads", "---------------------"));
// TODO |twoThreadsReady| is passed to DoCalculateRoute(), CalculateSubroute() and
// to CalculateSubrouteJointsMode() for test purposes only. It should be removed in
// these methods.
m_guides.Clear();
lastReturn = DoCalculateRoute(checkpoints, startDirection, delegate, twoThreadsReady, route);
LOG(LINFO, ("---------------------", twoThreadsReady ? "Two threads" : "One threads", "END---------------------"));
}
// return DoCalculateRoute(checkpoints, startDirection, delegate, false, route);
return lastReturn;
return DoCalculateRoute(checkpoints, startDirection, delegate, useTwoThreads, route);
}
catch (RootException const & e)
{
Expand Down Expand Up @@ -565,7 +553,7 @@ void IndexRouter::AddGuidesOsmConnectionsToGraphStarter(size_t checkpointIdxFrom
RouterResultCode IndexRouter::DoCalculateRoute(Checkpoints const & checkpoints,
m2::PointD const & startDirection,
RouterDelegate const & delegate,
bool twoThreadsReady, Route & route)
bool useTwoThreads, Route & route)
{
m_lastRoute.reset();
// MwmId used for guides segments in RedressRoute().
Expand Down Expand Up @@ -598,7 +586,7 @@ RouterResultCode IndexRouter::DoCalculateRoute(Checkpoints const & checkpoints,
return RouterResultCode::NeedMoreMaps;

TrafficStash::Guard guard(m_trafficStash);
unique_ptr<WorldGraph> graph = MakeWorldGraph(twoThreadsReady);
unique_ptr<WorldGraph> graph = MakeWorldGraph(useTwoThreads);

vector<Segment> segments;

Expand Down
7 changes: 4 additions & 3 deletions routing/index_router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ class IndexRouter : public IRouter

void SetGuides(GuidesTracks && guides) override;
RouterResultCode CalculateRoute(Checkpoints const & checkpoints,
m2::PointD const & startDirection, bool adjustToPrevRoute,
RouterDelegate const & delegate, Route & route) override;
m2::PointD const & startDirection, bool useTwoThreads,
bool adjustToPrevRoute, RouterDelegate const & delegate,
Route & route) override;

bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction,
double radius, EdgeProj & proj) override;
Expand All @@ -122,7 +123,7 @@ class IndexRouter : public IRouter

RouterResultCode DoCalculateRoute(Checkpoints const & checkpoints,
m2::PointD const & startDirection,
RouterDelegate const & delegate, bool twoThreadsReady,
RouterDelegate const & delegate, bool useTwoThreads,
Route & route);
RouterResultCode CalculateSubroute(Checkpoints const & checkpoints, size_t subrouteIdx,
RouterDelegate const & delegate,
Expand Down
5 changes: 3 additions & 2 deletions routing/router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class IRouter
/// @return ResultCode error code or NoError if route was initialised
/// @see Cancellable
virtual RouterResultCode CalculateRoute(Checkpoints const & checkpoints,
m2::PointD const & startDirection, bool adjust,
RouterDelegate const & delegate, Route & route) = 0;
m2::PointD const & startDirection, bool useTwoThreads,
bool adjust, RouterDelegate const & delegate,
Route & route) = 0;

virtual bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction,
double radius, EdgeProj & proj) = 0;
Expand Down
3 changes: 2 additions & 1 deletion routing/routes_builder/routes_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ RoutesBuilder::Processor::operator()(Params const & params)
m_delegate->SetTimeout(params.m_timeoutSeconds);
base::Timer timer;
resultCode = m_router->CalculateRoute(params.m_checkpoints, m2::PointD::Zero(),
false /* adjustToPrevRoute */, *m_delegate, route);
false /* useTwoThreads */, false /* adjustToPrevRoute */,
*m_delegate, route);

if (resultCode != RouterResultCode::NoError)
break;
Expand Down
6 changes: 3 additions & 3 deletions routing/routing_benchmarks/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ void TestRouter(routing::IRouter & router, m2::PointD const & startPos,
routing::RouterDelegate delegate;
LOG(LINFO, ("Calculating routing ...", router.GetName()));
base::Timer timer;
auto const resultCode = router.CalculateRoute(routing::Checkpoints(startPos, finalPos),
m2::PointD::Zero() /* startDirection */,
false /* adjust */, delegate, route);
auto const resultCode = router.CalculateRoute(
routing::Checkpoints(startPos, finalPos), m2::PointD::Zero() /* startDirection */,
false /* useTwoThreads */, false /* adjust */, delegate, route);
double const elapsedSec = timer.ElapsedSeconds();
TEST_EQUAL(routing::RouterResultCode::NoError, resultCode, ());
TEST(route.IsValid(), ());
Expand Down
8 changes: 5 additions & 3 deletions routing/routing_integration_tests/routing_test_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,13 @@ IRouterComponents & GetVehicleComponents(VehicleType vehicleType)

TRouteResult CalculateRoute(IRouterComponents const & routerComponents,
m2::PointD const & startPoint, m2::PointD const & startDirection,
m2::PointD const & finalPoint)
m2::PointD const & finalPoint, bool useTwoThreads /* = false */)
{
RouterDelegate delegate;
shared_ptr<Route> route = make_shared<Route>("mapsme", 0 /* route id */);
RouterResultCode result = routerComponents.GetRouter().CalculateRoute(
Checkpoints(startPoint, finalPoint), startDirection, false /* adjust */, delegate, *route);
Checkpoints(startPoint, finalPoint), startDirection, useTwoThreads, false /* adjust */,
delegate, *route);
ASSERT(route, ());
routerComponents.GetRouter().SetGuides({});
return TRouteResult(route, result);
Expand All @@ -171,7 +172,8 @@ TRouteResult CalculateRoute(IRouterComponents const & routerComponents,
shared_ptr<Route> route = make_shared<Route>("mapsme", 0 /* route id */);
routerComponents.GetRouter().SetGuides(move(guides));
RouterResultCode result = routerComponents.GetRouter().CalculateRoute(
checkpoints, m2::PointD::Zero() /* startDirection */, false /* adjust */, delegate, *route);
checkpoints, m2::PointD::Zero() /* startDirection */, false /* useTwoThreads */,
false /* adjust */, delegate, *route);
ASSERT(route, ());
routerComponents.GetRouter().SetGuides({});
return TRouteResult(route, result);
Expand Down
2 changes: 1 addition & 1 deletion routing/routing_integration_tests/routing_test_tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ IRouterComponents & GetVehicleComponents(VehicleType vehicleType);

TRouteResult CalculateRoute(IRouterComponents const & routerComponents,
m2::PointD const & startPoint, m2::PointD const & startDirection,
m2::PointD const & finalPoint);
m2::PointD const & finalPoint, bool useTwoThreads = false);

TRouteResult CalculateRoute(IRouterComponents const & routerComponents,
Checkpoints const & checkpoints, GuidesTracks && guides);
Expand Down
7 changes: 4 additions & 3 deletions routing/routing_tests/async_router_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class DummyRouter : public IRouter
// IRouter overrides:
string GetName() const override { return "Dummy"; }
void SetGuides(GuidesTracks && /* guides */) override {}
RouterResultCode CalculateRoute(Checkpoints const & checkpoints, m2::PointD const & startDirection,
bool adjustToPrevRoute, RouterDelegate const & delegate,
Route & route) override
RouterResultCode CalculateRoute(Checkpoints const & checkpoints,
m2::PointD const & startDirection, bool useTwoThreads,
bool adjustToPrevRoute, RouterDelegate const & delegate,
Route & route) override
{
route = Route("dummy", checkpoints.GetPoints().cbegin(), checkpoints.GetPoints().cend(),
0 /* route id */);
Expand Down
10 changes: 5 additions & 5 deletions routing/routing_tests/routing_session_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ class DummyRouter : public IRouter
void ClearState() override {}
void SetGuides(GuidesTracks && /* guides */) override {}

RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */,
m2::PointD const & /* startDirection */, bool /* adjust */,
RouterDelegate const & /* delegate */, Route & route) override
RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */, m2::PointD const & /* startDirection */, bool /* useTwoThreads */,
bool /* adjust */, RouterDelegate const & /* delegate */, Route & route) override
{
++m_buildCount;
route = m_route;
Expand Down Expand Up @@ -90,8 +89,9 @@ class ReturnCodesRouter : public IRouter
void SetGuides(GuidesTracks && /* guides */) override {}

RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */,
m2::PointD const & /* startDirection */, bool /* adjust */,
RouterDelegate const & /* delegate */, Route & route) override
m2::PointD const & /* startDirection */, bool /* useTwoThreads */,
bool /* adjust */, RouterDelegate const & /* delegate */,
Route & route) override
{
TEST_LESS(m_returnCodesIdx, m_returnCodes.size(), ());
route = Route(GetName(), m_route.begin(), m_route.end(), 0 /* route id */);
Expand Down

0 comments on commit f184f1d

Please sign in to comment.