source: CIVL/examples/omp/pi1.c@ 8190175

main test-branch
Last change on this file since 8190175 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 465 bytes
Line 
1#include <omp.h>
2static long num_steps = 100000;
3double step;
4#define NUM_THREADS 2
5void main ()
6{ int i; double x, sum, pi=0.0;
7 step = 1.0/(double) num_steps;
8 omp_set_num_threads(NUM_THREADS)
9#pragma omp parallel private (x, sum)
10 {
11 id = omp_get_thread_num();
12 for (i=id,sum=0.0;i< num_steps;i=i+NUM_THREADS){
13 x = (i+0.5)*step;
14 sum += 4.0/(1.0+x*x);
15 }
16#pragma omp critical
17 pi += sum
18 }
19}
Note: See TracBrowser for help on using the repository browser.