You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With R 4.0.0, R (as well as packages on CRAN) will be built with the system toolchain (Apple Clang), which unfortunately mean OpenMP support is not provided natively by the compiler. Fortunately, it is still possible to use OpenMP with the system toolchain if you:
Instruct clang to enable OpenMP with -Xpreprocessor -fopenmp,
Explicitly provide include paths to libomp during compilation,
Explicitly provide library paths to libomp during link.
Unfortunately, data.table fails to detect this case as it invokes the compiler with just -fopenmp here:
I am pasting my working version of Makevars here with edits from the version in the install docs marked, so that google may find it and help a future traveller:
Please reply if you find anything about this that could be improved or if you find something redundant. I just change lines on a whim because I'm too lazy to spend the time really learning the ins and outs of the Makevars file.
UPDATE
I was able to get macOS clang to compile with OpenMP for my MacBook Pro (18,2 M1 Max) running macOS Ventura 13.3 with only this for Makevars.
@kevinushey could you please check if 1.13.2 resolves the problem for you? There was a change in #4735
User-supplied PKG_LIBS and PKG_CFLAGS are now retained and the suggestion in https://mac.r-project.org/openmp/; i.e., PKG_CPPFLAGS='-Xclang -fopenmp' PKG_LIBS=-lomp R CMD INSTALL data.table_<ver>.tar.gz
has a better chance of working on Mac.
Looks like this works for me as well. It sounds like the issue is ultimately resolved, then? Unless data.table wants to try and automagically enable OpenMP on macOS.
Unless data.table wants to try and automagically enable OpenMP on macOS.
That's an interesting idea. I don't have macOS and was waiting to see how macOS users got on with the latest version. I got the impression from https://mac.r-project.org/openmp/ that there are so many problems with macOS and OpenMP that there is not really much we can do. But, now that you said this, perhaps we could have another go. That would mean that the CRAN binary would be OpenMP-enabled again, iiuc? That would be great. If so, what exactly works for you: simply passing -Xclang -fopenmp and that's all that's needed?
On one hand, the use of OpenMP with Apple Clang isn't officially supported, and so for that reason data.table shouldn't try to enable it by default (since in theory Apple could pull the rug out from underneath us at any time);
On the other hands, as far as I know no users have reported issues when trying to use OpenMP with Apple Clang + data.table anyhow, so even if it's not officially supported it's still functional as far as it's used in data.table, so perhaps it's worth (trying to) enable by default.
I don't have a strong opinion on what the best way forward is, though.
If data.table makes an attempt in the configure script, and performs the attempt correctly by falling back to no OpenMP, then it looks like we're agreeing on option 2 then. It's the performing-the-attempt-correctly part that is tricky cross-platform. Did you see the comment I put into configure -- I'm not sure that attempt (testing to see if manually adding -fopenmp works) has ever worked as intended since it was put in a few versions ago.
I think you're right (sorry about that). It did ultimately work insofar that OpenMP was disabled by default on macOS, since the "default" OpenMP flags wouldn't work there. But it didn't help in turning OpenMP on.
Regardless, I think getting this right would mean redoing that part of the configure script, to keep track of + set the OpenMP compiler flags as appropriate in the Makevars file.
Picking one from the hat: @jameslamb I see {lightgbm} looks to possibly be attempting OpenMP setup in its configure, are you familiar with that / is it working well for you?
👋🏻 I'm very familiar with that. It's been working well for me on my macbook and in LightGBM's continuous integration. And we haven't received user reports about OpenMP not being found, but that might just be because no one's noticed.
It does seem like OpenMP is not being found successfully in our CRAN builds:
* installing *source* package ‘lightgbm’ ...
...
checking whether OpenMP will work in a package... no
***********************************************************************************************
OpenMP is unavailable on this macOS system. LightGBM code will run single-threaded as a result.
To use all CPU cores for training jobs, you should install OpenMP by running
brew install libomp
***********************************************************************************************
configure: creating ./config.status
That reminds me that it's also possible to submit a package tarball for testing at https://mac.r-project.org/macbuilder/submit.html; perhaps that could be used to further verify whether or not the PR in #6034 successfully detected OpenMP support on CRAN?
I just uploaded it to macbuilder. See here for the results.
According to this chunk of main.Rout it looks good
> test.data.table() # runs the main test suite of 5,000+ tests in /inst/tests/tests.Rraw
getDTthreads(verbose=TRUE):OpenMP version (_OPENMP) 201811
omp_get_num_procs() 8R_DATATABLE_NUM_PROCS_PERCENT unset (default50)
R_DATATABLE_NUM_THREADSunsetR_DATATABLE_THROTTLE unset (default1024)
omp_get_thread_limit() 2147483647
omp_get_max_threads() 8OMP_THREAD_LIMITunsetOMP_NUM_THREADSunsetRestoreAfterForktruedata.tableisusing4threadswiththrottle==1024.See ?setDTthreads.
test.data.table() running:/Volumes/PkgBuild/work/1720650797-9b56f65b10b20c0e/packages/big-sur-arm64/results/4.4/data.table.Rcheck/data.table/tests/tests.Rraw
Activity
MichaelChirico commentedon Apr 3, 2020
I think Jim Hester raised this same issue, let me see...
I see, it was on the orgs page... good to have this in the issue tracker
https://github.com/orgs/Rdatatable/teams/project-members/discussions/34
krivard commentedon Jul 7, 2020
I am pasting my working version of
Makevarshere with edits from the version in the install docs marked, so that google may find it and help a future traveller:macOS Mojave, 10.14.6
with thanks to these two threads on StackOverflow
dbrookeUAB commentedon Nov 15, 2020
Since @krivard last post was super helpful for me to get things working, here is my working version of
MakevarsAlso Mac Mojave 10.14.6
Please reply if you find anything about this that could be improved or if you find something redundant. I just change lines on a whim because I'm too lazy to spend the time really learning the ins and outs of the
Makevarsfile.UPDATE
I was able to get macOS clang to compile with OpenMP for my MacBook Pro (18,2 M1 Max) running macOS Ventura 13.3 with only this for
Makevars.I did have to download the libomp. Specifically, LLVM 14.0.6.
Voilà!
PS...
CC=clang -Wno-nullability-completenesswas nice.jangorecki commentedon Nov 22, 2020
@kevinushey could you please check if 1.13.2 resolves the problem for you? There was a change in #4735
kevinushey commentedon Nov 22, 2020
Looks like this works for me as well. It sounds like the issue is ultimately resolved, then? Unless
data.tablewants to try and automagically enable OpenMP on macOS.mattdowle commentedon Nov 23, 2020
@kevinushey Great to hear it works.
That's an interesting idea. I don't have macOS and was waiting to see how macOS users got on with the latest version. I got the impression from https://mac.r-project.org/openmp/ that there are so many problems with macOS and OpenMP that there is not really much we can do. But, now that you said this, perhaps we could have another go. That would mean that the CRAN binary would be OpenMP-enabled again, iiuc? That would be great. If so, what exactly works for you: simply passing
-Xclang -fopenmpand that's all that's needed?kevinushey commentedon Nov 23, 2020
Right, and I can see arguments both ways:
On one hand, the use of OpenMP with Apple Clang isn't officially supported, and so for that reason
data.tableshouldn't try to enable it by default (since in theory Apple could pull the rug out from underneath us at any time);On the other hands, as far as I know no users have reported issues when trying to use OpenMP with Apple Clang +
data.tableanyhow, so even if it's not officially supported it's still functional as far as it's used indata.table, so perhaps it's worth (trying to) enable by default.I don't have a strong opinion on what the best way forward is, though.
mattdowle commentedon Nov 23, 2020
If data.table makes an attempt in the configure script, and performs the attempt correctly by falling back to no OpenMP, then it looks like we're agreeing on option 2 then. It's the performing-the-attempt-correctly part that is tricky cross-platform. Did you see the comment I put into
configure-- I'm not sure that attempt (testing to see if manually adding-fopenmpworks) has ever worked as intended since it was put in a few versions ago.kevinushey commentedon Nov 23, 2020
I think you're right (sorry about that). It did ultimately work insofar that OpenMP was disabled by default on macOS, since the "default" OpenMP flags wouldn't work there. But it didn't help in turning OpenMP on.
Regardless, I think getting this right would mean redoing that part of the
configurescript, to keep track of + set the OpenMP compiler flags as appropriate in the Makevars file.3 remaining items
mattdowle commentedon Aug 16, 2021
Thanks. Yes:
According to https://mac.r-project.org/openmp/, how about adding
-Xclang -fopenmptoPKG_CFLAGSand adding-lomptoPKG_LIBS?kevinushey commentedon Aug 16, 2021
That looks good to me, especially since it has (some form of) R-Core's official blessing.
mattdowle commentedon Aug 17, 2021
Great. If I do the PR would you be able to test? (I don't have a Mac).
kevinushey commentedon Aug 17, 2021
Sure, I'd be happy to.
MichaelChirico commentedon Mar 29, 2024
@kevinushey any chance you're familiar enough with how the fix might go here to take up a PR here? It looks like it would benefit a lot of people.
MichaelChirico commentedon Mar 29, 2024
I do see some other packages on CRAN with
configurefiles reminiscent of the discussion above:https://github.com/search?q=org%3Acran+path%3Aconfigure+%2F%5B-%5Dfopenmp%2F+%2F%5B-%5DXclang%2F&type=code
Picking one from the hat: @jameslamb I see {lightgbm} looks to possibly be attempting OpenMP setup in its
configure, are you familiar with that / is it working well for you?The PR introducing that part of
configurewas pretty heavy: lightgbm-org/LightGBM#3188jameslamb commentedon Mar 29, 2024
👋🏻 I'm very familiar with that. It's been working well for me on my macbook and in LightGBM's continuous integration. And we haven't received user reports about OpenMP not being found, but that might just be because no one's noticed.
It does seem like OpenMP is not being found successfully in our CRAN builds:
https://www.r-project.org/nosvn/R.check/r-release-macos-x86_64/lightgbm-00install.html
So LightGBM's approach probably needs some tweaks to work with CRAN's setup.
Some other discussions you might find useful:
You can
@me any time here with questions, I'd be happy to try to help.kevinushey commentedon Apr 2, 2024
That reminds me that it's also possible to submit a package tarball for testing at https://mac.r-project.org/macbuilder/submit.html; perhaps that could be used to further verify whether or not the PR in #6034 successfully detected OpenMP support on CRAN?
MichaelChirico commentedon Jul 10, 2024
Can anyone confirm this can be closed? Or do we need to wait for a CRAN release?
ben-schwen commentedon Jul 10, 2024
I just uploaded it to macbuilder. See here for the results.
According to this chunk of
main.Routit looks goodThanks again @kevinushey