Built-in OpenMPI in Leopard

As many of you may know, OpenMPI is now bundled as part of a standard install of Leopard. OpenMPI is a very recent incarnation of the message-passing infrastructure for parallel programming. Older and possibly more commonly known versions of MPI are MPICH and LAM-MPI. What is really cool about OpenMPI - especially for Mac users - is that it fully supports Apple's Xgrid! So, you can deploy your parallel tasks exactly the same way you run your batch jobs on Xgrid.

This article is meant to introduce you the very basics of using OpenMPI on Leopard. It assumes you know that MPI is and what exactly it is meant for.

Lets start with a simple MPI sample code shown below. Copy paste this code into a file, called (say) mpicode.c

/* MPI C Example */
#include <stdio.h>
#include <mpi.h>

int main (argc, argv)
    int argc;
    char *argv[];
 int rank, size;

 MPI_Init (&argc, &argv);       /* starts MPI */
 MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */
 MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */
 printf( "Hello world from process %d of %d\n", rank, size );
 return 0;

Now, the first step is to compile this code and link it with the OpenMPI libraries. This couldn't be simpler on Leopard (you'll need to have Xcode 3.0 installed). Everything is already in place and ready to use. All you have to do is type:

mpicc mpicode.c -o mpiapp

This will create an OpenMPI binary called mpiapp. Next, lets launch this binary using Apple's Xgrid. I'm assuming you have access to an Xgrid based network, for example the OpenMacGrid. You can launch this MPI executable using the familiar mpirun command using the command-line. I'll refer you to the second half of this article by fellow MacResearcher, Drew McCormack for that approach. Essentially, you need to set up two environmental variables XGRID_CONTROLLER_HOSTNAME and XGRID_CONTROLLER_PASSWORD to the appropriate values. However, in this article we'll use an Xgrid related, GUI based application to launch this binary.

If you have Xcode 3.0 installed, you have all the pieces you need to build a nice application that can access your Xgrid, submit MPI tasks and download the results after completion. Navigate to /Developer/Examples/Xgrid/GridSample. Double-click on the Xcode project there and create the sample applications by simply clicking build. In a few minutes, you'll see three applications appear in /Developer/Examples/Xgrid/GridSample/build/Release. The one you need is called Xgrid MPI Sample.

Launch this application, simply by double-clicking. A simple, yet neat looking GUI window opens that will prompt you to enter your Xgrid related information. Then simply follow the simple steps to submit your MPI job mpiapp, choosing the appropriate number of processors. Your job will be submitted and run when the requested number of agents are available. You can check the status and even retrieve results in this same applications by clicking on the appropriate buttons on the application's menu bar. If everything worked fine, you'll see the following output:

Hello world from process 0 of 4
Hello world from process 1 of 4
Hello world from process 2 of 4
Hello world from process 3 of 4

Have fun!


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Intel compilers ?

Is it possible to use the intel compilers with the version that is builtin or do you need to recompile the openmpi package ?

I haven't tried myself ..

But look in /usr/share/openmpi. In particular the file called mpicc-wrapper-data.txt and change the gcc there to icc.