dependencies.rb: Add MPI compiler Requirement

All versions of OS X prior to Lion shipped with some version of Open-MPI, but
without working compiler wrappers for Fortran. Homebrew currently has two
formulae that can supply this software: open-mpi and mpich2.

This commit adds a `MPIDependency` Requirement that can be passed one of four
values when constructed:

    :cc, :cxx, :f90, :f77

This will ensure the `mpi<value>` compiler is available and working. For
example, if `depends_on MPIDependency.new(:cc, :f90)` is used, the Requirement
will search for working `mpicc` and `mpif90` wrappers.

If the required wrappers cannot be found, an error message will be displayed
that prompts the user to install one of the Homebrew formulae that provides
MPI.

For each language passed to a MPIDependency Requirement, environment variables
be will set that point to the compilers.

Signed-off-by: Charlie Sharpsteen <source@sharpsteen.net>
This commit is contained in:
Charlie Sharpsteen 2012-07-06 11:47:45 -08:00
parent 96ee0e90cc
commit 0d3578b28d

View File

@ -204,3 +204,86 @@ class X11Dependency < Requirement
end
end
class MPIDependency < Requirement
attr_reader :lang_list
def initialize *lang_list
@lang_list = lang_list
@non_functional = []
@unknown_langs = []
end
def fatal?; true; end
def mpi_wrapper_works? compiler
compiler = which compiler
return false if compiler.nil? or not compiler.executable?
# Some wrappers are non-functional and will return a non-zero exit code
# when invoked for version info.
#
# NOTE: A better test may be to do a small test compilation a la autotools.
quiet_system compiler, '--version'
end
def satisfied?
@lang_list.each do |lang|
case lang
when :cc, :cxx, :f90, :f77
compiler = 'mpi' + lang.to_s
@non_functional << compiler unless mpi_wrapper_works? compiler
else
@unknown_langs << lang.to_s
end
end
@unknown_langs.empty? and @non_functional.empty?
end
def modify_build_environment
# Set environment variables to help configure scripts find MPI compilers.
# Variable names taken from:
#
# http://www.gnu.org/software/autoconf-archive/ax_mpi.html
lang_list.each do |lang|
compiler = 'mpi' + lang.to_s
mpi_path = which compiler
# Fortran 90 environment var has a different name
compiler = 'MPIFC' if lang == :f90
ENV[compiler.upcase] = mpi_path
end
end
def message
if not @unknown_langs.empty?
<<-EOS.undent
There is no MPI compiler wrapper for:
#{@unknown_langs.join ', '}
The following values are valid arguments to `MPIDependency.new`:
:cc, :cxx, :f90, :f77
EOS
else
<<-EOS.undent
Homebrew could not locate working copies of the following MPI compiler
wrappers:
#{@non_functional.join ', '}
If you have a MPI installation, please ensure the bin folder is on your
PATH and that all the wrappers are functional. Otherwise, a MPI
installation can be obtained from homebrew by *picking one* of the
following formulae:
open-mpi, mpich2
EOS
end
end
end