Skip to content

Instantly share code, notes, and snippets.

@morefreeze

morefreeze/multimatch.cc

Last active Jul 27, 2018
Embed
What would you like to do?
multithread on get_postlist
// It need push_back postlist by order, so record pl_map[i] = pl, then push them orderly.
std::map<int, PostList *> pl_map;
std::vector<std::thread> vt;
std::mutex mutex;
auto start = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i != leaves.size(); ++i) {
vt.push_back(std::thread([this, first, maxitems, start, &total_subqs, &pl_map, &definite_matches_not_seen, &mutex](size_t ii) {
PostList *pl = leaves[ii]->get_postlist(this, &total_subqs);
if (false && is_remote[ii]) { // use localmutltimatch, so don't go here
if (pl->get_termfreq_min() > first + maxitems) {
LOGLINE(MATCH, "Found " <<
pl->get_termfreq_min() - (first + maxitems)
<< " definite matches in remote submatch "
"which aren't passed to local match");
definite_matches_not_seen += pl->get_termfreq_min();
definite_matches_not_seen -= first + maxitems;
}
}
{
// map should be thread safe
std::lock_guard<std::mutex> guard(mutex);
pl_map[ii] = pl;
}
}, i));
}
std::for_each(vt.begin(), vt.end(), [](std::thread &t) { t.join(); });
for (size_t i = 0; i != leaves.size(); ++i) {
postlists.push_back(pl_map[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment