0

I am trying to break this loop over multiple cores. For each loop i is sequentially changed from 1 to 16. At the moment it isn't breaking over the cores. Thank you for your help!

cl <- makeCluster((detectCores()-2))
registerDoParallel(cl)                 

clusters <- 1:16

foreach(i = clusters, .packages = c("tidyverse","magrittr")) %dopar% {

Encode.all.cl <-  Encode.all.t %>%
filter(cluster == i) %>%
select(-cluster)

Encode.all.cl.2 <- data.frame(t(Encode.all.cl)) %>%
set_rownames(colnames(Encode.all.cl)) %>%
set_colnames(rownames(Encode.all.cl))


Encode.all.cl.3 <- Encode.all.cl.2 %>%
mutate(.,count = rowSums(Encode.all.cl.2)) %>%
set_rownames(colnames(Encode.all.cl)) %>%
set_colnames(c(rownames(Encode.all.cl), "count")) %>%
filter(., count >= ncol(Encode.all.cl.2)*0.9) %>% #common in 90% of peaks
rownames_to_column(var = "Peak") %>%
dplyr::select(Peak) %>%
set_colnames("Cluster")

consensusPeaks[[i]] <- Encode.all.cl.3

print(paste0("Finished cluster ", i))

}

stopCluster(cl)
Ludojw
  • 1
  • 1
    What exactly do you mean by "it isn't breaking over the cores"? You mean it's not running in parallel? How can you tell? What is the value of `detectCores()-2`? – MrFlick Jan 07 '21 at 20:37
  • Yes, it is not running in parallel. It pastes the finished statement one at a time and also runs slower than expected if running in parallel. the result of `detectCores()-2` is 6. – Ludojw Jan 07 '21 at 21:37
  • 1
    I don't see why it should not run parallel. Try to make the code [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – mischva11 Jan 07 '21 at 22:16

0 Answers0