Hi,

I am looking for a solution to a reduction problem that is a little bit more complex than the standard max reduction problem found in various OpenACC examples/docs. I am assuming that reduction variables must be of basic type (int,double etc.) and not struct/class type, otherwise the solution would be trivial.

I need to find the maximum and its location which is an integer tuple:

```
double maxfield = 0.;
int i_max = -1;
int j_max = -1;
int k_max = -1;
for(int i = 0; i < xmax; ++i) {
for(int j = 0; j < ymax; ++j) {
for(int k = zmin; k < zmax; ++k) {
double v = sqrt(F1.Ex[ExID(i, j, k)]*
F1.Ex[ExID(i, j, k)] +
F2_.Ex[ExID(i, j, k)]*
F2_.Ex[ExID(i, j, k)]);
if(v > maxfield){
maxfield = v;
i_max = i;
j_max = j;
k_max = k;
}
}
}
}
```

ExID is just a macro for mapping the tuple (i,j,k) into the one-dimensional array.

If there were no need for the location of the maximum I could simply write the following statement withing a kernels construct:

```
#pragma acc loop independent collapse(3) reduction(max:maxfield)
for(.....)
```

I was thinking about thrust::max_element, but then I am not dealing with a single array, but the maximum of the sum of two arrays, which must not be changed. Creating a temporary array for holding the sum will cost me valuable device memory. It also would not directly solve finding the tuple as it returns a linear index, but this wouldn’t be a showstopper as it is a unique mapping and its inverse can be computed.

Do you have any best practices for handling such a reduction problem in an OpenACC context?

Thanks,

LS