R: parallel computing unstable with Brew version of R #7
-
Here is a simple script for LDA (linear discriminant analysis) simulation in R, and my goal is to run 20 replicates in parallel. library(MASS)
library(parallel)
library(doParallel)
num_cores <- detectCores()
registerDoParallel(cores = num_cores)
data <- list()
reps <- 20
## generate data
for (i in 1:reps) {
data[[i]] <-
list(x = rbind(mvrnorm(100, rep(0, 50), diag(50)),
mvrnorm(100, rep(1, 50), diag(50))),
xnew = rbind(mvrnorm(100, rep(0, 50), diag(50)),
mvrnorm(100, rep(1, 50), diag(50))),
y = rbind(rep(0, 100), rep(1, 100)),
ynew = rbind(rep(0, 100), rep(1, 100)))
}
## function producing prediction error for LDA
lda_prediction_error <- function(data) {
fit_lda <- lda(data$x, as.factor(data$y))
ypred <- predict(fit_lda, data$xnew)$class
pe_lda <- mean(data$ynew != ypred)
return(pe_lda)
}
foreach(i = 1:reps, .verbose = TRUE) %dopar% lda_prediction_error(data[[i]])
mclapply(data, lda_prediction_error, mc.cores = num_cores) However, R hangs forever with either If I use sequential computing (use If I generate data with Then I tested the code under different scenarios:
The code above hangs in scenario 1, but works in 2, 3, 4, 5. From these experiments I think it is the Homebrew r formula that causes R to hang. I don't have the insight to find the culprit in the formula, so I am asking for help here. I am also interested to see if this issue is reproducible. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
I just rebuilt R with Homebrew r formula default args:
|
Beta Was this translation helpful? Give feedback.
-
I'm going to take a look at it sometime this week. R on Homebrew has a lot of issues that unfortunately few people have had time to look into. For the time being using the cask version of R is probably the way to go if you need this specific functionality. As a bonus, you'll be able to use pre-compiled binary packages from CRAN. |
Beta Was this translation helpful? Give feedback.
-
Issue solved in R 4.0.3. Edit: see Homebrew/homebrew-core#75506 |
Beta Was this translation helpful? Give feedback.
Issue solved in R 4.0.3.
Edit: see Homebrew/homebrew-core#75506