Error in mclapply(1:20, function(ii) { : Windows does not supprot 'mc.cores' > 1

Viewed 47

I try to reproduce and run the code from GitHub: https://github.com/sangwon-hyun/omd. I first try to run the code from the file: 01-climatology.Rmd (https://github.com/sangwon-hyun/omd/blob/master/main/01-climatology.Rmd)

When I run the code after the 296th line "Toy distances" part.

library(parallel)

start.time = Sys.time()
dists = mclapply(1:20, function(ii){
  printprogress(ii, 20, start.time = start.time)

  dat1 = darwindat %>% add_blob(c(-150, -25))
  dat2 = darwindat %>% add_blob(c(-150 + 2*ii, -25), rotate = (ii / 20) * 90)

  val1 = dat1 %>% pull(val)
  val2 = dat2 %>% pull(val)

  costm = form_cost_matrix(dat1)
  res = omd(M1_long = dat1,
            M2_long = dat2,
            p = 1,
            ## costm = costm,
            geodesic = TRUE)

  diffval = val1 - val2
  twodists = c(omd = res$dist, rmse = sqrt(sum((diffval)^2)))

  return(twodists)
}, mc.cores = 3)

distmat = do.call(rbind, dists) %>% as_tibble()  %>%
  tibble::add_column(shift = 2*(1:20)) %>%
  mutate(omd = omd-min(omd), rmse = rmse-min(rmse)) %>% 
  mutate(omd = omd/max(omd), rmse = rmse/max(rmse)) %>% 
  tidyr::pivot_longer(cols = c('omd', 'rmse')) 

saveRDS(distmat, file = file.path(datadir, "distmat-toy.RDS"))

It reports the error:

Error in mclapply(1:20, function(ii) { : Windows does not supprot 'mc.cores' > 1

I use R 4.2.0. How to fix this error?

0 Answers
Related