openmp与mpi

3,366次阅读
没有评论

共计 1896 个字符,预计需要花费 5 分钟才能阅读完成。

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>
正文完
请博主喝杯咖啡吧!
post-qrcode
 
admin
版权声明:本站原创文章,由 admin 2018-05-30发表,共计1896字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码