Here is a smaller code which gives me the same error:
main.cpp
#include <vector>
#include <algorithm>
#include <execution>
#include <cstdio>
#include <cstdlib>
using namespace std;
class Test
{
public:
Test(size_t size) : m_data(size), m_Size(size)
{
for (size_t i = 0; i < m_Size; ++i)
{
m_data[i] = rand() % m_Size;
}
}
double getMedian()
{
vector<double> temp(m_Size);
for (int i = 0; i < m_Size; i++)
{
temp[i] = m_data[i];
}
std::sort(std::execution::par, temp.begin(), temp.end());
return temp[m_Size / 2];
}
void print()
{
for (int i = 0; i < m_Size; i++)
{
printf("%d, ", m_data[i]);
}
printf("\nMedian = %lf\n", getMedian());
}
private:
vector<double> m_data;
size_t m_Size;
};
int main()
{
Test t(100'000);
#pragma acc parallel loop
for (int i = 0; i < 1'000'000; ++i)
{
if (i % 1'000 == 0)
{
t.print();
}
}
return EXIT_SUCCESS;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project (
TestOpenAcc
VERSION 1.0.0
LANGUAGES CXX CUDA
)
# Set build type
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -fast -stdpar -acc -gpu=managed -Minfo=accel")
# Add the CPP files to the executable
add_executable(a.out
${CMAKE_SOURCE_DIR}/main.cpp
)
output
[ 50%] Building CXX object CMakeFiles/a.out.dir/main.cpp.o
main:
47, Generating NVIDIA GPU code
33, #pragma acc loop seq
50, #pragma acc loop gang, vector(128) /* blockIdx.x threadIdx.x */
47, Generating implicit copy(t) [if not already present]
Test::getMedian():
21, Generating implicit acc routine seq
Test::print():
32, Generating implicit acc routine seq
Generating acc routine seq
Generating NVIDIA GPU code
void std::_Destroy_aux<true>::__destroy<decltype(std::allocator<double>::pointer std::allocator_traits<std::allocator<double>>::_S_pointer_helper<std::allocator<double>>(std::allocator<double>*)((std::allocator<double>*)0))>(decltype(std::allocator<double>::pointer std::allocator_traits<std::allocator<double>>::_S_pointer_helper<std::allocator<double>>(std::allocator<double>*)((std::allocator<double>*)0)), decltype(std::allocator<double>::pointer std::allocator_traits<std::allocator<double>>::_S_pointer_helper<std::allocator<double>>(std::allocator<double>*)((std::allocator<double>*)0))):
1, include "vector"
62, include "stl_construct.h"
112, Generating implicit acc routine seq
Generating acc routine seq
Generating NVIDIA GPU code
void std::__uninitialized_default_n_1<true>::__uninit_default_n<decltype(std::allocator<double>::pointer std::allocator_traits<std::allocator<double>>::_S_pointer_helper<std::allocator<double>>(std::allocator<double>*)((std::allocator<double>*)0)), unsigned long>(decltype(std::allocator<double>::pointer std::allocator_traits<std::allocator<double>>::_S_pointer_helper<std::allocator<double>>(std::allocator<double>*)((std::allocator<double>*)0)), unsigned long):
1, include "vector"
63, include "stl_uninitialized.h"
511, Generating implicit acc routine seq
Generating acc routine seq
Generating NVIDIA GPU code
std::string::_M_data() const:
2, include "algorithm"
10, include "algorithm"
62, include "stl_algo.h"
65, include "random"
41, include "string"
52, include "basic_string.h"
293, Generating implicit acc routine seq
Generating acc routine seq
Generating NVIDIA GPU code
std::string::_M_rep() const:
2, include "algorithm"
10, include "algorithm"
62, include "stl_algo.h"
65, include "random"
41, include "string"
52, include "basic_string.h"
301, Generating implicit acc routine seq
Generating acc routine seq
Generating NVIDIA GPU code
NVC++-S-1062-Support procedure called within a compute region - llvm.expect (/home/016950414/test_openacc/main.cpp: 240)
std::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string():
240, Accelerator restriction: unsupported call to support routine 'llvm.expect'
NVC++/x86-64 Linux 23.11-0: compilation completed with severe errors
make[2]: *** [CMakeFiles/a.out.dir/main.cpp.o] Error 2
make[1]: *** [CMakeFiles/a.out.dir/all] Error 2
make: *** [all] Error 2
Using the following HPC and CMake:
module load cmake-3.25.1-gcc-10.2.0-sgz3pso
module load nvhpc/23.11