Skip to content
Prev 7855 / 12125 Next

[R-pkg-devel] Setting OpenMP threads (globally) for an R package

Hi Simon

I really appreciate the help, thanks for the message.
I think uncontrolled forking could be the issue, though I don't see all
cores used via `htop`; I just see the memory quickly surge.


*> There are many things that are not allowed inside mclapply so that's
where I would look. *
Could you detail this a bit more? This could be what's happening....


*>Threads typically don't cause memory explosion, because OpenMP threads
don't allocate new memory, but uncontrolled forking does*
Do you have insight on how to explicitly limit forking? It looks like
Henrik had been thinking about this earlier:
https://github.com/HenrikBengtsson/Wishlist-for-R/issues/94

Moreover, could you explain how setting the OpenMP global variables e.g.
`OMP_NUM_THREADS=1` would stop forking? I don't quite follow this.


*> It may be better to look at the root cause first, but for that we would
need more details on what you are doing.*
Functions with mclapply do indeed show this "memory surging" behavior, e.g.

https://github.com/kharchenkolab/numbat/blob/main/R/main.R#L940-L963


Thanks, Evan

On Thu, Mar 17, 2022 at 7:23 PM Simon Urbanek <simon.urbanek at r-project.org>
wrote: