Giter Site home page Giter Site logo

juerei / pi_quadrature Goto Github PK

View Code? Open in Web Editor NEW

This project forked from russel/pi_quadrature

0.0 0.0 0.0 1.9 MB

Various implementations in various languages of approximating π using quadrature. This is an embarrassingly parallel problem to investigate scaling.

License: GNU General Public License v3.0

Ada 1.64% C# 2.97% Python 28.71% C++ 8.22% C 3.14% Ceylon 2.10% Chapel 2.32% Clojure 1.95% Java 9.27% D 3.70% Dart 0.27% Erlang 2.76% Fantom 1.44% Fortran 2.08% Go 1.23% Groovy 21.22% Haskell 2.14% JavaScript 1.23% Julia 1.80% Kotlin 1.81%

pi_quadrature's Introduction

π 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.