今天弄了半天才弄好mac上的openmp,一方面智商下限,另一方面竟然发现网上也没有什么详细过程,特意把我的配置过程贴上来

多核编程可以认为是对多线程编程做了一定程度的抽象,提供一些简单的API,使得用户不必花费太多精力来了解多线程的底层知识,从而提高编程效率。这两天关注的多核编程的工具包括openMP和TBB。按照目前网上的讨论,TBB风头要盖过openMP,比如openCV过去是使用openMP的,但从2.3版本开始抛弃openMP,转向TBB。但我试下来,TBB还是比较复杂的,相比之下,openMP则非常容易上手。因为精力和时间有限,没办法花费太多时间去学习TBB,就在这里分享下这两天学到的openMP的一点知识,和大家共同讨论。

openMP支持的编程语言包括C语言、C++和Fortran,支持OpenMP的编译器包括Sun Studio,Intel Compiler,Microsoft Visual Studio,GCC。

Microsoft Visual Studio上OpenMP的配置

总共分2步:

  • 新建一个工程。这个不再多讲。
  • 建立工程后,点击 菜单栏->Project->Properties,弹出菜单里,点击 Configuration Properties->C/C++->Language->OpenMP Support,在下拉菜单里选择Yes。 至此配置结束。

Using clang-omp with Xcode

  • Install clang-omp using homebrew:
  • brew install clang-omp
  • Create a new Xcode project.
  • Under click 'the name of the project' —> Build Settings
    • Editor --> Add Build Setting --> Add User-Defined Setting (Press ‘delete’ on the keyboard to delete the user-defined setting when you do not want it)

      • set the setting name as CC
      • set its value as /usr/local/bin/clang-omp

    • Add -fopenmp to Other C Flags
    • Add /usr/local/include to Header Search Paths
    • Set Enable Modules (C and Objective-C) to No.
  • Under Build Phases
    • Add /usr/local/lib/libiomp5.dylib to Link Binary With Libraries
  • Done. You can now #include <libiomp/omp.h> and start using #pragma omp ... in your source code.

测试编译器和环境配置是否成功的代码如下:

#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());
}
/* OUTPUT:
Hello from thread 0, nthreads 4
Hello from thread 3, nthreads 4
Hello from thread 2, nthreads 4
Hello from thread 1, nthreads 4
Program ended with exit code: 0
*/

You should see more than one "Hello" line with different thread numbers. Note that the lines may be mixed together. If you see only one, try setting the environment variable OMP_NUM_THREADS to some number (say 4) and try again.

[openMP] OpenMP在visual studio和mac上的配置的更多相关文章

  1. Visual Studio for Mac 初体验

    你喜爱的 IDE,现在可用于 Mac 来自:https://www.visualstudio.com/zh-hans/vs/visual-studio-mac/ 惊不惊喜?意不意外?惊喜但不意外,因为 ...

  2. Visual Studio for Mac

    Visual Studio for Mac 初体验   你喜爱的 IDE,现在可用于 Mac 来自:https://www.visualstudio.com/zh-hans/vs/visual-stu ...

  3. Xamarin+Prism开发详解四:简单Mac OS 虚拟机安装方法与Visual Studio for Mac 初体验

    Mac OS 虚拟机安装方法 最近把自己的电脑升级了一下SSD固态硬盘,总算是有容量安装Mac 虚拟机了!经过心碎的安装探索,尝试了国内外的各种安装方法,最后在youtube上找到了一个好方法. 简单 ...

  4. Visual Studio for Mac 简介

    2016-12-13 Hutchinson 微软中国MSDN 在 11 月举行的 Connect(); 上,Microsoft 将推出 Visual Studio for Mac 预览版.这是一个激动 ...

  5. Install Visual Studio For Mac Preview

    在Hack News上看到Visual Studio For Mac Preview的链接,上面有许多评论,纪录下尝鲜安装过程. 第一次尝试 VisualStudioforMacPreviewInst ...

  6. 在Visual Studio for Mac中使用fastlane管理iOS的provision

    Xamarin开发中,最烦的就是provision的管理了. 全手工的话,要先创建一个key,上传后生成cert文件,再创建provision.如果在手机上调试,还要把手机加到provision中去. ...

  7. Visual Studio for mac从入门到放弃1

    MAC  第一步:从微软官网下载:https://www.visualstudio.com/vs/visual-studio-mac/ 第二步:安装软件过程出现 It was not possible ...

  8. Visual Studio for Mac 安装

    有一周时间没有更新博客了,最近这段时间真是苦不堪言,上周四晚上,一杯水将我的MBP报废掉了,开机状态,键盘进水,当场就关机了,很担心当时爆炸了,幸好还只是关机,然后就...没有然后了.第二天插电源可以 ...

  9. 在 Visual Studio for Mac 中编译和生成

    使用Visual Studio将C#生成DLL文件的方法 https://www.cnblogs.com/AaronBlogs/p/6840283.html Visual Studio 开发 - Vi ...

随机推荐

  1. VM使用标准交换机

    1.新建模板: 网卡选择“未连接”,此处看不到“标准交换机”选项

  2. 【转】rvm安装ruby,gem,rails,之后仍然无法找到rails命令

    转自:http://chinacheng.iteye.com/blog/1738036 rvm安装ruby和rails之后,ruby -v好使,gem -v好使.但是rails -v不好使,提示没有安 ...

  3. MmSystem播放Wav格式声音

    //MmSystem播放Wav格式声音 //MmSystem 支持 *.wav声音格式 snd ->SoundRecorderuses MmSystem; //引用MmSystem//播放系统声 ...

  4. VMWare9下基于Ubuntu12.10搭建Hadoop-1.2.1集群

    VMWare9下基于Ubuntu12.10搭建Hadoop-1.2.1集群 下一篇:VMWare9下基于Ubuntu12.10搭建Hadoop-1.2.1集群-整合Zookeeper和Hbase 近期 ...

  5. Java下拼接运行动态SQL语句

    mod=viewthread&tid=3039" target="_blank">Java拼接动态SQL的一般做法有       1.使用动态语句 非常多数 ...

  6. iOS开发——开发技巧&Git常用命令

    Git常用命令 初始化git init        加—bare实现远程仓库 配置git config user.name iCocos 配置全局git config —global user.na ...

  7. [000]socket通信--server和client实现的简单例子

    在C语言中就学过scanf和printf,其实理解socket就跟这两个输入输出差不多,只不过是信息的传输而已. 1.TCP服务器端(server)的默认函数调用顺序: 按照上述的调用顺序,我们可以来 ...

  8. Gaussian Discriminant Analysis

    如果在我们的分类问题中,输入特征$x$是连续型随机变量,高斯判别模型(Gaussian Discriminant Analysis,GDA)就可以派上用场了. 以二分类问题为例进行说明,模型建立如下: ...

  9. 结合 category 工作原理分析 OC2.0 中的 runtime

    绝大多数 iOS 开发者在学习 runtime 时都阅读过 runtime.h 文件中的这段代码: struct objc_class { Class isa  OBJC_ISA_AVAILABILI ...

  10. CentOS内核升级

    CentOS 6.5自动内核升级的主要步骤: 1)内核文件下载到/usr/src/kernel/目录下: 如:2.6.32-431.5.1.el6.x86_64编译后差不多有48M大小: 2)生成的引 ...