Hi!
This is what I did to find the max integer in an array.
int value = INT_MIN;
#pragma acc parallel loop independent\
deviceptr(arr) copy(value) reduction(max:value)
for (int i = 0; i < n; ++i) {
int a = arr[i];
// value = max(a, value);
value = std::max(a, value);
}
return value;
Obviously, I can’t use max
because it’s not defined in C++ and I suppose I should not use fmax
instead. This observation confused me – how are these two max
(one in the pragma line, one in the loop) related? It never occurred to me when I coded in Fortran.
If the compiler doesn’t care about what function we use to set value
inside the loop, would the following code be correct?
int value;
#pragma acc parallel loop independent\
deviceptr(arr) copyout(value) reduction(max:value)
for (int i = 0; i < n; ++i) {
value = arr[i];
}
return value;
Thanks.
stw