class BoostMpi < Formula desc "C++ library for C++/MPI interoperability" homepage "https://www.boost.org/" url "https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2" sha256 "5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9" revision 1 head "https://github.com/boostorg/boost.git" bottle do sha256 "f4787bde14ed2b84468437f54b2a60e140f3eb9f878f9ada7086fd3ce27f6dae" => :high_sierra sha256 "7037c8d24185dd079dddd4292859c55d2b149f1753db81cfd04b18ccf42b9b8f" => :sierra sha256 "2de5c190fb851c83c8732190ea1411108a6e35b633dea28a8fc393a3888bc2f8" => :el_capitan end depends_on "boost" depends_on "open-mpi" needs :cxx11 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"] # Trunk starts using "clang++ -x c" to select C compiler which breaks C++11 # handling using ENV.cxx11. Using "cxxflags" and "linkflags" still works. args << "cxxflags=-std=c++11" if ENV.compiler == :clang args << "cxxflags=-stdlib=libc++" << "linkflags=-stdlib=libc++" 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 #include #include 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