main
test-branch
|
Last change
on this file since bb03188 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>
|
|---|
| 2 | static long num_steps = 100000;
|
|---|
| 3 | double step;
|
|---|
| 4 | #define NUM_THREADS 2
|
|---|
| 5 | void 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.