-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CC=g++ | ||
|
||
CCFLAGS=-O3 -std=c++11 -std=gnu++11 | ||
|
||
LIBS = -lm | ||
|
||
CPP_COMMON = ../../Cpp_common | ||
|
||
INC = -I $(CPP_COMMON) | ||
|
||
pi: pi.cpp | ||
$(CC) $^ $(INC) $(CCFLAGS) $(LIBS) -o $@ | ||
|
||
clean: | ||
rm -f pi |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
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. | ||
Ported to C++ by Tom Deakin, August 2013 | ||
*/ | ||
|
||
#include "util.hpp" | ||
|
||
#include <cstdio> | ||
static long num_steps = 100000000; | ||
double step; | ||
extern double wtime(); // returns time since some fixed past point (wtime.c) | ||
|
||
|
||
int main () | ||
{ | ||
int i; | ||
double x, pi, sum = 0.0; | ||
|
||
|
||
step = 1.0/(double) num_steps; | ||
|
||
util::Timer timer; | ||
|
||
for (i=1;i<= num_steps; i++){ | ||
x = (i-0.5)*step; | ||
sum = sum + 4.0/(1.0+x*x); | ||
} | ||
|
||
pi = step * sum; | ||
double run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0; | ||
printf("\n pi with %ld steps is %lf in %lf seconds\n", num_steps, pi, run_time); | ||
} |