Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: map_rect_concurrent with parallel STL backends #1085

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
eliminate need for extra lambda declaration
  • Loading branch information
wds15 committed Dec 16, 2018
commit 4ec241626b2f7c04582b116501f538510f205df0
11 changes: 4 additions & 7 deletions stan/math/parallel/for_each.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,16 @@ UnaryFunction for_each_impl(InputIt first, InputIt last, UnaryFunction f,
for (std::size_t i = 0; i < num_big_jobs; ++i)
++job_chunk_size[num_threads - i - 1];

auto execute_chunk = [&](InputIt start, InputIt end) -> void {
std::for_each(start, end, f);
};

std::vector<std::future<void> > job_futures;

InputIt cur_job_start = first;
for (std::size_t i = 0; i < num_threads; ++i) {
InputIt cur_job_end = cur_job_start;
std::advance(cur_job_end, job_chunk_size[i]);
job_futures.emplace_back(
std::async(i == 0 ? std::launch::deferred : std::launch::async,
execute_chunk, cur_job_start, cur_job_end));
job_futures.emplace_back(std::async(
i == 0 ? std::launch::deferred : std::launch::async, [=]() -> void {
std::for_each<InputIt, UnaryFunction>(cur_job_start, cur_job_end, f);
}));
cur_job_start = cur_job_end;
}

Expand Down