Question:
So I want to make a program that calculates pi...?
anonymous
2009-01-13 09:02:58 UTC
I know this idea has been done to death but I'm about to finish my Bachelors and this would be a great project to add to my portfolio. It's got algorithms, networking (hardware and software), saving to a file, and a lot of unique problem solving.

The application will run on n computers which will work together to calculate as many digits of pi as possible. I'm thinking one server computer which then breaks the problem apart and delegates subproblems out to other computers that are running the application. Since you can buy a terabyte HD for $100 I would like to fill up an entire terabyte with the digits of pi. So that's the basic idea. Do you have any advice or guidance?

Some things I am thinking about:
1. The algorithm. How to break the problem apart. e.g. 8/2 = 4. 4/2 to computerA 4/2 to computerB. How I am going to write it and send out the subproblems to the other computers?

2.Determining connection speed? Does the connection speed of any given computer create a bottleneck in the program? In other words, would it just be faster to do it on one computer than send it to other computers for processing? This could involve having to analyze each computers hardware to determine if it's worth sending the subproblem couldn't it?

3. I will use Java or C# but I wont be able to use primitive data types because they don't have any numbers that big. So what do I use?

4. Is Java a bad language to use for this? I know scientific programming languages are usually used but these are the only two languages that I know well enough to attempt this problem. The JVM would slow things down wouldn't it? That is, the same program with C# would be faster right? But then if I use Java I'll be able to run it on more computers.

5. I'm not sure how the numbers will be stored but since I will only be using 10 different characters it doesn't seem very effecient to store them in a format that allows for many more than 10 characters. Like, in ANSI each character will be stored as 1 byte but I would only need 4 bits (1010 = 10). How on earth would I go about doing this? Of course, I would also have to partition the hard drive to a multiple of 4 bits.

I think I can do this but it will be a huge challenge for me. I am not even in the planning phase right now. Just the dreaming phase. Any help at all would be appreciated.
Three answers:
Fred W
2009-01-13 15:03:39 UTC
Calculating PI:



First answer, in TECO (an editor dating back to the early 60's):



GZ0J\UNQN"E 40UN ' BUH BUV HK

QN< J BUQ QN*10/3UI

QI< \+2*10+(QQ*QI)UA B L K QI*2-1UJ QA/QJUQ

QA-(QQ*QJ)-2\ 10@I// -1%I >

QQ/10UT QH+QT+48UW QW-58"E 48UW %V ' QV"N QV^T ' QWUV QQ-(QT*10)UH >

QV^T @^A/

/HKEX



It's a macro. Store into a file "pi.tec" (it ends with two ESC characters, decimal 27), and execute:



[user@localhost teco]$ MUNG pi.tec

3141592653589793238462643383279502884197

[user@localhost teco]$



In SCHEME:



http://www.corriganjc.net/code/pi/pi_scheme.html



This program, when run on a 1.6ghz ATOM processor with 512mb (netbook), and timed:



[user@localhost ~]$ time gsi pi.scm

31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989



real 0m6.399s

user 0m6.064s

sys 0m0.240s

[user@localhost ~]$



gsi is Gambit-C, this was run in interpreter mode, not compiled. It took 6 seconds to compute PI to 1000 places. Gambit-C also offers Termite, which will allow you to distribute a computation.



Of course the interesting thing is the distributed computation of PI.



http://en.wikipedia.org/wiki/Software_for_calculating_%CF%80



Of interest is Fabrice Bellards work (he is also known for the TCC compiler, and the QEMU emulator). This allows for direct calculation of binary digits of PI and also allows distribution.



Good luck with your project.
Tasm
2009-01-13 09:15:40 UTC
Forgot the algorithm for pi.



The fact that your making a system like the Seti@home is awesome.



If you can make a cpu sharing program that allows a manager to dump in the calculation and another computer to pick up the calculation and return the result. I would give you an A+.
E=mc²
2009-01-13 09:11:00 UTC
there are many math programs i use buth maple and mat lab


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...