我正在學習並行計算,並已開始與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})
我錯過了什麼?