processor. And I'm naturally seduced to do some experiment on parallel
programming. The result is far more than exciting. I tried the
following program:
library(snow)
cc <- makePVMcluster(2)
n.loop <- 10
n.size <- 1000
temp <- NULL
for(i in 1:n.loop){
x <- list(matrix(rnorm(n.size^2),n.size))
temp <- c(temp,x)
}
system.time(t.1 <- clusterApply(cc,temp,"solve"))
system.time(t.2 <- sapply(temp,"solve"))
The serial program took 23.9 seconds while the parallel one took only
3.0 seconds. That's more than double the performance!
Then I n.loop to 100 and n.size to 100. This time serial processing
outperformed parallel processing.
I guess this is a result of the trade-off between parallel
communication and computational time. When computational task is
relatively heavy, the time spent on communicating between processing
units are relatively insignificant. Thus the parallel method works
better. When the computational task is light, more time is wasted
sending messages. And the parallel way takes more time.
No comments:
Post a Comment