mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-07 23:22:11 +01:00
27 lines
529 B
C
27 lines
529 B
C
/*
|
|
* @@name: reduction.1c
|
|
* @@type: C
|
|
* @@compilable: yes
|
|
* @@linkable: no
|
|
* @@expect: success
|
|
*/
|
|
#include <math.h>
|
|
void reduction1(float *x, int *y, int n)
|
|
{
|
|
int i, b, c;
|
|
float a, d;
|
|
a = 0.0;
|
|
b = 0;
|
|
c = y[0];
|
|
d = x[0];
|
|
#pragma omp parallel for private(i) shared(x, y, n) \
|
|
reduction(+:a) reduction(^:b) \
|
|
reduction(min:c) reduction(max:d)
|
|
for (i=0; i<n; i++) {
|
|
a += x[i];
|
|
b ^= y[i];
|
|
if (c > y[i]) c = y[i];
|
|
d = fmaxf(d,x[i]);
|
|
}
|
|
}
|