Quantcast
Channel: Eva & Quirinius
Viewing all articles
Browse latest Browse all 69

Calculating pi on the Pi

$
0
0
Here's a way to calculate pi (3.141592...) on the Raspberry Pi:

First get the source:

wget http://myownlittleworld.com/miscellaneous/computers/files/pi_css5/pi_css5_src.tgz
tar xvzf pi_css5_src.tgz
cd pi_css5_src/


If you would now run 'make', you would get errors. That's because of this line in Makefile:


CFLAGS += -march=i686 -malign-double


These flags are x86-only, which do not work on our Raspi's ARM. So let's get rid of that line: use an editor like vi or nano to comment out that line (put a # in front of it), or use the command line:


cp Makefile Makefile.org
sed -i -e "s/^CFLAGS +=/#CFLAGS +=/g" Makefile
grep march Makefile


The last command should now give (and note the "#" at the beginning of the line):

#CFLAGS += -march=i686 -malign-double

You should now run make:

make

If that goes without errors, the pi calculation can start:

./pi_css5 100000


The output should look like this:

pi@raspberrypi ~/pi_css5_src $ ./pi_css5 100000
Calculation of PI using FFT and AGM, ver. LG1.1.2-MP1.5.2a.memsave
initializing...
nfft= 32768
radix= 10000
error_margin= 0.000620286
calculating 131072 digits of PI...
AGM iteration
precision= 48: 0.48 sec
precision= 80: 0.49 sec
precision= 176: 0.48 sec
precision= 352: 0.49 sec
precision= 688: 0.48 sec
precision= 1392: 0.49 sec
precision= 2784: 0.48 sec
precision= 5584: 0.49 sec
precision= 11168: 0.48 sec
precision= 22336: 0.49 sec
precision= 44688: 0.48 sec
precision= 89408: 0.49 sec
precision= 178816: 0.48 sec
writing pi131072.txt...
7.61 sec. (real time)
pi@raspberrypi ~/pi_css5_src/ $ 


So that's 131072 digits of PI in 7.61 seconds. The result is in the file pi131072.txt

FWIW: on my laptop with Core i3 M370 2.40GHz laptop the same calculation only takes 0.29 seconds ...



Viewing all articles
Browse latest Browse all 69

Trending Articles