main
test-branch
|
Last change
on this file since beab7f2 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:
1.2 KB
|
| Line | |
|---|
| 1 | /******************************************************************************
|
|---|
| 2 | * FILE: omp_bug2.c
|
|---|
| 3 | * DESCRIPTION:
|
|---|
| 4 | * Another OpenMP program with a bug.
|
|---|
| 5 | * AUTHOR: Blaise Barney
|
|---|
| 6 | * LAST REVISED: 04/06/05
|
|---|
| 7 | ******************************************************************************/
|
|---|
| 8 |
|
|---|
| 9 | // online source: https://computing.llnl.gov/tutorials/openMP/samples/C/omp_bug2.c
|
|---|
| 10 |
|
|---|
| 11 | #include <omp.h>
|
|---|
| 12 | #include <stdio.h>
|
|---|
| 13 | #include <stdlib.h>
|
|---|
| 14 |
|
|---|
| 15 | int main (int argc, char *argv[])
|
|---|
| 16 | {
|
|---|
| 17 | int nthreads, i, tid;
|
|---|
| 18 | float total;
|
|---|
| 19 |
|
|---|
| 20 | /*** Spawn parallel region ***/
|
|---|
| 21 | #pragma omp parallel
|
|---|
| 22 | {
|
|---|
| 23 | /* Obtain thread number */
|
|---|
| 24 | tid = omp_get_thread_num();
|
|---|
| 25 | /* Only master thread does this */
|
|---|
| 26 | if (tid == 0) {
|
|---|
| 27 | nthreads = omp_get_num_threads();
|
|---|
| 28 | printf("Number of threads = %d\n", nthreads);
|
|---|
| 29 | }
|
|---|
| 30 | printf("Thread %d is starting...\n",tid);
|
|---|
| 31 |
|
|---|
| 32 | #pragma omp barrier
|
|---|
| 33 |
|
|---|
| 34 | /* do some work */
|
|---|
| 35 | total = 0.0;
|
|---|
| 36 | #pragma omp for schedule(dynamic,10)
|
|---|
| 37 | for (i=0; i<1000000; i++)
|
|---|
| 38 | total = total + i*1.0;
|
|---|
| 39 |
|
|---|
| 40 | printf ("Thread %d is done! Total= %e\n",tid,total);
|
|---|
| 41 |
|
|---|
| 42 | } /*** End of parallel region ***/
|
|---|
| 43 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.