[R-pkg-devel] [Tagged] Re: multithreading in packages

Vladimir Dergachev vo|ody@ @end|ng |rom m|nd@pr|ng@com
Sat Oct 9 17:45:44 CEST 2021



On Sat, 9 Oct 2021, Jeff Newmiller wrote:

> Keep in mind that by embedding this decision into your package you may 
> be consuming a resource (cores) that may be more efficiently allocated 
> by an application-level partitioning. of available resources. I for one 
> am not a fan of this kind of thinking, and it makes system requirements 
> for your package more complex even if you allow me to disable it.

That's right, and this is why I was asking about any present or future 
plans for R support - if there was a way to find out how many threads R 
should use, I would use that.

So far, it looks like the most portable way is to use OpenMP and let the 
user set an appropriate environment variable if they want to restrict 
thread usage. I could use the same OpenMP variable for pthreads as well.

This is pretty common on clusters anyway, with openmp environment 
variables set automatically to the number of cores user requested.

I would probably also add a function to the package to report the number 
of threads being used. Not sure whether it would be a good idea to report 
this during package loading (and not sure what is the right way to display 
a message during package load either).

best

Vladimir Dergachev



More information about the R-package-devel mailing list