Skip to content

Instructions for building from source for OpenMP support on Apple Silicon / M1 / arm64 under Monterey 12.4 #5419

Closed

Description

@sciatro

Thanks for all the great work on data.table. It's a really fantastic tool.

I've found that the instructions at https://github.com/Rdatatable/data.table/wiki/Installation for building data.table from source to enable OpenMP support on macOS 12.4 Monterey do not produce a working build via the preferred Option 1.1 Install libomp with brew approach.

If, after brew update && brew install libomp the recommended .R/Makevars flags are set (i.e. CPPFLAGS += -Xclang -fopenmp and LDFLAGS += -lomp).

With the documented flags, install.package from source errors out after failing to find omp.h. After a bit of fiddling around I found that the following will produce a working install:

LDFLAGS += -L/opt/homebrew/opt/libomp/lib -lomp
CPPFLAGS += -I/opt/homebrew/opt/libomp/include -Xclang -fopenmp

That build does not, however, pass test.data.table() which fails after about 1800 tests citing the absence of libz. To solve this problem I needed to also install pkg-config (i.e. brew install pkg-config). After doing this and reinstalling data.table from source test.data.table() completes all 9999 tests successfully.

As such, for me, on a clean native R arm64 4.2.1 install onto an Apple M1 running on 12.4 with no other brew packages installed what I needed to do for a working OpenMP enabled install of data.table was:

  1. brew install libomp and pkg-config
  2. Create ~/.R/Makevars with:
LDFLAGS += -L/opt/homebrew/opt/libomp/lib -lomp
CPPFLAGS += -I/opt/homebrew/opt/libomp/include -Xclang -fopenmp
  1. Install data.table from source within R install.packages("data.table", type = "source")

Sorry that I do not have the exact error messages encountered along the way. Given how fussy macOS / OpenMP support has always been I assumed that I was the problem and thus did not keep track of the steps required to fix what I've now come to think could be more general departure of current state brew / xcode build tools (i.e. xcode-select --install) on Apple Silicon from the documentation.

If those who know more believe that the steps I took to get a working build are likely those required I'm not sure how this should be best documented as the current macOS instructions worked well for me on an x86 Mac very recently so I think this may be a case of platform specific differences in brew not just a 'new normal'.

Activity

  1. tdhock commented on Jul 12, 2022

    @tdhock
    Member

    Can you please update the wiki with these instructions? (the wiki should be editable by anyone)

  2. pintoa1-mskcc commented on Aug 11, 2022

    @pintoa1-mskcc

    Great job @sciatro!

  3. derekschinke commented on Dec 8, 2022

    @derekschinke

    Can confirm this still works on Ventura, as long as you make sure your Makevarvs doesn't save as an RTF

  4. sciatro commented on Mar 11, 2023

    @sciatro
    Author

    I just got access to a clean install of macOS 13.2.1 running on an m2 chip and was able to retest these instructions and confirm they continue to work but with a newly noted quirk in that they only work from the cli, not the R console GUI.

    To recap with some extra notes on zlib / pkg-config:

    1. Install the command line developer tools (xcode-select --install)
    2. Install brew (see https://brew.sh/)
    3. Use brew to install pkg-config to provide zlib (brew install pkg-config)
    4. Confirm that pkg-config is working (pkg-config --libs zlib should return -lz)
    5. Use brew to install libomp to get multiple threads (brew install libomp) ... this is the point
    6. Save paths in ~/.R/Makevars:
    LDFLAGS += -L/opt/homebrew/opt/libomp/lib -lomp
    CPPFLAGS += -I/opt/homebrew/opt/libomp/include -Xclang -fopenmp
    
    1. From an R interpreter running in your terminal emulator (e.g. iTerm2 or Terminal) install data.table (install.packages("data.table", type = "source")) ... this seems to be required for R installs to find pkg-config vs running the R console GUI app on macOS which seems unable to find pkg-config.
    2. Test your install (data.table::test.data.table())
  5. sciatro commented on Mar 11, 2023

    @sciatro
    Author
  6. tdhock commented on Mar 12, 2023

    @tdhock
    Member

    looks good thanks! ok to close this issue now? or do you think this info should be mentioned somewhere other than that wiki page?

  7. sciatro commented on Mar 13, 2023

    @sciatro
    Author

    My sense is that this is documented but not supported and thus the present "works for me" level solution is adequate and thus the issue can be closed.

    If some future reader is looking to clear up unknowns:

    • Why is pkg-config not picked up by the macOS R console GUI? (i.e. will this work if you try and do a data.table install in the console GUI)
    • Is pkg-config picked up by R Studio? (i.e. will this work if you try and do a data.table install in R Studio)
    • Is the impact of "successful" installation that lacks zlib (i.e. installs but doesn't pass the all tests) due to failure to detect pkg-config gentle enough that what amounts to silent failure is fine.
  8. kylebutts commented on Jun 25, 2023

    @kylebutts

    Testing on Mac OS Ventura, the above wouldn't work, but with this small tweak, it worked perfectly!

    LDFLAGS += -L/opt/homebrew/opt/libomp/lib -lomp
    CPPFLAGS += -I/opt/homebrew/opt/libomp/include -Xpreprocessor -fopenmp
  9. pvanlaake commented on Nov 2, 2023

    @pvanlaake

    Ventura 13.5.2 / M2 Pro / clang-1500.0.40.1, built from source without problem, using instructions on this page, without @kylebutts 's tweak. Noting that the instructions on the page linked from the install.packages(data.table) message are not fully capturing the detail in this thread.

  10. jorondo1 commented on Jan 23, 2024

    @jorondo1

    Hi! Thanks a lot. I was having trouble enabling parallel processing on the DECIPHER R package (specifically the IdTaxa() function) on my M2 mac (Ventura 13.5.2) and this helped me solve it. I'm leaving a comment here in the hopes that someone running in the same problem doesn't have to do all the googling I had to do to figure out it was an OpenMP problem.

    Briefly, here's what I did, summarized from above

    1. xcode-select --install
    2. Install Brew
    3. brew install pkg-config
    4. pkg-config --libs zlib (should return -lz)
    5. brew install libomp ... this is the point
    6. Create ~/.R/Makevars and add @kylebutts' flags :
    LDFLAGS += -L/opt/homebrew/opt/libomp/lib -lomp
    CPPFLAGS += -I/opt/homebrew/opt/libomp/include -Xpreprocessor -fopenmp
    
    1. Reinstall DECIPHER from source BiocManager::install("DECIPHER", type="source")
  11. Jonavi04 commented on Feb 18, 2024

    @Jonavi04

    @kylebutts's edits still working for MacOS Ventura 14.2 M3 pro! this thread saves my day!

  12. MichaelChirico commented on Mar 30, 2024

    @MichaelChirico
    Member

    Anyone on this thread able to test out #6034? Would be great to have more confirmation from Mac users that it's working (or at very least, not breaking anyone)

    cc reaction-only participants @odani @m-muecke @vc77 @arbuzovv @shrektan @linoferreira @hauselin @biga94 @polettif @truenomad @cportner @RodDalBen @sparrow925 @sigmafelix

  13. truenomad commented on Mar 31, 2024

    @truenomad

    Anyone on this thread able to test out #6034? Would be great to have more confirmation from Mac users that it's working (or at very least, not breaking anyone)

    cc reaction-only participants @odani @m-muecke @vc77 @arbuzovv @shrektan @linoferreira @hauselin @biga94 @polettif @truenomad @cportner @RodDalBen @sparrow925 @sigmafelix

    Following the instructions and building from source solved it for me!

  14. RodDalBen commented on Jul 11, 2024

    @RodDalBen

    Anyone on this thread able to test out #6034? Would be great to have more confirmation from Mac users that it's working (or at very least, not breaking anyone)

    cc reaction-only participants @odani @m-muecke @vc77 @arbuzovv @shrektan @linoferreira @hauselin @biga94 @polettif @truenomad @cportner @RodDalBen @sparrow925 @sigmafelix

    Works for me w/ version 1.15.99. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions