Skip to content

Instantly share code, notes, and snippets.

@armstrtw
Created October 17, 2011 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armstrtw/1292481 to your computer and use it in GitHub Desktop.
Save armstrtw/1292481 to your computer and use it in GitHub Desktop.
deathstar example
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