From charlesreid1

Revision as of 22:36, 18 May 2011 by Admin (talk | contribs)

Installing

Prerequisites

OpenMPI forces you to install bindings for Fortran (which is a bummer, since Fortran is a mess on Mac OS X and I don't plan on using MPI bindings for Fortran anyway).

So before installing OpenMPI, you must first install a Fortran compiler. I stuck with Gfortran.

Mac Leopard (OS X 10.5)

For 10.5, I installed LAM MPI. It has since been dropped in favor of OpenMPI.

Mac Snow Leopard (OS X 10.6)

The following is my configure line to configure OpenMPI:

#!/bin/sh

./configure \
    --prefix=${HOME}/pkg/openmpi/1.4.3 \
    CC="/usr/bin/gcc" \
    CXX="/usr/bin/g++" \
    F77="/usr/local/bin/gfortran" \
    \
    CXXFLAGS="-arch x86_64" \
    CCFLAGS="-arch x86_64" \
    F77FLAGS="-arch x86_64"

Note that OpenMPI is picky about compilers.

First, you have to specify exactly which compiler you want to use: you shouldn't say gcc, you should say /usr/bin/gcc.

Second, you have to specify architecture flags for all of the compilers. This is important, because otherwise the compilers will have problems by either producing 32-bit binaries, or maybe one compiler will produce a 64-bit binary and another will produce a 32-bit binary, etc.

If you want to be able to build both 32-bit and 64-bit binaries, then normally you can use the techniques specified at the page Compiling_Software#Compiler_Specifications.

However, if you try and specify two architectures for the compiler, like this:

#!/bin/sh

./configure \
    --prefix=${HOME}/pkg/openmpi/1.4.3 \
    CC="/usr/bin/gcc -arch x86_64 -arch i386" \
    CXX="/usr/bin/g++ -arch x86_64 -arch i386" \
    F77="/usr/local/bin/gfortran -arch x86_64 -arch i386" \
    \
    CPP="/usr/bin/gcc -E" \
    CXXCPP="/usr/bin/g++ -E"

then the "make" process will fail with an error, something like "Bad registers" during the linking process.

The alternative is to create separate builds of OpenMPI: a 32-bit build, and a 64-bit build. For each, you can specify CFLAGS="-arch i386" or CFLAGS="-arch x86_64", and install them to different locations.

Errors

C and Fortran 77 Compilers Not Link Compatible

When I first installed OpenMPI on Snow Leopard, I saw an error like this:

checking if C and Fortran 77 are link compatible... no
**********************************************************************
It appears that your Fortran 77 compiler is unable to link against
object files created by your C compiler.  This typically indicates
one of a few possibilities:

  - A conflict between CFLAGS and FFLAGS
  - A problem with your compiler installation(s)
  - Different default build options between compilers (e.g., C
    building for 32 bit and Fortran building for 64 bit)
  - Incompatible compilers

Such problems can usually be solved by picking compatible compilers
and/or CFLAGS and FFLAGS.  More information (including exactly what
command was given to the compilers and what error resulted when the
commands were executed) is available in the config.log file in this
directory.
**********************************************************************
configure: error: C and Fortran 77 compilers are not link compatible.  Can not continue.

Digging into config.log showed this error:

onfigure:35860: checking if C and Fortran 77 are link compatible
configure:35910: /usr/bin/gcc -c -O3 -DNDEBUG -finline-functions -fno-strict-aliasing  conft
est_c.c
configure:35917: $? = 0
configure:35944: /usr/local/bin/gfortran -o conftest   conftest.f conftest_c.o  >&5
ld: warning: in conftest_c.o, file was built for unsupported file format which is not the architecture being linked (i386)

The problem was twofold: first, I needed to compile 64-bit binaries iwth the C compiler, which wasn't happening, because it was trying to create an i386 binary. Second, the fortran copmiler was producing an "unsupported file format".

I fixed the problem by adding the "-arch x86_64" flag to both the C and Fortran compilers.