Dear all,
I’m continuing my quest on getting the cartesian product example of Bruce A Lelbach running.
I implemented it in the following way:
#include <algorithm>
#include <iostream>
#include <ranges>
#include <execution>
#ifndef D_Vector
#include <valarray>
#else
#include <vector>
#endif
#include <experimental/mdspan>
namespace stdex = std::experimental;
namespace execution = std::execution;
namespace stdv = std::views;
int main()
{
constexpr int N = 1000;
constexpr int M = 1000;
constexpr int O = 100;
#ifndef D_Vector
std::valarray<double> input(1, N * M * O);
std::valarray<double> output(N * M * O);
stdex::mdspan A{std::begin(input), N, M, O};
stdex::mdspan B{std::begin(output), N, M, O};
#else
std::vector<double> input(N * M * O, 1);
std::vector<double> output(N * M * O);
// stdex::mdspan<double, stdex::dextents<2>> A{input.begin(), N, M, O};
stdex::mdspan A{input.begin(), N, M, O};
stdex::mdspan B{output.begin(), N, M, O};
#endif
A(1, 1, 1) = 2;
auto v = stdv::cartesian_product(
std::ranges::views::iota(1ul, A.extent(0) - 1),
std::ranges::views::iota(1ul, A.extent(1) - 1),
std::ranges::views::iota(1ul, A.extent(2) - 1));
std::for_each(execution::par_unseq,
std::begin(v),
std::end(v),
[=] (auto idx)
{
auto [i, j, k] = idx;
B(i, j, k) = (A(i, j, k-1) + A(i, j, k+1)
+ A(i-1, j, k) + A(i+1, j, k)
+ A(i, j-1, k) + A(i, j, k) + A(i, j+1, k)) / 7;
});
std::cout << B(1, 1, 1) << ' ' << A(1, 1, 1) << std::endl;
}
Compiling with (note, I’m using nvc++ from hpc_sdk 24.3 and a conda installed g++ 13.2)
nvc++ cp1.C -O2 --std=c++23 --gcc-toolchain=${CONDA_PREFIX}/bin/gcc -L ${CONDA_PREFIX}/x86_64-conda-linux-gnu/lib -o cp1 -L ${CONDA_PREFIX}/lib && ./cp1
everything looks fine. It compiles and runs.
Adding -stdpar=multicore
as compile flag results in
/usr/bin/ld: /tmp/nvc++dd_6jmN0pH6I.o: in function `__nv__ZN6thrust6system3omp6detail10for_each_nINS2_5par_tENSt6ranges22cartesian_product_viewINS5_9iota_viewImmEEJS8_S8_EE9_IteratorILb1EEEnZ4mainEUlT_E_EET0_RNS2_16execution_policyISC_EESE_T1_T2__F786L74_1':
${HOME}/NVidia/hpc_sdk/Linux_x86_64/24.3/compilers/include-stdpar/thrust/system/omp/detail/for_each.inl:74: undefined reference to `__kmpc_for_static_init_16'
where I replaced my home directory with $HOME. Any hints which library I need to link? I scanned all installed library but couldn’t find a suitable one.
In addition, when using -stdpar=gpu
compilations aborts with
NVC++-F-0155-Compiler failed to translate accelerator region (see -Minfo messages): Unexpected branch type (cp1.C: 432)
NVC++/x86-64 Linux 24.3-0: compilation aborted
And finally, when trying to use std::vector
with -DD_Vector
I’m flooded with error messages, starting with
"cp1.C", line 35: error: cannot deduce class template arguments
stdex::mdspan A{input.begin(), N, M, O};
Any help is appreciated,
best regards,
Peter