Reduction on two dimensional arrays

Hi,

I would like to know if the reduction kernel could be adapted to work on arrays whose ioshape is not three-dimensional (e.g. nupts, nvars, neles) but rather bidimensional (e.g. nvars, neles) and still perform a reduction over neles to get a nvars shape as a resulting array.
If so could you point out to the major changes that should be set for indexing the matrix appropriately?

Best

The overall logic should be simple to adapt (basically just removing the inner loop which does the accumulation over the first dimension). I would suggest starting with the OpenMP backend as its reduction code is the simplest.

Regards, Freddie.

Hi @fdw,

thanks for the hint, I changed the inner loop as you suggested to:

if (i < ncolb)
{
    ixdtype_t idx = SOA_IX(i, blockIdx.y, gridDim.y);
    r = data[idx];
    acc += r;
}

but when I test it with a sum of all elements I get this as results

    test = np.ones((5, 49055)).astype(np.float32)
    test= self._be.matrix(test, initval= test, tags={'align'})
    red = self._be.kernel('sum', test)
    self._be.run_kernels([red], wait=True)

with a result which is

[49054. 49054. 49054. 49054. 49055.]

Is there anything else that should be changed?

Best

As per my suggestion, start with the OpenMP backend first for testing.

Regards, Freddie.

(basically just removing the inner loop which does the accumulation over the first dimension)

In the openMP kernel is it

                #pragma omp simd
                for (ixdtype_t _xj = 0; _xj < SOA_SZ; _xj++)
                {
                 ...
                }

?

Best