Search code examples
xcodemacososx-lionparallel-processingopenmpi

How do I compile openmpi programs using xcode 4?


I'm using lion and xcode 4.2. I installed openmpi using macports. It all installed successfully.

I cannot, however find a guide to tell me how/which libraries to include to compile an example (see below)

#include <mpi.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    int numprocs;
    int myid;
    MPI_Status stat; 

    /* all MPI programs start with MPI_Init */
    MPI_Init(&argc,&argv);     

    /* Comm_size tells us how many processes there are  */
    MPI_Comm_size(MPI_COMM_WORLD,&numprocs); 

    /* Comm_rank finds the rank of the process */
    MPI_Comm_rank(MPI_COMM_WORLD,&myid); 

    /* Print out a message */
    printf("Hello world, from process %d of %d\n", myid, numprocs);  

    /* MPI Programs end with MPI Finalize; this is a weak synchronization point */
    MPI_Finalize(); 

    return 0; 
} 

Xcode reports that mpi.h is missing.


Solution

  • Open-mpi has a walkthrough to do exactly this. Here you go.