Skip to content

Commit

Permalink
install libomp directly
Browse files Browse the repository at this point in the history
  • Loading branch information
wassimmazouz committed Jul 17, 2024
1 parent 3f95a84 commit c241413
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:

jobs:
benchopt_dev:
uses: wassimmazouz/template_benchmark/.github/workflows/test_benchmarks.yml@adding-libomp-install
uses: benchopt/template_benchmark/.github/workflows/test_benchmarks.yml@main
with:
benchopt_branch: benchopt@main
benchopt_release:
Expand Down
9 changes: 9 additions & 0 deletions benchmark_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from libomp_install import install_libomp_on_macos

# libomp x86_64 is needed for snapML on macOS. Homebrew is needed for this install as well.

# Homebrew is installed and added to path to install libomp x86_64.

# Also, libomp needs some directories added to PATH to function correctly.

install_libomp_on_macos()
57 changes: 57 additions & 0 deletions benchmark_utils/libomp_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import platform
import subprocess
import os


def install_libomp_on_macos():
# Check if the OS is macOS
if platform.system() != 'Darwin':
return

# Install and setup Homebrew
subprocess.run(
[
'arch', '-x86_64', '/bin/bash', '-c',
'"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
],
check=True,
shell=True
)

# Add Homebrew to the shell environment
homebrew_shellenv = subprocess.run(
[
'/usr/local/bin/brew', 'shellenv'
],
check=True,
capture_output=True,
text=True,
shell=True
).stdout
with open(os.path.expanduser('~/.profile'), 'a') as profile_file:
profile_file.write(f'eval "$({homebrew_shellenv})"\n')
subprocess.run(
['eval', f'"$({homebrew_shellenv})"'],
check=True,
shell=True
)

# Install libomp
subprocess.run(
['arch', '-x86_64', '/usr/local/bin/brew', 'install', 'libomp'],
check=True,
shell=True
)

# Set environment variables
with open(os.path.expanduser('~/.profile'), 'a') as profile_file:
profile_file.write('export LDFLAGS="-L/usr/local/opt/libomp/lib"\n')
profile_file.write('export CPPFLAGS="-I/usr/local/opt/libomp/include"\n')
profile_file.write(
'export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/opt/libomp/lib\n')

# Also export environment variables in the current session
os.environ['LDFLAGS'] = '-L/usr/local/opt/libomp/lib'
os.environ['CPPFLAGS'] = '-I/usr/local/opt/libomp/include'
os.environ['DYLD_LIBRARY_PATH'] = os.environ.get(
'DYLD_LIBRARY_PATH', '') + ':/usr/local/opt/libomp/lib'

0 comments on commit c241413

Please sign in to comment.