> Is there any reliable way to let packages to know if they are on CRAN, so > they can set omp cores to 2 by default?
Instead of testing for "on CRAN" or not, you can test for 'R CMD check' running or not. 'R CMD check' sets environment variable _R_CHECK_LIMIT_CORES_=TRUE. You can use that to limit your code to run at most two (2) parallel threads or processes. The parallelly::availableCores() function is agile to this and many other settings, i.e. it'll return 2 when running via 'R CMD check'. As the author, I obviously suggest using that function to query what amount of CPU resources your R process is allowed to use. For more info, see <https://parallelly.futureverse.org/index.html#availablecores-vs-paralleldetectcores>. /Henrik PS. I'm in the camp of *not* having R packages parallelize by default. At least not until R and its community have figured out how to avoid ending up with nested parallelization (e.g. via dependencies) by mistake. We would also need a standard for end-users (and the sysadms on the machines they're running) to control the default number of CPU cores the R session may use. Right now we only have a few scattered settings for separate purposes, e.g. option 'mc.cores'/env var 'MC_CORES', and option 'Ncpus', which is not enough for establishing a de facto standard. On Tue, Nov 23, 2021 at 11:11 AM Dipterix Wang <dipterix.w...@gmail.com> wrote: > > Dear R wizards, > > I recently received an email from Prof. Ripley. He pointed out that my > package seriously violates the CRAN policy: "using 8 threads is a serious > violation of the CRAN policy”. By default the number of cores my package uses > is determined from system CPU cores. After carefully reading all the CRAN > policies, now I understand that CRAN does not allow a package to use more > than 2 CPU cores when checking a package. I can easily change my code to let > my tests comply to that constraint. > > However, this warning worries me because my package uses OpenMP. I got > “caught" partially because I printed the number of cores used in the package > startup message, and one of my test exceeded the time limit (which leads to > manual inspection). However, what if I develop a package that imports on > those openmp-dependent packages? (For example, data.table, fst…) These > packages use more than 2 cores by default. If not carefully treated, it’ll be > very easy to exceed that limit, and it’s very hard for CRAN to detect it. > > Is there any reliable way to let packages to know if they are on CRAN, so > they can set omp cores to 2 by default? > > Best, > - Dipterix > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel