• 为了保证你在浏览本网站时有着更好的体验,建议使用类似Chrome、Firefox之类的浏览器~~
    • 如果你喜欢本站的内容何不Ctrl+D收藏一下呢,与大家一起分享各种编程知识~
    • 本网站研究机器学习、计算机视觉、模式识别~当然不局限于此,生命在于折腾,何不年轻时多折腾一下

openmp与mpi

C++ admin 2年前 (2018-05-30) 851次浏览 0个评论 扫描二维码

I’ve been taking the course Parallel Computing this semester, and I’m also participating in some student cluster competitions. Therefore, I wanted to configure OpenMP and MPI on my Mac to run some OpenMP and MPI programs. This post describes how I successfully configured OpenMP and MPI with Homebrew.

Pre-requisite

Make sure you have Homebrew installed on your Mac. Homebrew is a package manager for macOS. It is in some way similar to package managers in Linux distributions, such as apt-get and yum. It’s very easy to install, just go to their website and follow the steps.

Remember to run brew update before you continue.

Installing OpenMP

One thing you should know is that OpenMP is not really a package that you install on your computer. Instead, it’s part of the compiler. Therefore, what we need to do is to compile a compiler with OpenMP support. We’ll use Homebrew to build the GNU Compiler Collection (GCC) on our Mac from source, with OpenMP support. To do that, type in the following command

$ brew install gcc --without-multilib

If you have installed gcc before on your Mac using Homebrew, then reinstall it with the following command

$ brew reinstall gcc --without-multilib

According to my experience, it takes about half an hour to one hour to build gcc since it’s quite a large piece of program. Just be patient. After you installed it, you should be able to compile programs with OpenMP support with

gcc-6 -fopenmp

Installing MPI

MPI is only an interface. Therefore, there are several MPI implementations, such as MPICH, OpenMPI, and Intel MPI. In this post, we’ll install OpenMPI. Here we also want to build it from source because then our MPI compiler is using the gcc we built just now with OpenMP support. If you installed the binary distribution, it’s compiled with clang without any OpenMP support. To build OpenMPI, type in the following command

$ brew install openmpi --build-from-source --cc=gcc-6

This command forces Homebrew to build OpenMPI from source with the gcc-6 compiler. (On Mac, the brewed gcc has the name gcc-6 to avoid name clash with the system link gcc that is in your Mac)

Now you should have OpenMPI installed on your Mac, with OpenMP support! To compile any MPI programs, just type

$ mpicc <your source code>

Deeplearn, 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明openmp 与 mpi
喜欢 (0)
admin
关于作者:
互联网行业码农一枚/业余铲屎官/数码影音爱好者/二次元

您必须 登录 才能发表评论!