[R-sig-hpc] Error in UseMethod("stopCluster") : no applicable method for 'stopCluster' ...

Marius Hofert marius.hofert at math.ethz.ch
Fri Sep 21 09:47:49 CEST 2012


Dear expeRts,

If I run the minimal example below, I obtain:

Loading required package: Rmpi
Loading required package: grDevices
Loading required package: grDevices
Loading required package: grDevices
Loading required package: grDevices
	4 slaves are spawned successfully. 0 failed.
Error in UseMethod("stopCluster") :
  no applicable method for 'stopCluster' applied to an object of class "c('spawnedMPIcluster', 'MPIcluster', 'cluster')"

However, if I run the body of the function (linewise; without calling the
function), everything works. Why is that so?

Cheers,

Marius


grid <- expand.grid(a=1:4, b=2:10)
ngrid <- nrow(grid)
f <- function(x) sum(x)

ex <- function() {
    cl <- snow::makeCluster(parallel::detectCores(), type="MPI")
    on.exit(snow::stopCluster(cl))
    RNGkind("L'Ecuyer-CMRG")
    parallel::clusterExport(cl, varlist=c("f", "grid"))
    parallel::clusterApply(cl, seq_len(ngrid), function(i) f(grid[i,]))
}

res <- ex()



More information about the R-sig-hpc mailing list