2

I have a problem with using the variable "Druckfaktor" in parLapply.

My code looks like this:

  Druckfaktor <- 1.3      

  no_cores <- detectCores()-1
  cl <- makeCluster(no_cores)

  S <- parLapply(cl,m.list,function(x) {
        s <- diag(x[2:4])
        s[1,2] <- s[2,1] <- x[5]
        s[2,3] <- s[3,2] <- x[6]
        s[3,1] <- s[1,3] <- x[7]

        VD <- eigen(s)
        V <- VD$vectors
        D <- VD$values
        D[D<0] <- D[D<0]/Druckfaktor
        s <- V %*% diag(D) %*% t(V)
        c(x[1],s[1,1],s[2,2],s[3,3],s[1,2],s[2,3],s[3,1])
  })
  stopCluster(cl)code here

Unfortunately the function answers with:

Error in checkForRemoteErrors(val) : 11 nodes produced errors; first error: Objekt 'Druckfaktor' nicht gefunden

How can I use this "Druckfaktor" together with parLapply?

Thanks

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75

1 Answers1

1

You have to use clusterExport:

clusterExport(cl = NULL, varlist, envir = .GlobalEnv)

clusterExport assigns the values on the master R process of the variables named in varlist to variables of the same names in the global environment (aka ‘workspace’) of each node. The environment on the master from which variables are exported defaults to the global environment.

In your case:

Druckfaktor <- 1.3      

no_cores <- detectCores()-1
cl <- makeCluster(no_cores)
clusterExport(cl, c("Druckfaktor"))
[...]
Community
  • 1
  • 1
Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75