Last active
July 27, 2018 07:54
-
-
Save morefreeze/e06dfd6de44dbe61d4fb4905b14e9e27 to your computer and use it in GitHub Desktop.
multithread on get_postlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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