I am new to multicore in R and is trying out the snowfall package to test if it is possible to speed up the apply function.
Not sure what went wrong but my multi-core implementation of sfApply() is always about 2 times slower than the apply()
Any help is greatly appreciated! Thanks in advance.
Single core example - complete to about 1.3 seconds in my PC:
x=2000
y=10000
startTime <- proc.time()
randomX <- sample(1:100,x*y, replace=T)/100+0.5
randomMatrix <- matrix(NA,x,y)
randomMatrix[,] <- randomX
randomRetX <- apply(randomMatrix,2,cumprod)
endTime <- proc.time()
endTime-startTime
Snowfall Implementation - close to 3 secs in my PC:
library(snowfall)
sfInit( parallel=TRUE, cpus=4)
x=2000
y=10000
startTime <- proc.time()
randomX <- sample(1:100,x*y, replace=T)/100+0.5
randomMatrix <- matrix(NA,x,y)
randomMatrix[,] <- randomX
randomRetX <- sfApply(randomMatrix,2,cumprod)
endTime <- proc.time()
endTime-startTime
sfStop()