编译 openmp、macports gcc 和 eclipse cdt [英] compiling openmp, macports gcc, and eclipse cdt
问题描述
我是 openmp 的新手.以下是环境.
I am newbie in openmp. The following is the environment.
操作系统:Mac OSX 小牛队
编译器:gcc (MacPorts gcc48 4.8.2_0) 4.8.2
IDE : Eclipse Kepler CDT 插件
OS : Mac OSX Mavericks
Compiler : gcc (MacPorts gcc48 4.8.2_0) 4.8.2
IDE : Eclipse Kepler CDT plugin
我写了下面的openmp程序
I wrote the following openmp program
#include < stdio.h>
#include < omp.h>
int main()
{
#pragma omp parallel
{
int i=omp_get_thread_num();
printf("hello (%d)",i);
printf("world (%d)",i);
}
}
我编译了上面的程序,得到了找不到 omp.h 和找不到 lgomp 的错误.因此,我在项目属性中添加了一个包含路径/opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.2/include 和一个库路径/opt/local/lib/gcc48.包含路径包含 omp.h 文件,库路径包含文件 libomp.o.
I compiled the above program and got the error that omp.h is not found and lgomp not found. Hence I added in the project properties an include path with /opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.2/include and a library path /opt/local/lib/gcc48. The include path had the omp.h file and the library path had the file libomp.o.
我通过项目属性在链接器和编译器选项中包含 -fopenmp 选项.它正在编译 gcc -I/opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.2/include -O0 -g3 -Wall -c -fmessage-length=0 -fopenmp -MMD -MP -MF"src/OpenMPCourseExamples.d" -MT"src/OpenMPCourseExamples.d" -o "src/OpenMPCourseExamples.o" "../src/OpenMPCourseExamples.c" 并使用命令链接 "gcc -L/opt/local/lib/gcc48 -fopenmp -o "OpenMPCourseExamples" ./src/OpenMPCourseExamples.o".
I include the -fopenmp option in both the linker and the compiler option through project properties. It is compiling with gcc -I/opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.2/include -O0 -g3 -Wall -c -fmessage-length=0 -fopenmp -MMD -MP -MF"src/OpenMPCourseExamples.d" -MT"src/OpenMPCourseExamples.d" -o "src/OpenMPCourseExamples.o" "../src/OpenMPCourseExamples.c" and linking with the command "gcc -L/opt/local/lib/gcc48 -fopenmp -o "OpenMPCourseExamples" ./src/OpenMPCourseExamples.o".
使用上面的命令,它编译没有错误,但有警告 - 警告:未知编译指示被忽略 [-Wunknown-pragmas] #pragma omp parallel".
With the above command it compiles without an error but with a warning - "warning: unknown pragma ignored [-Wunknown-pragmas] #pragma omp parallel".
此外,我在启动属性中设置了一个环境变量,其中 OMP_NUM_THREADS=4.我运行了使用上述警告编译的程序.我只得到你好(0)世界(0)".我的印象是我应该启动四个线程,并且应该以某种顺序看到hello(1)world(1)hello(2)world(2)hello(3)world(3)"的其他输出.现在,这是我的以下问题.
Also, I set an environment variable in the launch properties with OMP_NUM_THREADS=4. I ran the program that compiled with the above warning. I am getting only "hello (0)world (0)". I was under the impression that I should start four threads and should see the other outputs of "hello(1)world(1)hello(2)world(2)hello(3)world(3)" in some ordering as well. Now, here are my following questions.
- 为什么我会收到 #pragma 警告?
- 编译器是否真的检测到 openmp 并使用 openmp 进行构建?
- 如果一切都正确,为什么我没有看到四个不同的线程开始?
推荐答案
MacPorts 使用 --program-suffix=-mp-${major}
配置 GCC 构建过程,因此所有编译器可执行文件都有-mp-4.8
后缀.当您调用 gcc
时,您最终会使用 Apple 的 Clang 编译器,该编译器不支持 OpenMP,因此无法识别 -fopenmp
选项和 #pragma omp ...
.
MacPorts configures the GCC build process with --program-suffix=-mp-${major}
and therefore all compiler executables have the -mp-4.8
suffix. When you call gcc
, you end up using Apple's Clang compiler, which does not support OpenMP and therefore does not recognise the -fopenmp
option and #pragma omp ...
.
您必须对项目设置进行以下更改:
You have to do the following changes to the project settings:
- 将编译器命令改为
gcc-mp-4.8
- 将链接器命令更改为
gcc-mp-4.8
- 删除包含和库路径的显式规范,因为
-fopenmp
的存在会自动添加它们.
- Change the compiler command to
gcc-mp-4.8
- Change the linker command to
gcc-mp-4.8
- Remove the explicit specification of the include and library paths since the presence of
-fopenmp
adds them automatically.
这篇关于编译 openmp、macports gcc 和 eclipse cdt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!