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

Vladimir Dergachev vo|ody@ @end|ng |rom m|nd@pr|ng@com
Sat Oct 9 19:35:19 CEST 2021



On Sat, 9 Oct 2021, Ben Bolker wrote:

>  FWIW there is some machinery in the glmmTMB package for querying, setting, 
> etc. the number of OpenMP threads.
>
> https://github.com/glmmTMB/glmmTMB/search?q=omp

Great, thank you !

Vladimir Dergachev

>
> On 10/9/21 11:45 AM, Vladimir Dergachev wrote:
>> 
>> 
>> 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
>> 
>> ______________________________________________
>> R-package-devel using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
> -- 
> Dr. Benjamin Bolker
> Professor, Mathematics & Statistics and Biology, McMaster University
> Director, School of Computational Science and Engineering
> Graduate chair, Mathematics & Statistics
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list