summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c/appendix-a/a.4.1.c
blob: c6be4909002f8207869291914aee1c3317f4f792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* { dg-do run } */

#include <omp.h>
extern void abort (void);
void
subdomain (float *x, int istart, int ipoints)
{
  int i;
  for (i = 0; i < ipoints; i++)
    x[istart + i] = 123.456;
}

void
sub (float *x, int npoints)
{
  int iam, nt, ipoints, istart;
#pragma omp parallel default(shared) private(iam,nt,ipoints,istart)
  {
    iam = omp_get_thread_num ();
    nt = omp_get_num_threads ();
    ipoints = npoints / nt;	/* size of partition */
    istart = iam * ipoints;	/* starting array index */
    if (iam == nt - 1)		/* last thread may do more */
      ipoints = npoints - istart;
    subdomain (x, istart, ipoints);
  }
}
int
main ()
{
  int i;
  float array[10000];
  sub (array, 10000);
  for (i = 0; i < 10000; i++)
    if (array[i] < 123.45 || array[i] > 123.46)
      abort ();
  return 0;
}