首页 > 解决方案 > 如何通过 bsub 提交 doMPI 作业?

问题描述

我正在尝试使用带有 doMPI 包的 foreach 循环提交 R 脚本。不幸的是,该过程在 50 个请求的节点中的每一个上启动。但我希望每个节点都用于执行其中一次 foreach 迭代。

这就是我提交 R 脚本的方式。

bsub -n 50 -J "test doMPI 50" 'mpirun -n 1 R --slave -f sincMPI.R'

的内容sincMPI.R

suppressMessages(library(doMPI))

# Create and register an MPI cluster
cl <- startMPIcluster()
registerDoMPI(cl)

x <- 1:200
out_path = "out_dt.csv"

foreach(y=x, .combine="cbind") %dopar% {
  library(data.table, quietly = T)
  library(flock, quietly = T)
  dt_out <- data.table(
    times1 = x*1,
    times2 = x*2,
    times3 = x*3
  )
  
  lock <- flock::lock(out_path)
  fwrite(dt_out, out_path, append = TRUE)
  flock::unlock(lock)
}

# Shutdown the cluster and quit
closeCluster(cl)
mpi.quit()

这改编自 doMPI 包中的示例。

结果 in"out_dt.csv"现在的行数比预期的多 50 倍,因为每个节点都在执行所有 foreach 迭代。

为什么会发生这种情况?如何将 50 个内核中的 49 个用作从属进程,而不是全部作为主进程?

标签: rparallel-processingmpilsfdompi

解决方案


推荐阅读