【发布时间】:2018-03-19 19:32:55
【问题描述】:
我正在学习并行计算,并开始了我的 OpenMP 和 C 之旅。
我一直在配置 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 toomp_get_num_threads'
C:/Users/John/CLionProjects/Parallelexamples/main.c:7: 未定义对“omp_get_thread_num”的引用
collect2.exe:错误:ld 返回 1 退出状态
mingw32-make.exe[2]: * [Parallelexamples.exe] 错误 1
CMakeFiles\Parallelexamples.dir\build.make:95:目标“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})
我错过了什么吗?
【问题讨论】: