Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions src/sorted_node_store.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <iostream>
#include <algorithm>
#include <atomic>
#include <boost/asio/post.hpp>
#include <boost/asio/thread_pool.hpp>
#include <cstring>
#include <string>
#include <map>
Expand Down Expand Up @@ -530,20 +533,31 @@ void SortedNodeStore::finalize(size_t threadNum) {
}
workerBuffers.clear();

// Empty the orphanage into the index.
std::vector<element_t> copy;
for (const auto& entry: orphanage) {
for (const auto& orphan: entry.second)
copy.push_back(orphan);

// Orphans may come from different workers, and thus be unsorted.
std::sort(
copy.begin(),
copy.end(),
[](auto const &a, auto const &b) { return a.first < b.first; }
);
publishGroup(copy);
copy.clear();
// Empty the orphanage into the index. The groups are independent and publishGroup is what the
// workers call during the pass anyway, so publish them from all threads: one after the other,
// the planet's leftover groups took ~10 s with every other thread idle.
std::vector<const std::vector<element_t>*> orphanGroups;
for (const auto& entry: orphanage)
orphanGroups.push_back(&entry.second);
std::atomic<size_t> nextGroup(0);
auto publishOrphans = [&]() {
std::vector<element_t> copy;
for (size_t i = nextGroup++; i < orphanGroups.size(); i = nextGroup++) {
copy.assign(orphanGroups[i]->begin(), orphanGroups[i]->end());
// Orphans may come from different workers, and thus be unsorted.
std::sort(
copy.begin(),
copy.end(),
[](auto const &a, auto const &b) { return a.first < b.first; }
);
publishGroup(copy);
}
};
{
boost::asio::thread_pool pool(std::max<unsigned int>(1, threadNum));
for (unsigned int t = 0; t < std::max<unsigned int>(1, threadNum); t++)
boost::asio::post(pool, publishOrphans);
pool.join();
}

orphanage.clear();
Expand Down
42 changes: 28 additions & 14 deletions src/sorted_way_store.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <algorithm>
#include <atomic>
#include <boost/asio/post.hpp>
#include <boost/asio/thread_pool.hpp>
#include <bitset>
#include <cstring>
#include <iostream>
Expand Down Expand Up @@ -278,20 +281,31 @@ void SortedWayStore::finalize(unsigned int threadNum) {
}
workerBuffers.clear();

// Empty the orphanage into the index.
std::vector<std::pair<WayID, std::vector<NodeID>>> copy;
for (const auto& entry: orphanage) {
for (const auto& orphan: entry.second)
copy.push_back(orphan);

// Orphans may come from different workers, and thus be unsorted.
std::sort(
copy.begin(),
copy.end(),
[](auto const &a, auto const &b) { return a.first < b.first; }
);
publishGroup(copy);
copy.clear();
// Empty the orphanage into the index. The groups are independent and publishGroup is what the
// workers call during the pass anyway, so publish them from all threads: one after the other,
// the planet's leftover groups took ~10 s with every other thread idle.
std::vector<const std::vector<std::pair<WayID, std::vector<NodeID>>>*> orphanGroups;
for (const auto& entry: orphanage)
orphanGroups.push_back(&entry.second);
std::atomic<size_t> nextGroup(0);
auto publishOrphans = [&]() {
std::vector<std::pair<WayID, std::vector<NodeID>>> copy;
for (size_t i = nextGroup++; i < orphanGroups.size(); i = nextGroup++) {
copy.assign(orphanGroups[i]->begin(), orphanGroups[i]->end());
// Orphans may come from different workers, and thus be unsorted.
std::sort(
copy.begin(),
copy.end(),
[](auto const &a, auto const &b) { return a.first < b.first; }
);
publishGroup(copy);
}
};
{
boost::asio::thread_pool pool(std::max<unsigned int>(1, threadNum));
for (unsigned int t = 0; t < std::max<unsigned int>(1, threadNum); t++)
boost::asio::post(pool, publishOrphans);
pool.join();
}

orphanage.clear();
Expand Down
Loading