| 1 |
/* { dg-do run } */ |
| 2 |
|
| 3 |
#include <omp.h> |
| 4 |
extern void abort (void); |
| 5 |
void |
| 6 |
subdomain (float *x, int istart, int ipoints) |
| 7 |
{ |
| 8 |
int i; |
| 9 |
for (i = 0; i < ipoints; i++) |
| 10 |
x[istart + i] = 123.456; |
| 11 |
} |
| 12 |
|
| 13 |
void |
| 14 |
sub (float *x, int npoints) |
| 15 |
{ |
| 16 |
int iam, nt, ipoints, istart; |
| 17 |
#pragma omp parallel default(shared) private(iam,nt,ipoints,istart) |
| 18 |
{ |
| 19 |
iam = omp_get_thread_num (); |
| 20 |
nt = omp_get_num_threads (); |
| 21 |
ipoints = npoints / nt; /* size of partition */ |
| 22 |
istart = iam * ipoints; /* starting array index */ |
| 23 |
if (iam == nt - 1) /* last thread may do more */ |
| 24 |
ipoints = npoints - istart; |
| 25 |
subdomain (x, istart, ipoints); |
| 26 |
} |
| 27 |
} |
| 28 |
int |
| 29 |
main () |
| 30 |
{ |
| 31 |
int i; |
| 32 |
float array[10000]; |
| 33 |
sub (array, 10000); |
| 34 |
for (i = 0; i < 10000; i++) |
| 35 |
if (array[i] < 123.45 || array[i] > 123.46) |
| 36 |
abort (); |
| 37 |
return 0; |
| 38 |
} |