如何设置OpenMP? [英] How to set up OpenMP?

查看:561
本文介绍了如何设置OpenMP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用代码块,并且必须运行OpenMP C程序.因此,我在代码块(编译器设置)中添加了标志-fopenmp,现在出现错误" mingw32-g ++.exe:错误:libgomp.spec:没有这样的文件或目录"

I am using Codeblocks and have to run an OpenMP C program. So, I added the flag -fopenmp in Codeblocks (compiler settings) and am now getting the error of 'mingw32-g++.exe: error: libgomp.spec: No such file or directory'

因此,在Internet上对错误进行了一些搜索之后,我下载了TDM-GCC(安装在C:\ TDM-GCC-64中).但是在代码块上仍然显示相同的错误.

So after a bit of searching on the internet about the error, I downloaded TDM-GCC ( installed in C:\TDM-GCC-64). But still the same error is being shown on Codeblocks.

我在做什么错了?

以下是构建日志:

mingw32-gcc.exe -c"D:\ Language Files \ MatrixMultiplication.c" -o"D:\ Language Files \ MatrixMultiplication.o"

mingw32-gcc.exe -c "D:\Language Files\MatrixMultiplication.c" -o "D:\Language Files\MatrixMultiplication.o"

mingw32-g ++.exe -o"D:\ Language Files \ MatrixMultiplication.exe""D:\ Language Files \ MatrixMultiplication.o" -fopenmp

mingw32-g++.exe -o "D:\Language Files\MatrixMultiplication.exe" "D:\Language Files\MatrixMultiplication.o" -fopenmp

mingw32-g ++.exe:错误:libgomp.spec:没有这样的文件或目录

mingw32-g++.exe: error: libgomp.spec: No such file or directory

推荐答案

有多种可能的原因:您未在编译器中安装OpenMP,或者在Code :: Blocks配置中出错.无论如何,请执行以下步骤,您应该可以对其进行修复.您似乎在Windows上工作,但我还添加了有关如何在Linux上进行操作的说明.

There are multiple possible causes for this: Either you did not install OpenMP with the compiler or you made a mistake in the Code::Blocks configuration. Anyways go through the following steps and you should be able to fix it. You seem to be working on Windows but I also added remarks on how to do it on Linux.

1)您将需要OpenMP随附的编译器.对于Windows 下载TDM-GCC 最好是64位可执行文件(第二个文件)并安装.确保在组件选项卡中选择 OpenMP : Components> gcc(TDM当前:..)> OpenMP (最后一个条目). Linux已经附带了GCC,因此只需打开命令行并在终端中键入 sudo apt-get install libomp-dev 即可获得OpenMP.

1) You will need a compiler that comes with OpenMP. For Windows download TDM-GCC preferably the 64-bit executable (second file) and install it. Make sure you select OpenMP in the component tab: Components > gcc (TDM current: ....) > OpenMP (the last entry). Linux already comes with GCC so just open the command line and get yourself OpenMP by typing sudo apt-get install libomp-dev in the terminal.

2)您现在必须在Code :: Blocks 中配置编译器:转到选定的编译器"下的"<设置>编译器" ,选择" GNU GCC编译器" em>,然后单击 Copy ,然后为新的编译器(如 TDM-GCC编译器)键入一个方便的名称.转到工具链可执行文件,并浏览所有程序文件(C编译器,C ++编译器,链接器,调试器,资源编译器,Make)的目录,您应该能够找到它们如果选择默认安装,请在Windows计算机上的 C:\ TDM-GCC-64 \ ... \ bin 中.在Linux机器上工作时,我无法告诉您确切的子目录,但是您应该可以很容易地找到它.根据您的安装,可能有两个32位和64位文件夹.对于Linux,此步骤不是必需的.

2) You will have to configure the Compiler in Code::Blocks now: Go to Settings > Compiler under Selected Compiler select GNU GCC Compiler and click Copy and type in a convenient name for your new compiler such as TDM-GCC Compiler. Go to Toolchain executables and browse the directory for all the Program files (C compiler, C++ compiler, Linkers, Debugger, Resource compiler, Make) you should be able to find them in C:\TDM-GCC-64\ ...\bin on a Windows machine if you chose the default installation. I can't tell you the precise sub-directory as I working on a Linux machine but you should be able to find it pretty easily. Depending on your installation there might be two folders for 32- and 64-bit. For Linux this step is not necessary.

4)然后,您需要设置链接器设置.可以通过上述菜单中的以下步骤对所有项目(我不建议这样做)或单击 Project> Build options 对您当前的项目进行此操作.转到相应配置( Debug Release )的链接器设置,然后单击链接库下的添加 .在Windows计算机上,您需要浏览名为 libgomp-1.dll (32位)或 libgomp_64-1.dll (64位)的文件,该文件应为位于与上述程序文件相同的文件夹中.在Linux下,改为在其他链接器选项下选择 -lgomp .

4) Then you need to set the Linker settings. This can be done for all projects (which I would not recommend) by doing the following steps in the aforementioned menu or for your current project by clicking Project > Build options. Go to Linker settings of the corresponding configuration (Debug or Release) and click Add under Link libraries. On a Windows machine you will need to browse a file called libgomp-1.dll (32-bit) or libgomp_64-1.dll (64-bit) which should be located in the same folder as the aforementioned Program files. Under Linux instead choose -lgomp under Other linker options.

3)通过转到编译器设置>其他编译器选项设置编译器标志 -fopenmp (对于所有项目或仅用于当前项目) em>并在其中输入-fopenmp.

3) Set the compiler flag -fopenmp (for all the projects or only the current one) by going to Compiler settings > Other compiler options and typing in there -fopenmp.

4)使用 OpenMP"Hello World ".

这篇关于如何设置OpenMP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆