The current code for the Parallel Pi program:
#include <stdio.h>
int main(){
double numOfSteps=1000000000;
double deltaX=2/numOfSteps;
double x;
double piSum=0;
for(x=-1;x<=1;x=x+deltaX){
piSum=piSum+deltaX*sqrt(1-x*x);
}
piSum=piSum*2;
printf(“%.30f\n”,piSum);
return 0;
}
The program uses Euler’s method to evaluate the integral
2*(1-x^2)^(1/2)dx from x=-1 to 1, which equals pi.
The output of the program is 3.141592621098947990532224139315 which is accurate to 8 decimal places and took 7 seconds to run (without parallel processing).