R/setup.ncore.R

Defines functions setup.ncore

Documented in setup.ncore

setup.ncore <- function(ncore, bigmem = FALSE) {
  if(is.null(ncore) || ncore > 1) {
    os1 <- .Platform$OS.type
    if(os1 == "windows") {
       if(is.null(ncore)) 
          ncore = 1
       else
          stop("Multicore is NOT supported in Windows (Set ncore = 1 or NULL)")
    } else {
       if(bigmem) {
         oops <- requireNamespace("bigmemory", quietly = TRUE)
         if(!oops) {
           if(is.null(ncore))
             ncore <- 1
           else
             stop("Please install the bigmemory package from CRAN for running with multicore")
         }
       }
       if(is.null(ncore))
         ncore = parallel::detectCores()

       ## parallel::detectCores() returns 'NA' if the answer is unknown
       if(is.na(ncore))
           ncore <- 1
       
       # Following lines check R internal varible for potential limit on multicore usage
       # Normally it does nothing, but will be helpful in running `R CMD check --as-cran`
       if(ncore > 1) {
          chk <- tolower(Sys.getenv("_R_CHECK_LIMIT_CORES_", ""))
          if (nzchar(chk) && (chk != "false")) ncore = 1
       }

    }
  }
  options(mc.cores = ncore)
  return(ncore)
}

Try the bio3d package in your browser

Any scripts or data that you put into this service are public.

bio3d documentation built on Oct. 27, 2022, 1:06 a.m.