gpt4 book ai didi

c++ - 如何在 Windows 上使用 MinGW 安装/启用 OpenMP for Eclipse?

转载 作者:行者123 更新时间:2023-11-28 06:05:54 25 4
gpt4 key购买 nike

随着我继续学习 C++,我尝试使用 MinGW 工具链在 Eclipse (C/C++ Mars 4.5.0) 中启用 OpenMP。我只想说我不知道​​该怎么做。将 -fopenmp 标志添加到项目设置中的 C/C++ 编译器选项是不够的。我尝试使用 GNU Make Builder 编译并运行 OpenMP 提供的以下测试代码:

#include <omp.h>
#include <stdio.h>

int main()
{
#pragma omp parallel printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}

Eclipse 吐出以下内容:

Building file: ../OpenMPTest.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -fopenmp -MMD -MP -MF"OpenMPTest.d" -MT"OpenMPTest.d" -o "OpenMPTest.o" "../OpenMPTest.cpp"
../OpenMPTest.cpp: In function 'int main()':
../OpenMPTest.cpp:14:23: error: expected '#pragma omp' clause before 'printf'
#pragma omp parallel printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
^
../OpenMPTest.cpp:15:1: error: expected primary-expression before '}' token
}
^
make: *** [OpenMPTest.o] Error 1

这给我的(可能不正确的)印象是 Eclipse 找不到 OpenMP 库。

因此,在我搞砸任何无法修复的事情之前,我想知道我是否可以得到一份针对白痴的分步指南,以在使用 MinGW 的 Eclipse 项目中安装和启用 OpenMP。

最佳答案

不要在 #pragma 行中放置任何不应存在的内容。#pragma 行是预处理器指令,您的 printf 代码不应该存在。

你的 main() 应该是这样的

int main()
{
#pragma omp parallel
{
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}
return 0;
}

关于c++ - 如何在 Windows 上使用 MinGW 安装/启用 OpenMP for Eclipse?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32416419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com