The code below compiles with execution of seq, but not par:
//Parallel brute-force finding of near-neighbors of x in y;
auto search_with_copy_if(vector &x, vector &y) {
vector<std::tuple<size_t, size_t>> nn_pairs( //Allocate 1D array of pairs:
10 * x.size(),
std::tuple<size_t, size_t>{-9999, -9999});
auto xs = std::views::iota((size_t)0, x.size());
auto ys = std::views::iota((size_t)0, y.size());
auto ids = std::views::cartesian_product(xs, ys);
//copy a touple [i,j] from ids into nn_pairs if x[i] near j[j]
std::copy_if(
std::execution::par, //nvc++ for gpu compiles with seq, but not with par
ids.begin(), ids.end(),
nn_pairs.begin(), //GPU nvc++ requires random_access iter;
[=, x = x.data(), y = y.data()](auto idx) {
auto i = get<0>(idx);
auto j = get<1>(idx);
return is_near(x[i], y[j]); //is_near returns true iff x[i]=y[i] ± delta.
}
);
return nn_pairs;
}
I am using nvc++ 23.5 with flags -std=c++20 -stdpar=gpu -O2 -g. The two error messages are:
[build] /opt/nvidia/hpc_sdk/Linux_x86_64/23.5/compilers/share/llvm/bin/opt: /tmp/nvc++5-XkRAsqATbA.ll:286988:1: error: redefinition of global ‘@_ZN70_INTERNAL_48__home_mzuniga_gfdl_misc_src_cpp_src_stdpartest_C_02339522St14is_reference_vIRKDTcl6deduceIN2tl22cartesian_product_viewIJNSt6ranges9iota_viewImmEES4_EE6cursorILb0EEEELi0EEEEE’
[build] @_ZN70_INTERNAL_48__home_mzuniga_gfdl_misc_src_cpp_src_stdpartest_C_02339522St14is_reference_vIRKDTcl6deduceIN2tl22cartesian_product_viewIJNSt6ranges9iota_viewImmEES4_EE6cursorILb0EEEELi0EEEEE = internal dso_local global i8 1, align 1, !dbg !156711
Thanks!