All Projects → russel → Pi_Quadrature

russel / Pi_Quadrature

Licence: GPL-3.0 License
Various implementations in various languages of approximating π using quadrature. This is an embarrassingly parallel problem to investigate scaling.

Programming Languages

python
139335 projects - #7 most used programming language
groovy
2714 projects
java
68154 projects - #9 most used programming language
C++
36643 projects - #6 most used programming language
scala
5932 projects
d
599 projects

π by Quadrature

This directory contains various implementations in various programming languages of the embarrassingly parallel problem of calculating an approximation of the value of π using quadrature. (Quadrature in this case is the process of finding the area under a curve using the approximation of filling the area with rectangles and summing the areas of the rectangles.)

The integral equation:

\fraction{\pi}{4} = \int_{0}^{1} \fraction{1}{1 + x^2} dx

leads to the following summation as an approximation:

\pi \approx \fraction{4}{n} \sum_{i = 1}^{n} \fraction{1}{1 + (\fraction{i - 0.5}{n})^2}

This summation can be partitioned into partial sums that are then summed. This is an embarrassingly parallel, data parallel problem that can check scalability. As well as actual data parallel solutions there are some simple scatter/gather variants to highlight the use of other tools for concurrency and parallelism. In all cases, if the speed of execution does not increase linearly with the number of processors available, there is an issue to investigate.

Various different idioms and techniques in the various languages are tried as part of showing which languages are better than others for this problem. Also the examples investigate the properties of, and indeed idioms and techniques appropriate to, the various languages.

A point on JVM "warm up" (i.e. the JIT). If loop variables are longs then there is a noticeable "warm up" effect and two executions prior to any timing executions are needed to have the code JITed. Using int loop variables there appears to be no such affect – in fact there is, but it is a relatively small effect and can effectively be ignored.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].