Skip to content

Instantly share code, notes, and snippets.

@LTLA
Created October 19, 2019 00:28
Show Gist options
  • Save LTLA/e3a10e18cd32994bac0281a839ae47a8 to your computer and use it in GitHub Desktop.
Save LTLA/e3a10e18cd32994bac0281a839ae47a8 to your computer and use it in GitHub Desktop.
Efficiency problems with MulticoreParam
library(scRNAseq)
hESCs <- LaMannoBrainData('human-es')
# Trivial function to get something working on two matrices.
FUN <- function(x, y) { list(colSums(x), colSums(y)) }
library(BiocParallel)
BPPARAM1 <- SerialParam()
BPPARAM5 <- MulticoreParam(5)
# This function does nothing but split a matrix into chunks according
# to the number of cores it will eventually be parallelized over.
M <- SingleR:::.prep_for_parallel(assay(hESCs), BPPARAM=BPPARAM5)
bpstart(BPPARAM1)
system.time({
bplapply(M, FUN=FUN, y=assay(hESCs)) # 0.2 seconds
})
bpstop(BPPARAM1)
bpstart(BPPARAM5)
system.time({
bplapply(M, FUN=FUN, y=assay(hESCs), BPPARAM=BPPARAM5) # 2.6 seconds
})
bpstop(BPPARAM5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment