Skip to content

Instantly share code, notes, and snippets.

@sriramkswamy
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sriramkswamy/2a341b9d2fbb773de494 to your computer and use it in GitHub Desktop.
Save sriramkswamy/2a341b9d2fbb773de494 to your computer and use it in GitHub Desktop.
Hello world equivalent for Parallel Computing
/*
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