Open main menu

CDOT Wiki β

Changes

Team Titans

1,152 bytes added, 05:18, 15 October 2015
Calculation of Pi
== Progress ==
=== Assignment 1 ===
 
===Calculation of Pi===
 
 
I decided on finding a technique which is the most efficient way to calculate pi. I found one way of doing this on http://www.codecodex.com/wiki/Calculate_digits_of_pi as seen below. By parallelizing the code, it could reduce the computation time considerably.
 
void pi_digits(int digits) {
int carry = 0;
int arr[digits + 1];
for (int i = 0; i <= digits; ++i)
arr[i] = ARRINIT;
for (int i = digits; i > 0; i-= 14) {
int sum = 0;
for (int j = i; j > 0; --j) {
sum = sum * j + SCALE * arr[j];
arr[j] = sum % (j * 2 - 1);
sum /= j * 2 - 1;
}
printf("%04d", carry + sum / SCALE);
carry = sum % SCALE;
}
}
 
After profiling, I get the following results:
 
Flat profile:
 
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
100.00 1.56 1.56 pi_digits(int)
 
===Image Manipulation===