Skip to content

Commit

Permalink
Updated the PI calculation test
Browse files Browse the repository at this point in the history
* correct the formula
* output the final result
  • Loading branch information
chunhualiao committed Dec 13, 2017
1 parent 99d2d52 commit 2493459
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions micro-benchmarks/pireduction-orig-no.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,22 @@ Classic PI calculation using reduction
*/

#define num_steps 2000000000

int main(int argc, char** argv)

#include <stdio.h>
int main(int argc, char** argv)
{
double pi = 0;
double pi = 0.0;
int i;
#pragma omp parallel for reduction(+:pi)
double x, interval_width;
interval_width = 1.0/(double)num_steps;

#pragma omp parallel for reduction(+:pi) private(x)
for (i = 0; i < num_steps; i++) {
pi += 1.0 / (i * 4.0 + 1.0);
x = (i+ 0.5) * interval_width;
pi += 1.0 / (x*x + 1.0);
}
pi = pi * 4.0;

pi = pi * 4.0 * interval_width;
printf ("PI=%f\n", pi);
return 0;
}

0 comments on commit 2493459

Please sign in to comment.