Last active
August 29, 2015 14:17
-
-
Save sriramkswamy/2a341b9d2fbb773de494 to your computer and use it in GitHub Desktop.
Hello world equivalent for Parallel Computing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This program will numerically compute the integral of | |
4/(1+x*x) | |
from 0 to 1. The value of this integral is pi -- which | |
is great since it gives us an easy way to check the answer. | |
The is the original sequential program. It uses the timer | |
from the OpenMP runtime library | |
History: Written by Tim Mattson, 11/99. | |
Edited for this gist by Sriram Krishnaswamy, 3/15 | |
*/ | |
#include <stdio.h> | |
static long num_steps = 100000000; | |
double step; | |
int main () | |
{ | |
int i; | |
double x, pi, sum = 0.0; | |
step = 1.0/(double) num_steps; | |
for (i=1;i<= num_steps; i++) | |
{ | |
x = (i-0.5)*step; | |
sum = sum + 4.0/(1.0+x*x); | |
} | |
pi = step * sum; | |
printf("\n pi is %lf \n ",pi); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment