2015-08-03 13:09:07 +01:00
|
|
|
require "requirement"
|
2013-04-02 15:33:35 -05:00
|
|
|
|
|
|
|
# There are multiple implementations of MPI-2 available.
|
|
|
|
# http://www.mpi-forum.org/
|
|
|
|
# This requirement is used to find an appropriate one.
|
2015-06-15 09:56:04 +01:00
|
|
|
class MPIRequirement < Requirement
|
2013-04-02 15:33:35 -05:00
|
|
|
attr_reader :lang_list
|
|
|
|
|
|
|
|
fatal true
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
default_formula "open-mpi"
|
2013-06-03 15:08:47 -05:00
|
|
|
|
2013-04-02 15:33:35 -05:00
|
|
|
env :userpaths
|
|
|
|
|
2013-06-26 22:08:54 -05:00
|
|
|
# This method must accept varargs rather than an array for
|
|
|
|
# backwards compatibility with formulae that call it directly.
|
|
|
|
def initialize(*tags)
|
2013-04-02 15:33:35 -05:00
|
|
|
@non_functional = []
|
|
|
|
@unknown_langs = []
|
2013-06-26 22:08:54 -05:00
|
|
|
@lang_list = [:cc, :cxx, :f77, :f90] & tags
|
|
|
|
tags -= @lang_list
|
|
|
|
super(tags)
|
2013-04-02 15:33:35 -05:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def mpi_wrapper_works?(compiler)
|
2013-04-02 15:33:35 -05:00
|
|
|
compiler = which compiler
|
2015-08-03 13:09:07 +01:00
|
|
|
return false if compiler.nil? || !compiler.executable?
|
2013-04-02 15:33:35 -05:00
|
|
|
|
|
|
|
# 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.
|
2015-08-03 13:09:07 +01:00
|
|
|
quiet_system compiler, "--version"
|
2013-04-02 15:33:35 -05:00
|
|
|
end
|
|
|
|
|
2015-02-23 23:41:43 +08:00
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name}: #{name.inspect} #{tags.inspect} lang_list=#{@lang_list.inspect}>"
|
|
|
|
end
|
|
|
|
|
2013-04-02 15:33:35 -05:00
|
|
|
satisfy do
|
|
|
|
@lang_list.each do |lang|
|
|
|
|
case lang
|
|
|
|
when :cc, :cxx, :f90, :f77
|
2015-08-03 13:09:07 +01:00
|
|
|
compiler = "mpi" + lang.to_s
|
2013-04-02 15:33:35 -05:00
|
|
|
@non_functional << compiler unless mpi_wrapper_works? compiler
|
|
|
|
else
|
|
|
|
@unknown_langs << lang.to_s
|
|
|
|
end
|
|
|
|
end
|
2015-08-03 13:09:07 +01:00
|
|
|
@unknown_langs.empty? && @non_functional.empty?
|
2013-04-02 15:33:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
env do
|
|
|
|
# Set environment variables to help configure scripts find MPI compilers.
|
|
|
|
# Variable names taken from:
|
2015-01-04 05:02:27 +01:00
|
|
|
# https://www.gnu.org/software/autoconf-archive/ax_mpi.html
|
2013-04-02 15:33:35 -05:00
|
|
|
@lang_list.each do |lang|
|
2015-08-03 13:09:07 +01:00
|
|
|
compiler = "mpi" + lang.to_s
|
2013-04-02 15:33:35 -05:00
|
|
|
mpi_path = which compiler
|
|
|
|
|
|
|
|
# Fortran 90 environment var has a different name
|
2015-08-03 13:09:07 +01:00
|
|
|
compiler = "MPIFC" if lang == :f90
|
2013-04-02 15:33:35 -05:00
|
|
|
ENV[compiler.upcase] = mpi_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|