Created
October 17, 2011 12:07
-
-
Save armstrtw/1292481 to your computer and use it in GitHub Desktop.
deathstar example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(AWS.tools) | |
library(rzmq) | |
estimatePi <- function(seed) { | |
set.seed(seed) | |
numDraws <- 1e6 | |
r <- .5 | |
x <- runif(numDraws, min=-r, max=r) | |
y <- runif(numDraws, min=-r, max=r) | |
inCircle <- ifelse( (x^2 + y^2)^.5 < r , 1, 0) | |
sum(inCircle) / length(inCircle) * 4 | |
} | |
cl <- startCluster(ami="ami-9d5f93f4",key="maher-ave",instance.count=2,instance.type="c1.xlarge") | |
print("starting sim.") | |
run.time <- system.time(ans <- zmq.cluster.lapply(cluster=cl$instances[,"dnsName"],as.list(1:1e3),estimatePi)) | |
print("sim completed.") | |
res <- terminateCluster(cl) | |
print(mean(unlist(ans))) | |
print(run.time) | |
print(attr(ans,"execution.report")) | |
pi.est <- mean(unlist(ans)) | |
print("result:") | |
print(pi.est) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment