OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [libgomp/] [testsuite/] [libgomp.c/] [omp_workshare4.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/******************************************************************************
2
* OpenMP Example - Combined Parallel Loop Work-sharing - C/C++ Version
3
* FILE: omp_workshare4.c
4
* DESCRIPTION:
5
*   This is a corrected version of the omp_workshare3.c example. Corrections
6
*   include removing all statements between the parallel for construct and
7
*   the actual for loop, and introducing logic to preserve the ability to
8
*   query a thread's id and print it from inside the for loop.
9
* SOURCE: Blaise Barney  5/99
10
* LAST REVISED: 03/03/2002
11
******************************************************************************/
12
 
13
#include <omp.h>
14
#include <stdio.h>
15
#define N       50
16
#define CHUNKSIZE   5
17
 
18
main ()  {
19
 
20
int i, chunk, tid;
21
float a[N], b[N], c[N];
22
char first_time;
23
 
24
/* Some initializations */
25
for (i=0; i < N; i++)
26
  a[i] = b[i] = i * 1.0;
27
chunk = CHUNKSIZE;
28
first_time = 'y';
29
 
30
#pragma omp parallel for     \
31
  shared(a,b,c,chunk)            \
32
  private(i,tid)             \
33
  schedule(static,chunk)     \
34
  firstprivate(first_time)
35
 
36
  for (i=0; i < N; i++)
37
    {
38
    if (first_time == 'y')
39
      {
40
      tid = omp_get_thread_num();
41
      first_time = 'n';
42
      }
43
    c[i] = a[i] + b[i];
44
    printf("tid= %d i= %d c[i]= %f\n", tid, i, c[i]);
45
    }
46
 
47
  return 0;
48
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.