100 lines
3.4 KiB
Ruby
100 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.0/source/boost_1_65_0.tar.bz2"
|
|
sha256 "ea26712742e2fb079c2a566a31f3266973b76e38222b9f88b387e3c8b2f9902c"
|
|
head "https://github.com/boostorg/boost.git"
|
|
|
|
bottle do
|
|
sha256 "0426b13a2802b1185ae9c0dd1412badf9235b360645268222410142ddc0ebf59" => :sierra
|
|
sha256 "e71c7f243e7bceaff1977f4332e9b0388aaf11de7dfa206a0c7c6aa73321a3d9" => :el_capitan
|
|
sha256 "1428798211c52b06fc25f11883267406e5ed95f95d70b347e4d9be794dad6a0b" => :yosemite
|
|
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.undent
|
|
#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
|