homebrew-core/Formula/boost-mpi.rb
2017-10-29 11:51:45 -07:00

101 lines
3.4 KiB
Ruby

class BoostMpi < Formula
desc "C++ library for C++/MPI interoperability"
homepage "https://www.boost.org/"
url "https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.bz2"
sha256 "9807a5d16566c57fd74fb522764e0b134a8bbe6b6e8967b83afefd30dcd3be81"
revision 1
head "https://github.com/boostorg/boost.git"
bottle do
sha256 "ab1599905ccc3891aaf12ccb8fc7d82a48f3c62c5a0b949c9594fcec41f11f96" => :high_sierra
sha256 "c6a68706caf6d58e6e2efed6d96a56877c9b198bb4ea9036013b144fc589f5d3" => :sierra
sha256 "268a16ac0a424bf62366591a4b6b8a1347ab82705aa70d3ede245fd81e9565f1" => :el_capitan
end
option :cxx11
if build.cxx11?
depends_on "boost" => "c++11"
depends_on "open-mpi" => "c++11"
else
depends_on "boost"
depends_on :mpi => [:cc, :cxx]
end
def install
# "layout" should be synchronized with boost
args = ["--prefix=#{prefix}",
"--libdir=#{lib}",
"-d2",
"-j#{ENV.make_jobs}",
"--layout=tagged",
"--user-config=user-config.jam",
"threading=multi,single",
"link=shared,static"]
# Build in C++11 mode if boost was built in C++11 mode.
# Trunk starts using "clang++ -x c" to select C compiler which breaks C++11
# handling using ENV.cxx11. Using "cxxflags" and "linkflags" still works.
if build.cxx11?
args << "cxxflags=-std=c++11"
if ENV.compiler == :clang
args << "cxxflags=-stdlib=libc++" << "linkflags=-stdlib=libc++"
end
elsif Tab.for_name("boost").cxx11?
odie "boost was built in C++11 mode so boost-mpi must be built with --c++11."
end
open("user-config.jam", "a") do |file|
file.write "using darwin : : #{ENV.cxx} ;\n"
file.write "using mpi ;\n"
end
system "./bootstrap.sh", "--prefix=#{prefix}", "--libdir=#{lib}", "--with-libraries=mpi"
system "./b2", *args
lib.install Dir["stage/lib/*mpi*"]
# libboost_mpi links to libboost_serialization, which comes from the main boost formula
boost = Formula["boost"]
MachO::Tools.change_install_name("#{lib}/libboost_mpi-mt.dylib",
"libboost_serialization-mt.dylib",
"#{boost.lib}/libboost_serialization-mt.dylib")
MachO::Tools.change_install_name("#{lib}/libboost_mpi.dylib",
"libboost_serialization.dylib",
"#{boost.lib}/libboost_serialization.dylib")
end
test do
(testpath/"test.cpp").write <<~EOS
#include <boost/mpi.hpp>
#include <iostream>
#include <boost/serialization/string.hpp>
namespace mpi = boost::mpi;
int main(int argc, char* argv[])
{
mpi::environment env(argc, argv);
mpi::communicator world;
if (world.rank() == 0) {
world.send(1, 0, std::string("Hello"));
std::string msg;
world.recv(1, 1, msg);
std::cout << msg << "!" << std::endl;
} else {
std::string msg;
world.recv(0, 0, msg);
std::cout << msg << ", ";
std::cout.flush();
world.send(0, 1, std::string("world"));
}
return 0;
}
EOS
boost = Formula["boost"]
system "mpic++", "test.cpp", "-L#{lib}", "-L#{boost.lib}", "-lboost_mpi", "-lboost_serialization", "-o", "test"
system "mpirun", "-np", "2", "./test"
end
end