代码之家  ›  专栏  ›  技术社区  ›  David

使用并联功能时,起重机检查失败。

  •  1
  • David  · 技术社区  · 8 年前

    我想向Cran提交一个包,它使用 parallel::makeCluster(parallel::detectCores()) .

    当我构建包时,一切都正常,但是当我检查包时( devtools::check(document = FALSE) )返回错误:

    Running examples in ‘TESTER-Ex.R’ failed
    The error most likely occurred in:
    
    > base::assign(".ptime", proc.time(), pos = "CheckExEnv")
    > ### Name: hello_world
    > ### Title: Prints hello world
    > ### Aliases: hello_world
    > 
    > ### ** Examples
    > 
    > hello_world()
    Error in .check_ncores(length(names)) : 8 simultaneous processes spawned
    Calls: hello_world -> <Anonymous> -> makePSOCKcluster -> .check_ncores
    Execution halted
    

    我在一个只有一个功能的MWE包(测试仪)中重新创建了该错误。 hello_world ,我已经上传了整个 TESTER-package 但它应该可以从以下函数中复制。

    #' Prints hello world
    #'
    #' @return nothing
    #' @export
    #'
    #' @examples
    #' hello_world()
    hello_world <- function() {
    
      # initiate cluster
      cl <- parallel::makeCluster(parallel::detectCores())
    
      # stop cluster
      parallel::stopCluster(cl)
    
      cat("Hello World\n")
      return(invisible(NULL))
    }
    

    我查过了 Writing R Extensions 但找不到与此问题相关的任何内容,我也找不到与此相关的问题。

    有什么想法是什么导致这个错误以及如何解决它吗?

    2 回复  |  直到 8 年前
        1
  •  10
  •   Alexis    8 年前

    CRAN将可用于包装的芯数限制为2, 出于性能原因。 邮件列表中有一个线程, 我相信, 但我现在找不到。

    在我的测试中,我使用如下的方法:

    chk <- Sys.getenv("_R_CHECK_LIMIT_CORES_", "")
    
    if (nzchar(chk) && chk == "TRUE") {
        # use 2 cores in CRAN/Travis/AppVeyor
        num_workers <- 2L
    } else {
        # use all cores in devtools::test()
        num_workers <- parallel::detectCores()
    }
    
        2
  •  0
  •   Carlos Santillan    8 年前

    我认为问题是没有加载库并行程序

    在您的命名空间文件中,您应该加载包

    import(parallel)
    
    推荐文章