How to compile OpenMP and MPI hybrid C program on OS X
<p>I was testing a HelloWorld C program that mixes OpenMP and MPI on my Macbook Pro. </p>

<p>Compiling with <code>mpicc -fopenmp helloworld.c -o helloworld</code> or <code>mpicc -openmp helloworld.c -o helloworld</code> both give me an error message <code>fatal error: 'omp.h' file not found</code>. </p>

<p>If I compile only the MPI part with <code>mpicc helloworld.c -o helloworld</code>, or only the OpenMP part with <code>gcc -fopenmp helloworld.c -o helloworld</code>, it worked just fine. </p>

<p>I looked up in SO and I've seen people successfully compile in Linux so I was wondering if this is an issue for OS X only. Should I use a different flag for OS X other than <code>-openmp</code> or <code>-fopenmp</code>? I am using OpenMPI-1.10.0 with OS X El Capitan (10.11.1).</p>

<p>The simple HelloWorld program code is given as below and the steps I followed is on <a href="http://www.slac.stanford.edu/comp/unix/farm/mpi_and_openmp.html" rel="nofollow noreferrer">this page</a>:</p>

<pre><code>#include &lt;stdio.h&gt;
#include "mpi.h"
#include &lt;omp.h&gt;

int main(int argc, char *argv[]) {
  int numprocs, rank, namelen;
  char processor_name[MPI_MAX_PROCESSOR_NAME];
  int iam = 0, np = 1;

  MPI_Init(&amp;argc, &amp;argv);
  MPI_Comm_size(MPI_COMM_WORLD, &amp;numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
  MPI_Get_processor_name(processor_name, &amp;namelen);

  #pragma omp parallel default(shared) private(iam, np)
  {
    np = omp_get_num_threads();
    iam = omp_get_thread_num();
    printf("Hello from thread %d out of %d from process %d out of %d on %s\n",
           iam, np, rank, numprocs, processor_name);
  }

  MPI_Finalize();
}
</code></pre>