我正在学习并行计算,并已开始与OpenMP和C的旅程。Clion和OpenMP
我一直在配置Clion,但没有运气。
#include <stdio.h>
#include <omp.h>
int main() {
#pragma omp parallel
{
int n = omp_get_num_threads();
int tid = omp_get_thread_num();
printf("There are %d threads. Hello from thread %d\n", n, tid);
};
/*end of parallel section */
printf("Hello from the master thread\n");
}
但我正在此错误:
在功能main': C:/Users/John/CLionProjects/Parallelexamples/main.c:6: undefined reference to
omp_get_num_threads' C:/Users/John/CLionProjects/Parallelexamples/main.c:7:未定义参考` omp_get_thread_num' collect2.exe:error:ld returned 1 exit status mingw32-make.exe [2]:* [Parallelexamples.exe] Error 1 CMakeFiles \ Parallelexamples.dir \ build.make:95:recipe for target' Parallelexamples.exe”失败 mingw32-make.exe [1]:* [CMakeFiles/Parallelexamples.dir/all]错误2 CMakeFiles \ Makefile2:66:目标'CMakeFiles/Parallelexamples.dir/all'失败的配方 Makefile:82:配方对于目标 '所有' 失败 的mingw32-的make.exe:*** [全部]错误2
我按照指示,使我CMakeListtxt文件是这样的:
cmake_minimum_required(VERSION 3.8)
project(Parallelexamples)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu11 -fopenmp")
set(SOURCE_FILES main.c)
add_executable(Parallelexamples ${SOURCE_FILES})
我错过了什么?