Skip to content

Instantly share code, notes, and snippets.

@morefreeze
Last active July 27, 2018 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morefreeze/e06dfd6de44dbe61d4fb4905b14e9e27 to your computer and use it in GitHub Desktop.
Save morefreeze/e06dfd6de44dbe61d4fb4905b14e9e27 to your computer and use it in GitHub Desktop.
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