Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatoly Serdtcev <serdtcev@maps.me>2019-01-29 20:03:36 +0300
committerAnatoly Serdtcev <serdtcev@maps.me>2019-01-31 14:16:24 +0300
commit07ef24680d16929bbd900d65f8658b74382997c0 (patch)
treecad92f2e60d5b7aa81a8175d9e902fcbe86806e2 /geocoder
parent4f07aadd8d233b783943c79b45c81129438d4917 (diff)
[geocoder] Concurrent index houses
Diffstat (limited to 'geocoder')
-rw-r--r--geocoder/index.cpp49
1 files changed, 35 insertions, 14 deletions
diff --git a/geocoder/index.cpp b/geocoder/index.cpp
index 86e89ea0c7..f11e991c0a 100644
--- a/geocoder/index.cpp
+++ b/geocoder/index.cpp
@@ -8,7 +8,10 @@
#include "base/logging.hpp"
#include "base/string_utils.hpp"
+#include <atomic>
#include <cstddef>
+#include <mutex>
+#include <thread>
using namespace std;
@@ -88,29 +91,47 @@ void Index::AddStreet(DocId const & docId, Index::Doc const & doc)
void Index::AddHouses()
{
- size_t numIndexed = 0;
- for (DocId docId = 0; docId < static_cast<DocId>(m_docs.size()); ++docId)
- {
- auto const & buildingDoc = GetDoc(docId);
+ atomic<size_t> numIndexed{0};
+ std::mutex mutex;
- if (buildingDoc.m_type != Type::Building)
- continue;
+ vector<thread> threads(thread::hardware_concurrency());
- size_t const t = static_cast<size_t>(Type::Street);
+ for (size_t t = 0; t < threads.size(); ++t)
+ {
+ threads[t] = thread([&, t, this]() {
+ size_t const size = m_docs.size() / threads.size();
+ size_t docId = t * size;
+ size_t const docIdEnd = (t + 1 == threads.size() ? m_docs.size() : docId + size);
- ForEachDocId(buildingDoc.m_address[t], [&](DocId const & streetCandidate) {
- auto const & streetDoc = GetDoc(streetCandidate);
- if (streetDoc.IsParentTo(buildingDoc))
+ for (; docId < docIdEnd; ++docId)
{
- m_buildingsOnStreet[streetCandidate].emplace_back(docId);
+ auto const & buildingDoc = GetDoc(docId);
- ++numIndexed;
- if (numIndexed % kLogBatch == 0)
- LOG(LINFO, ("Indexed", numIndexed, "houses"));
+ if (buildingDoc.m_type != Type::Building)
+ continue;
+
+ size_t const streetType = static_cast<size_t>(Type::Street);
+
+ ForEachDocId(buildingDoc.m_address[streetType], [&](DocId const & streetCandidate) {
+ auto const & streetDoc = GetDoc(streetCandidate);
+
+ if (streetDoc.IsParentTo(buildingDoc))
+ {
+ auto && lock = lock_guard<std::mutex>(mutex);
+ m_buildingsOnStreet[streetCandidate].emplace_back(docId);
+ }
+ });
+
+ auto processedCount = numIndexed.fetch_add(1) + 1;
+ if (processedCount % kLogBatch == 0)
+ LOG(LINFO, ("Indexed", processedCount, "houses"));
}
});
}
+ for (auto & t : threads)
+ t.join();
+
if (numIndexed % kLogBatch != 0)
LOG(LINFO, ("Indexed", numIndexed, "houses"));
}