我希望每个从属读取一个较大的单独级别的数据集,然后在给定参数向量的更新的情况下迭代查找主题级别的可能性。从属读取数据集,然后第一个从属引发该错误,以尝试计算主题级别的可能性-它找不到数据框。我猜测成功的广播读取命令是退出的R进程。因此,我的一般问题是-如何使数据在一次命令(读取)和要迭代的命令之间持久存在
我通过shell命令提交工作
sbatch --partition=multinode batch-rmpi-ex1mle.s
文件batch-rmpi-ex1mle.R
#!/bin/bash
#
# this file is batch-rmpi-ex1mle.sh
#
#SBATCH --ntasks=1051
#SBATCH --time=00:30:00
#SBATCH --mem-per-cpu=1024
#SBATCH --job-name="Rmpi_ex1mle"
#SBATCH --mail-type=BEGIN,END
#
cd $SLURM_SUBMIT_DIR
echo "Working from $(pwd)"
export OMPI_MCA_mpi_warn_on_fork=0
#Run this from mpirun so that R starts in an MPI environment
module load R
module load openmpi/3.0.2/gcc-7.3.0-pmi2
mpirun -n 1 R CMD BATCH --no-restore --no-save --quiet \
main-rmpi-ex1mle.R main-rmpi-ex1mle.Rout
文件main-rmpi-ex1mle.R
if (!is.loaded("mpi_initialize")) {
library("Rmpi")
}
"%,%" <- function(x,y)paste(x,y,sep="")
wd <- Sys.getenv("SLURM_SUBMIT_DIR")
source(wd %,% "/" %,% "funs-rmpi-ex1mle.R")
N <- 1051
dsname <- "dat.rda"
load(wd %,% "/" %,% (N-1) %,% "/" %,% dsname)
p <- ncol(DAT.i)
B <- rep(0, p)
# Spawn ns workers
mpi.spawn.Rslaves(nslaves=N-1)
# broadcast common code to all slaves
mpi.bcast.Robj2slave(read.i)
mpi.bcast.Robj2slave(logL.i)
# The command we want to run on all the nodes/processors we have
mpi.bcast.cmd(read.i, N-1, dsname, wd)
fit.glm <- nlminb(start=B, obj=FlogL, n=N-1)
fit.glm.s <- summary(fit.glm)
save(list=c("fit.glm", "fit.glm.s"), file=fit-glm-par.rda")
# Close down the MPI processes and quit
mpi.close.Rslaves(dellog=FALSE)
mpi.exit()
funs-rmpi-ex1mle.R文件
"%,%" <- function(x,y)paste(x,y,sep="")
"FlogL" <-
function(B, n)
{
ns <- n
logL <- sum(unlist(mpi.apply(1:ns, logL.i, B=B, comm=1)))
-logL
}
#workercode
"read.i" <-
function(ns, dsname, wd)
{
"%,%" <- function(x,y)paste(x,y,sep="")
imx <- ceiling(logb(ns, 10))
# which slave am I?
i <- mpi.comm.rank()
i.digs <- ceiling(logb(1 + i, 10))
z <- paste(rep("0", imx-i.digs), collapse="")
i.s <- z %,% i
load(wd %,% "/" %,% i.s %,% "/" %,% dsname)
}
"logL.i" <-
function(B, i)
{
attach(DAT.i)
b0 <- B[1]
b <- B[-1]
P.i <- logit.inv(b0 + X%*%b)
D*log(P.i) + (1-D)*log(1-P.i)
}