-
-
Save Jedi18/7c280062f21f5da091126cfaef0b6352 to your computer and use it in GitHub Desktop.
async inclusive_scan gist
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
std::vector<double> output(input.size()); | |
const std::size_t tile_size = (input.size() + tile_count - 1) / tile_count; | |
std::vector<double> partials(tile_count + 1); | |
partials[0] = init; | |
return ex::just_on(sched, partials) | | |
ex::bulk(tile_count, | |
[&](std::size_t i, std::vector<double>& partials) { | |
auto start = i * tile_size; | |
auto end = std::min(input.size(), (i + 1) * tile_size); | |
partials[i + 1] = | |
*--std::inclusive_scan(std::begin(input) + start, | |
std::begin(input) + end, std::begin(output) + start); | |
}) | | |
ex::transform([](std::vector<double>& partials) { | |
std::inclusive_scan( | |
std::begin(partials), std::end(partials), std::begin(partials)); | |
return std::move(partials); | |
}) | | |
ex::bulk(tile_count, | |
[&](std::size_t i, std::vector<double>& partials) { | |
auto start = i * tile_size; | |
auto end = std::min(input.size(), (i + 1) * tile_size); | |
std::for_each(output.begin() + start, | |
output.begin() + end, | |
[&](double& e) { e = partials[i] + e; }); | |
}) | | |
ex::transform([&](std::vector<double>&) { return output; }) | | |
ex::sync_wait(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment