It is possible to compile, say mgcv with OpenMP. There are several steps (done 
on a Mac M4 with Sequoia 15.3.2) :

- Installed R 4.5.0 patched (should not change from the initial 4.5.0 version, 
but to be correct)

- Installed the compilation tools with `xcode-select —install`

- Installed gfortran-14.2-universal.pkg from here: 
https://mac.r-project.org/tools/ 

- Followed instructions here: https://mac.r-project.org/bin/, that is, `sudo 
R`, then `source("https://mac.R-project.org/bin/install.R »)`, then 

```bash
install.libs("r-base-dev")
install.libs("gettext")
```

- Followed instructions on this page to get experimental OpenMP libraries: 
https://mac.r-project.org/openmp/ 

- Downloaded the latest .tar.gz source of mgcv and placed the file in the 
current directory

- Recompiled mgcv with: `PKG_CPPFLAGS='-Xclang -fopenmp' PKG_LIBS=-lomp R CMD 
INSTALL mgcv-1.9-3.tar.gz`

Now I have `mgcv:::mgcv.omp()` that returns TRUE.

Note that I used to recompile data.table also to get a multithreaded version, 
but apparently, it is not needed any more:

```R
install.packages("data.table")
library(data.table)
getDTthreads() # 8 for me by default (M4 max)
packageVersion("data.table") # 1.17.0
```

It would be nice to get multithreading, and especially OpenMP, enabled by 
default for the Mac. But I understand that it is risky since Apple does not 
support it officially.

Best,

Philippe

.........................................<°}))><........
 ) ) ) ) )
( ( ( ( (    Prof. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (    Numerical Ecology
 ) ) ) ) )   Mons University, Belgium
( ( ( ( (
.............................................................. 

> Le 24 avr. 2025 à 11:58, Gavin Simpson <ucfa...@gmail.com> a écrit :
> 
> Dear list,
> 
> I'm trying to clarify my understanding of what is and is not
> implemented / expected in terms of openMP support in R and CRAN
> package *binaries* for MacOS on apple silicon.
> 
> I have the CRAN's R binary for MacOS X (apple silicon) and also the
> CRAN binaries for two packages, glmmTMB and mgcv, both of which seem
> to be instrumented (following WRE) to use OpenMP if available. And
> from discussions here I understand that thanks to Simon and  others,
> OpenMP support for MacOS X is in R and so should I expect OpenMP to
> work in these two packages?
> 
> If I am, neither of them is working on various of my Mac systems;
> model fitting is single threaded and the test functions that glmmTMB
> and mgcv use to detect OMP support both return FALSE:
> 
> R version 4.5.0 (2025-04-11) -- "How About a Twenty-Six"
> Platform: aarch64-apple-darwin20 (64-bit)
> r$> glmmTMB::omp_check()
> [1] FALSE
> r$> mgcv:::mgcv.omp()
> [1] FALSE
> 
> Is this reproducible on other's systems? (Could someone run those two
> bits of code on their systems if they use the MacOS X R binary from
> CRAN and the CRAN Mac binaries for the packages - running mgcv's test
> should be easier as this pkg is shipped with the R binary).
> 
> I am happy to provide further system details, but at this point I'm
> mostly hoping to clarify what I should expect and whether what I'm
> seeing is typical?
> 
> Thanks in advance
> 
> Gavin
> 
> -- 
> Gavin Simpson, PhD [he/him/his]
> [tw] @ucfagls [OrciD] 0000-0002-9084-8413
> [web] fromthebottomoftheheap.net
> • Assistant Professor
> • Department of Animal & Veterinary Sciences, Aarhus University
> • Adjunct Professor, Department of Biology, University of Regina.
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

_______________________________________________
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Reply via email to