Git Product home page Git Product logo

weimingtom / pi_examples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ucl-rits/pi_examples

0.0 2.0 0.0 843 KB

A lot of ways to run the same way of calculating pi. Some of them are dumb.

License: Creative Commons Zero v1.0 Universal

Makefile 11.38% Ada 2.26% Shell 21.61% C# 4.78% Gnuplot 0.55% Fortran 10.64% C 11.07% Prolog 2.85% Common Lisp 3.22% Clojure 2.89% COBOL 3.13% C++ 3.22% D 1.57% Emacs Lisp 2.57% F# 1.31% Forth 3.44% Batchfile 0.28% Scheme 4.33% Go 6.65% Haskell 2.24%

pi_examples's Introduction

Pi calculating examples

These are intended as examples people can run to show how to run code from jobs, the terminal, or where ever else.

We (UCL RITS) use some of these for cluster training, showing users how to run MPI jobs and demonstrating different parallelisation mechanisms and so on.

The others are mostly just the result of learning a new thing, wanting to do something ridiculous, or just wondering what the performance would be like.

Maths

They calculate pi using a numerical integration of

           1                                                                   
   y = ---------                                                               
        1 + x²                                                                

The indefinite integral of (1 + x²)⁻¹ wrt x is tan⁻¹ x (+ constant)

OIOW:

\int\frac{1}{1+x^2}\mathrm{d} x = \tan^{-1} x + c                             

Evaluating that integral between x = 0 and x = 1 gives us π/4

 \int^{1}_0\frac{1}{1+x^2}\mathrm{d} x = \frac{\pi}{4}                         

So if we add the area of sufficiently many y-high rectangles between 0 and 1
for y = (1+x²)⁻¹ , and multiply by 4, we should get a decent approximation for π.

Running

So that we can automatically test these, each directory should have a run.sh that builds and runs the example. Please use make unless you really can't (just to minimise additional dependencies).

Output Format

To aid in comparison, when writing new ones or updating old ones, here's a few specifications:

  • If convenient, they may optionally take an argument that is the number of slices to use.
  • They are not required to act sensibly if the number of slices is fewer than the number of workers.
  • They should produce output following the scheme below:
Calculating PI using:
  1000 slices
  16 MPI tasks
  2 OpenMP threads per task
Worker checkins:
  MPI task 1, thread 0 calculating slices: [0:10000)
  MPI task 0, thread 1 calculating slices: [10000:19999)
Obtained value of PI: 3.141592645453890
Time taken: 0.4124 seconds

Worker checkin strings should be adapted to be appropriate to the given parallelisation method, obviously, but should aim to follow the format:

method number, method number, method number calculating slices: boundary specifier

Or for automatic distributions:

method number calculating automatic work allocation

If timing information has not yet been implemented, the following line may replace the time line:

No time data obtained

Optionally the following line may be appended where applicable:

Kahan summation difference: 0.00531

pi_examples's People

Contributors

owainkenwayucl avatar ikirker avatar

Watchers

weimingtom avatar  avatar

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.