Hi,
I heard that with nvc++ 22.2 and higher (and GCC10 or newer) we should be able to use the new std::ranges::views::iota function from c++20 instead of the Thrust counting_iterator function to iterate over indices. However, I only manage to compile my code when I use integer indices.
#include <iostream>
#include <vector>
#include <execution>
#include <ranges>
#include <algorithm>
#include <atomic>
int main()
{
constexpr size_t size = 1000;
std::vector<float> v1(size);
auto v1Ptr = v1.data();
auto range = std::ranges::iota_view(0, int(size));
std::for_each(std::execution::par_unseq, range.begin(), range.end(), [=](size_t i) {
v1Ptr[i] = 10;
});
std::cout << v1[size-1] << std::endl;
return 0;
}
The code compiles with nvc++ -stdpar -std=c++20
With unsigned long indices, it only compiles without the -stdpar option:
#include <iostream>
#include <vector>
#include <execution>
#include <ranges>
#include <algorithm>
#include <atomic>
int main()
{
constexpr size_t size = 1000;
std::vector<float> v1(size);
auto v1Ptr = v1.data();
auto range = std::ranges::iota_view(0ul, size);
std::for_each(std::execution::par_unseq, range.begin(), range.end(), [=](size_t i) {
v1Ptr[i] = 10;
});
std::cout << v1[size-1] << "\n";
return 0;
}
The error:
NVC++-F-0155-Compiler failed to translate accelerator region (see -Minfo messages): Unsupported operation (test_range.cpp: 1)
NVC++/x86-64 Linux 22.7-0: compilation aborted
I know I can get the same result with Thrust counting_iterator or by deducing the index from the address of an element but I find it more elegant to use std::ranges::views::iota.
Regards,
Raf