simulations's People
simulations's Issues
How to parallelize the simulations in R?
Parrallel computations stack-over-flow resolution.
Results
No 1
Simulations code
m1 <- vector("list", 100)
library(parallel)
cl <- makeCluster(detectCores())
clusterEvalQ(cl, library(Rpickands))
system.time({
m1 <- parLapply(cl, 1:100,Take_expected_value, copy_number=100000,points=10000)
})
stopCluster(cl)
user system elapsed
0.22 0.91 2741.93
plot(unlist(m1)/1:100, ylim=c(0,3))
abline(h=1/(sqrt(pi)), col="red")
unlist(m1)
Results:
[1] 2.696103 3.824087 4.757944 5.782585 6.103098 8.314943 7.933611 8.586543 9.239043 11.644069 10.191150 12.010007
[13] 16.825036 14.475594 13.182947 14.777401 10.451305 23.840736 14.237660 9.955883 17.517705 19.271054 14.542429 12.563869
[25] 11.377340 10.100034 19.189640 12.080305 14.395206 22.932530 11.070851 75.039759 10.139179 28.693873 10.352961 14.428169
[37] 10.980427 13.175679 18.998276 10.090254 10.091116 13.606485 12.646165 12.196682 15.277995 10.864889 10.761174 12.558026
[49] 11.161201 21.001675 9.187723 20.033081 8.636519 26.310541 67.970616 10.430356 10.746864 14.495912 19.766499 12.845559
[61] 11.045934 11.820578 10.737559 11.564290 13.168917 10.964343 16.186598 17.438162 13.712377 24.905167 22.606472 9.789053
[73] 16.089995 11.796208 23.471996 10.010266 12.803666 10.331008 19.545839 14.429806 80.925815 10.553487 20.343777 19.146669
[85] 14.432933 10.713293 9.557530 9.406336 12.601006 10.623573 59.562875 10.918457 14.719750 14.125113 10.156976 10.098214
[97] 10.500530 10.508240 14.317996 14.265341
Plot of results -> unlist(m1)/1:100
Some time elapsed of generating from rnorm
Code
library(parallel)
cl <- makeCluster(detectCores())
clusterEvalQ(cl, library(Rpickands))
system.time({
ma <- rnorm(10^9)
})
stopCluster(cl)
Time:
user system elapsed
70.68 2.80 77.47
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.