I am using Ubuntu and have the following C++ code
#include <iostream>
#include <omp.h>
#define numPI 10000000000
using namespace std;
int main(void) {
std::cout<<"calculate pi..\n";
double pi = 0.0f; long i; long j;
double st = omp_get_wtime();
#pragma acc parallel loop
for (i=0; i<numPI; i++) {
double t= (double)((i+0.5)/numPI);
pi +=4.0/(1.0+t*t);
}
double runtime = omp_get_wtime() - st;
printf("ACC: %f s\n", runtime);
st = omp_get_wtime();
pi=0.0;
for (i=0; i<numPI; i++) {
double t= (double)((i+0.5)/numPI);
pi +=4.0/(1.0+t*t);
}
runtime = omp_get_wtime() - st;
printf("serial: %f s\n", runtime);
return 0;
}
it runs just fine with pgc++ -fast -ta=nvidia:cuda9.2,managed -Minfo=accel -o exampleOpenACC.cpp exampleOpenACC -std=c++11 -mp && ./exampleOpenACC
However, I want to be able to compile it with Cmake. I tried the following for CMakeLists.txt
:
cmake_minimum_required(VERSION 3.5)
project( exampleOpenACC )
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
SET(CMAKE_CXX_COMPILER /opt/pgi/linux86-64/19.10/bin/pgc++)
add_definitions("-DENABLE_SSE")
set(CMAKE_CXX_FLAGS
"${SSE_FLAGS} -O3 -g -std=c++11 -march=native -ta=nvidia:cuda9.2,managed -Minfo=accel"
)
set(CMAKE_C_FLAGS
"${SSE_FLAGS} -ta=tesla:cc50 -Minfo=accel"
)
find_package(OpenACC REQUIRED)
add_executable( exampleOpenACC exampleOpenACC.cpp)
target_compile_options(openacc-test PRIVATE ${OpenACC_CXX_FLAGS})
target_link_libraries(exampleOpenACC)
target_compile_features(exampleOpenACC PRIVATE cxx_range_for)
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
but when I hit cmake .
, I get:
by not providing FindOpenACC.cmake in CMAKE_MODULE_PATH this project asked Cmake to find a package configuration file provided by OpenACC but Cmake did not find one
Could not find a package configuration provided by OpenACC with any of the following names:
OpenACCConfig.cmake
openacc-config.cmake
Add the installation prefix of "OpenACC" to CMAKE_PREFIX_PATH or set "OpenACC_DIR" to a directory containing one of the above files. If "OpenACC" provides a separate development package or SDK, be sure it has been installed.
How should I set CMakeLists.txt
so the code compiles with pgc++?