# [Help] Using reduction with Array

Hi all,

Currently, i’m trying using reduction clause with array and i don’t know how to apply it for my case.

I have a array {1, 2, 3, 4, 5, 3, 1, 3, 2, 5, 6, 2, 6, 2, 9, 4, 2, 3, 5, 6}.
i want count number of values(0-9) in above array and put them into a array. But i don’t know use reduction clause in here (#pragma acc parallel loop reduction(+:res)??? ).

This is my source code:

``````#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;

int main()
{
int n = 20;
int arr[20] = {1,2,3,4,5,3,1,3,2,5,6,2,6,2,9,4,2,3,5,6};
int res[10] = {0,0,0,0,0,0,0,0,0,0};

#pragma acc enter data copyin(arr[0:20])
#pragma acc parallel loop reduction(+:res[])
for(int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++)
{
res[arr[i]] += 1;
}
#pragma acc update self(arr[0:20])
#pragma acc exit data delete(arr)

return 0;
}
``````

Thank you so much!

Hi all,

I think i found sample code for my issues:

``````float _Complex c;
real s[4];
..
#pragma acc parallel loop reduction(+:c,s) default(present)
for (int i = 0; i < n; ++i) {
c += CMPLXF( a[i], b[i] );
s[0] += a[i];
s[1] += b[i];
s[2] += c[i];
if (d[i] > 0) s[3] += d[i];
}
``````

But it has error: PGCC-S-1002-Reduction type not supported for this variable datatype - res

Currently, i’m using PGI compiler 18.10 that include openacc 2.6. Is this version support reduction with array?
When do the community version of PGI compiler 19.1 release?

Thank you so much!

Hi DanhNam

Currently, i’m using PGI compiler 18.10 that include openacc 2.6. Is this version support reduction with array?

No, the OpenACC 2.6 nor the most recent 2.7 standard does not support array reductions.

However, it is one of the more requested features so the OpenACC committee is considering it for a future standard.

Note that the concern from our engineers evaluating this feature is that array reductions might cause a performance issue. But if it is adopted by the OpenACC standard, PGI will add this support.

When do the community version of PGI compiler 19.1 release?

The next PGI Community Edition will be 19.4 which isn’t too far away.

-Mat

Sorry for Frankensteining this thread, but I do believe the 2.7 standard does include array reductions. From the 2.7 specifications pg. 28,

“If the reduction var is an array or subarray, the array reduction operation is logically equivalent to applying that reduction operation to each element of the array or subarray individually.”

From what I can tell, this is as of yet unsupported in PGI 19.7. Is this on the horizon of being added or has it been added in a more recent version? Thanks!

Correct, I was in error in stating that 2.7 did include array reductions. Apologies.

With all the other projects we’ve been working on and the rebranding effort, we unfortunately haven’t had time to add new OpenACC features. We should be getting back to these in the near future, but I don’t have firm timeline as to when.

-Mat