Parallelization handling

Only the search for expectation maximization is parallelized in QuantumClone - and used only if the number of cores set is strictly higher than 1. It parallelizes in priority the EM algorithm for different number of clusters then the iterations for a given number of clusters.

The parallelization is handled through parallel and foreach packages.

Gain of performance

First we create a data set to analyze:

set.seed(123)
Start.data<-QuantumCat(4,100,"AB")

Then we detect the number of cores on the computer, and create a reproducible analysis of the data with a different number of cores:

max.cores<-min(parallel::detectCores(),4)
print(max.cores)
## [1] 4
analysis<-function(ncores = 1,Start.data){
  set.seed(123)
  One_step_clustering(SNV_list = Start.data,ncores = ncores,contamination = c(0,0), 
                      save_plot = FALSE, Initializations = 2,preclustering = "FLASH",nclone_range = 2:10
)
}
mb<-microbenchmark(analysis(1,Start.data),analysis(2,Start.data),analysis(max.cores,Start.data),times = 5)
print(mb)
## Unit: seconds
##                             expr      min       lq     mean   median
##          analysis(1, Start.data) 4.876765 4.890748 4.938304 4.926384
##          analysis(2, Start.data) 3.220358 3.304035 3.343791 3.378552
##  analysis(max.cores, Start.data) 3.463822 3.504545 3.554144 3.539906
##        uq      max neval
##  4.973282 5.024340     5
##  3.403186 3.412823     5
##  3.588952 3.673497     5
autoplot(mb)+ylim(c(0,10))
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.