Skip to content
Open
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
46 changes: 46 additions & 0 deletions test/stdpar/tests/exclusive_scan.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <cstddef>
#include <execution>
#include <numeric>
#include <vector>

int main()
{
constexpr std::size_t N = 1 << 16;

std::vector<int> in(N);
std::vector<int> out(N);

for (std::size_t i = 0; i < N; ++i)
{
in[i] = static_cast<int>(i + 1);
}

// exclusive_scan with default initial value (0)
std::exclusive_scan(std::execution::par, in.begin(), in.end(), out.begin(), 0);

int running_sum = 0;
for (std::size_t i = 0; i < N; ++i)
{
if (out[i] != running_sum)
{
return 1;
}
running_sum += in[i];
}

// exclusive_scan with non-zero initial value
const int init = 42;
std::exclusive_scan(std::execution::par, in.begin(), in.end(), out.begin(), init);

running_sum = init;
for (std::size_t i = 0; i < N; ++i)
{
if (out[i] != running_sum)
{
return 1;
}
running_sum += in[i];
}

return 0;
}
Loading