Tuesday, April 29, 2008

Fortran plus MPI in OSX Tiger

Finally I've got the fortran/mpi stuff running in my macstation. The installation process is very complicated, and so I will be describing it here. First of all, the physics software that we must execute is OpenPIC2, and it must be installed once the running environment is set up.

We need a couple of things in order to run OpenPIC2: we need the fortran compilers up and running, and also an implementation of MPI (the official documents about MPI are available here). To install all that stuff, we'd better use some package installation manager. I recommend two packaging tools: MacPort and Fink. I had to install both, as I need fink to get g77, and I need port to get g95. You can download fink here, and Mac Ports here. Installing these programs in an apple computer is very simple.

Ok, now that we have the package managers up and running, it is time to install the compilers. Let's start with g95:

sudo port -v selfupdate
port -d install g95

This should install g95 in your machine. Actually, there is some other stuff that is pretty useful, and I guess we should install it right now. The first software is rpm, to compile the sources of openmpi, and the second is stow, which helps to organize the software installed.

sudo port -d install rpm
sudo port -d install stow

That should do with the port part of the installation routine. Now, let's get g77, and to do this, we use fink:

fink install g77

It is as easy as this. Now, you probably have two different compilers running in your machine. Fink puts stuff in /sw/bin. You'd better add it to your path. To add it permanently to your path, you can edit /etc/profile.
Good, good. Now comes the turing test for the faint of heart: installing openmpi from source. Actually, you can install it using port, but them it will not enable mpif90, which we need to compile stuff. You can get the source rpm from the openmpi site. I chose openmpi-1.2.6-1.src.rpm. Anyway, download it to your machine, and then do

rpm -i openmpi-1.2.6-1.src.rpm
cd /opt/local/src/macports/SOURCES
sudo tar -jxf openmpi-1.2.6.tar.bz2
cd openmpi-1.2.6
export CXX=g++
export CC=gcc
export F77=g77
export FC=g95
./configure
sudo make
sudo make install prefix=/usr/local/stow/openmpi-1.2.6
cd /usr/local/stow/
sudo stow openmpi-1.2.6

These commands should get openmpi running in your system. To test it, type mpif90 in your command prompt. If this does not report any error message, you can just throw some fireworks; otherwise, I recommending sitting and crying.

To compile the physics software, download this tar ball, and open it somewhere in your machine. You might have to edit your LAM.make file. The one that I have uses the following options:

MPIFC = mpif90
FC90 = g95
FC77 = g77
OPTS90 = -O3 -fno-second-underscore
OPTS77 = -O3 -fno-second-underscore
MOPTS =
LOPTS =
LEGACY =

In order to compile the first example, try:

make -f LAM.make lesopenpic2f77.out

You will probably get a lot of warnings, but do not let them scary you away. To run the program, try:

mpirun -n 2 esopenpic2

You will get a bunch or numbers. Do not ask me what are they about, but it looks right from my 600m distance.

1 Comments:

Blogger Jeff Squyres said...

FWIW, the official MPI site is http://www.mpi-forum.org/, not the Argonne site.

:-)

3:12 PM  

Post a Comment

<< Home