Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const unsigned trees_per_thread = num_trees / num_threads;
- const unsigned more_work_limit =
- num_trees - trees_per_thread * num_threads;
- std::vector<std::thread> workers;
- workers.reserve(num_threads);
- for (unsigned id = 0; id < num_threads; ++id) {
- workers.emplace_back([this, id, &ch, &starts, &distances,
- trees_per_thread, more_work_limit]() {
- const unsigned begin =
- trees_per_thread * id + more_work_limit -
- (id < more_work_limit ? (more_work_limit - id) : 0);
- const unsigned end =
- trees_per_thread * (id + 1) + more_work_limit -
- ((id + 1) < more_work_limit ? (more_work_limit - (id + 1)) : 0);
- for (unsigned index = begin; index < end; ++index) {
- forward_search_init(ch, ((unsigned *)&starts)[index], distances,
- index);
- }
- });
- }
- for (auto &w : workers) {
- w.join();
- }
Add Comment
Please, Sign In to add comment