File: pi.R

package info (click to toggle)
r-cran-foreach 1.4.2-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 772 kB
  • ctags: 3
  • sloc: sh: 58; makefile: 1
file content (12 lines) | stat: -rw-r--r-- 207 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
library(foreach)

w <- getDoParWorkers()
n <- 10000000
h <- 1 / n

pi <- foreach(i=1:w, .combine='+') %dopar% {
  x <- h * (seq(i, n, by=w) - 0.5)
  h * sum(4 / (1 + x * x))
}

cat(sprintf('pi = %f\n', pi))