-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The Parallellzation is slow in Python using rpy2 #1052
Comments
I don't have |
It is the exactly the same R code, I just copied the R script to the robjects.r(''' '''). To teas out if this is due to the "doParallel", I did another test with pure for loop without using any parallelzation: R script which returns me 355.575s: getPrimeNumbers <- function(n) { res<- c() proc.time()-A Python script by using rpy2 which returns me 394.3394511249935s:
print("R code time is:", time.perf_counter()-A) |
I simplified the example to use import time
import rpy2.robjects as robjects
A = time.perf_counter()
robjects.r('''
getPrimeNumbers <- function(n) {
n <- as.integer(n)
if(n > 1e6) stop("n too large")
primes <- rep(TRUE, n)
primes[1] <- FALSE
last.prime <- 2L
for(i in last.prime:floor(sqrt(n)))
{
primes[seq.int(2L*last.prime, n, last.prime)] <- FALSE
last.prime <- last.prime + min(which(primes[(last.prime+1):n]))
}
which(primes)
}
library(parallel)
cl <- makeCluster(getOption("cl.cores", 2))
result <- clusterApply(cl = cl, fun = getPrimeNumbers, 10:10000)
''')
print("R code time is:", time.perf_counter()-A) |
Presumed to be a typo that makes the the python/rpy2 version of the code ask 10 times more work from R than the R-only version (thus making it at least that much slower). |
Describe the issue or bug
I've been using "doParalell" R library in the R code, it takes much shorter time in R to execute the code than I use rpy2 to run the same code using rpy2
To Reproduce
ask
has somebody else found the same issue as me ?
The text was updated successfully, but these errors were encountered: