[R] How to set the correct libomp for R

ger@ophii m@iii@g oii gmx@@et ger@ophii m@iii@g oii gmx@@et
Tue Apr 9 09:55:06 CEST 2024

Sorry, if have to correct this. If I only move away /usr/local/lib/libomp.dylib, I can still install it. So it seems that also here the internal libomp.dylib from R is used. Just the bundled omp files at /usr/local/include (omp-tools.h, omp.h, ompt.h) seem to be used. So maybe this is caused by a mismatch of these file and the used libomp.dylib?

Gesendet: Dienstag, 09. April 2024 um 09:47 Uhr
Von: gernophil using gmx.net
An: "Ivan Krylov" <ikrylov using disroot.org>, "gernophil--- via R-help" <r-help using r-project.org>
Cc: gernophil using gmx.net
Betreff: Re: [R] How to set the correct libomp for R
Sorry fort he late reply, your mail ended up in my spam and I've just seen it recently.

> Does the behaviour change if you temporarily move away
> /usr/local/lib/libomp.dylib?

It does not change the behavior after loading (or attaching) data.table using "library(data.table)". It is still loaded with multiple threads:
"data.table 1.15.4 using 4 threads (see ?getDTthreads). Latest news: r-datatable.com"

It does however make it impossible to install data.table from source with these flags (set in ~/.R/Makevars; I also temporarily removed the omp files from /usr/local/include that are bundled in the tarball)
CPPFLAGS += -Xclang -fopenmp
LDFLAGS += -lomp

This is the error that happens then:
In file included from ./data.table.h:1:
./myomp.h:2:12: fatal error: 'omp.h' file not found
#include <omp.h>
1 error generated.
make: *** [assign.o] Error 1
ERROR: compilation failed for package ‘data.table’
* removing ‘/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/data.table’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/data.table’
Warning in install.packages :
installation of package ‘data.table’ had non-zero exit status
So, the libomp.dylib does indeed seem to be necessary for installing from source with OpenMP support, but not for executing the code

> When you reproduce the crash, what does the backtrace say?

I haven't done that yet, since I was on the non-OpenMP version right now. I'll come back to you once I tried.


Am 08.04.24, 11:13 schrieb "Ivan Krylov" <ikrylov using disroot.org <mailto:ikrylov using disroot.org>>:

В Mon, 8 Apr 2024 10:29:53 +0200
gernophil--- via R-help <r-help using r-project.org <mailto:r-help using r-project.org>> пишет:

> I have some weird issue with using multithreaded data.table in macOS
> and I am trying to figure out, if it’s connected to my libomp.dylib.
> I started using libomp as stated here:
> https://mac.r-project.org/openmp/ <https://mac.r-project.org/openmp/[https://mac.r-project.org/openmp/][https://mac.r-project.org/openmp/[https://mac.r-project.org/openmp/]]>

Does the behaviour change if you temporarily move away

> P.S.: If you need some more details about the actual issue with
> data.table you can also check here
> (https://github.com/rstudio/rstudio/issues/14517[https://github.com/rstudio/rstudio/issues/14517][https://github.com/rstudio/rstudio/issues/14517[https://github.com/rstudio/rstudio/issues/14517]] <https://github.com/rstudio/rstudio/issues/14517[https://github.com/rstudio/rstudio/issues/14517][https://github.com/rstudio/rstudio/issues/14517[https://github.com/rstudio/rstudio/issues/14517]]>) and here
> (https://github.com/Rdatatable/data.table/issues/5957[https://github.com/Rdatatable/data.table/issues/5957][https://github.com/Rdatatable/data.table/issues/5957[https://github.com/Rdatatable/data.table/issues/5957]] <https://github.com/Rdatatable/data.table/issues/5957[https://github.com/Rdatatable/data.table/issues/5957][https://github.com/Rdatatable/data.table/issues/5957[https://github.com/Rdatatable/data.table/issues/5957]]>)

The debugger may be able to shed more light on the problem than just
"yes, this is due to OpenMP":
https://github.com/rstudio/rstudio/issues/14517#issuecomment-2040231196[https://github.com/rstudio/rstudio/issues/14517#issuecomment-2040231196][https://github.com/rstudio/rstudio/issues/14517#issuecomment-2040231196[https://github.com/rstudio/rstudio/issues/14517#issuecomment-2040231196]] <https://github.com/rstudio/rstudio/issues/14517#issuecomment-2040231196[https://github.com/rstudio/rstudio/issues/14517#issuecomment-2040231196][https://github.com/rstudio/rstudio/issues/14517#issuecomment-2040231196[https://github.com/rstudio/rstudio/issues/14517#issuecomment-2040231196]]>

When you reproduce the crash, what does the backtrace say?

Best regards,


More information about the R-help mailing list