今天弄了半天才弄好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. 【C++深入浅出】智能指针之auto_ptr学习

    起:  C++98标准加入auto_ptr,即智能指针,C++11加入shared_ptr和weak_ptr两种智能指针,先从auto_ptr的定义学习一下auto_ptr的用法. template& ...

  2. mac下烦人的eclipse安装svn插件

    eclipse作为一个鸡肋般的java ide,颇有食之无味弃之可惜之感.最近公司统一对电脑做了一些处理,搞的我的eclipse都不能用了.重新安装了一下,各种maven.svn,代码格式什么的依赖神 ...

  3. 【转载】Android Studio 设置内存大小及原理

    http://www.cnblogs.com/justinzhang/p/4274985.html http://tsroad.lofter.com/post/376316_69363ae Andro ...

  4. hdu 5459 Jesus Is Here 数学

    Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  5. Android多媒体-人脸识别

    1. 相关背景 Google 于2006年8月收购Neven Vision 公司 (该公司拥有 10 多项应用于移动设备领域的图像识别的专利),以此获得了图像识别的技术,并不是常快应用到免费的 Pic ...

  6. Android ADB使用之详细篇

    Android开发环境中,ADB是我们进行Android开发经常要用的调试工具,它的使用当然是我们Android开发者必须要掌握的. ADB概述 Android Debug Bridge,Androi ...

  7. [COCOS2DX]交叉编译实践+速度优化(vs2012修改win32代码+修改makefile+编译安卓项目包+部署安卓项目包到Eclipse+运行apk)

    通过前面的部署过程可以知道cocos2dx的开发过程如下: 1.VS2012完成修改 2.因为指定了CPP文件位置,ndk可以通过jni方式完成C++文件的编译,运行以下命令完成proj.androi ...

  8. Android_listView_BaseAdapter

    layout.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x ...

  9. ajax数据保存及解析

    1.   $('#frmCam').serialize():serialize() 方法通过序列化表单值,创建 URL 编码文本字符串. 2.自动对应ID和值 window.camConfig = [ ...

  10. linux云计算集群架构学习笔记:workstation 12.0 按装Red Hat Enterprise Linux 7(64位)

    安装RHEL7.2 步骤: 1.安装虚拟机,按以下截图安装即可  步骤2: Ret hat 7.2 操作系统安装 rhel7因为许可报错解决