libomp 5.0.1 (new formula)
Add OpenMP for Apple Clang. Apple Clang now has support for OpenMP, but it has been disabled in the driver and is not included with High Sierra. It can be built and used, though; this formula will build it and provides hints on the correct usage. Closes #20589. Signed-off-by: ilovezfs <ilovezfs@icloud.com>
This commit is contained in:
parent
a0551cbd40
commit
3c6486f517
1 changed files with 54 additions and 0 deletions
54
Formula/libomp.rb
Normal file
54
Formula/libomp.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
class Libomp < Formula
|
||||
desc "LLVM's OpenMP runtime library"
|
||||
homepage "https://openmp.llvm.org/"
|
||||
url "https://releases.llvm.org/5.0.1/openmp-5.0.1.src.tar.xz"
|
||||
sha256 "adb635cdd2f9f828351b1e13d892480c657fb12500e69c70e007bddf0fca2653"
|
||||
|
||||
depends_on "cmake" => :build
|
||||
depends_on :macos => :yosemite
|
||||
|
||||
def install
|
||||
system "cmake", ".", *std_cmake_args
|
||||
system "make", "install"
|
||||
system "cmake", ".", "-DLIBOMP_ENABLE_SHARED=OFF", *std_cmake_args
|
||||
system "make", "install"
|
||||
end
|
||||
|
||||
def caveats; <<~EOS
|
||||
On Apple Clang, you need to add several options to use OpenMP's front end
|
||||
instead of the standard driver option. This usually looks like
|
||||
-Xpreprocessor -fopenmp -lomp
|
||||
|
||||
You might need to make sure the lib and include directories are discoverable
|
||||
if #{HOMEBREW_PREFIX} is not searched:
|
||||
|
||||
-L#{opt_lib} -I#{opt_include}
|
||||
|
||||
For CMake, the following flags will cause the OpenMP::OpenMP_CXX target to
|
||||
be set up correctly:
|
||||
-DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I#{opt_include}" -DOpenMP_CXX_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY=#{opt_lib}/libomp.dylib
|
||||
EOS
|
||||
end
|
||||
|
||||
test do
|
||||
(testpath/"test.cpp").write <<~EOS
|
||||
#include <omp.h>
|
||||
#include <array>
|
||||
int main (int argc, char** argv) {
|
||||
std::array<size_t,2> arr = {0,0};
|
||||
#pragma omp parallel num_threads(2)
|
||||
{
|
||||
size_t tid = omp_get_thread_num();
|
||||
arr.at(tid) = tid + 1;
|
||||
}
|
||||
if(arr.at(0) == 1 && arr.at(1) == 2)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
EOS
|
||||
system ENV.cxx, "-Werror", "-Xpreprocessor", "-fopenmp", "test.cpp",
|
||||
"-L#{lib}", "-lomp", "-o", "test"
|
||||
system "./test"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue