[OpenMP][nvc++] "Duplicate name in reduction clause" error with recent SDK

Hello,

How I should understand this error message:
nvc++ -mp -target=gpu condition_reduction.cpp -o test && ./test
NVC+±S-0155-Duplicate name in reduction clause - sum (condition_reduction.cpp: 9)
NVC++/x86-64 Linux 23.5-0: compilation completed with severe errors

The code is:

#include <iostream>
int main()
{
  bool kernelOnDevice = false;
  int sum=0;
  //std::cerr << kernelOnDevice << std::endl;
  #pragma omp target teams distribute parallel for if (kernelOnDevice) reduction(+:sum)
  for (int num_face=0; num_face<10000; num_face++)
      sum += 1;
  std::cerr << sum << std::endl;    
  return 0;
}

It worked fine with SDK 22.1. It works if I remove the conditional “if (kernelOnDevice)”.

Thanks,

Hi pledac,

Thanks for the report. This does look like a regression in 22.5, hence I added a problem report, TPR #33727, and sent it to engineering for review.

Note that changing the order, i.e. moving the “if” clause after the reduction, works around the issue as well.

% cat test.cpp
#include <iostream>
int main()
{
  bool kernelOnDevice = true;
  int sum=0;
#ifdef USE_IF_ORDER1
  #pragma omp target teams distribute parallel for reduction(+:sum) if(kernelOnDevice)
#elif defined(USE_IF_ORDER2)
  #pragma omp target teams distribute parallel for if(kernelOnDevice) reduction(+:sum)
#else
  #pragma omp target teams distribute parallel for reduction(+:sum)
#endif
  for (int num_face=0; num_face<10000; num_face++)
      sum += 1;
  std::cerr << sum << std::endl;
  return 0;
}
% nvc++ -mp=gpu test.cpp -w -V23.5 -DUSE_IF_ORDER1
% nvc++ -mp=gpu test.cpp -w -V23.5 -DUSE_IF_ORDER2
NVC++-S-0155-Duplicate name in reduction clause - sum (test.cpp: 13)
NVC++/x86-64 Linux 23.5-0: compilation completed with severe errors

-Mat

1 Like

Hi Mat,

Again, thanks for the quick reply and for the tip to permute “if” and “reduction” !

Unhappily, my C++ IDE (clion), rewrite the code like that and compiler complains:

#pragma omp target teams distribute parallel for reduction(+:sum) 
    if(kernelOnDevice)

So the only option for now to me is to duplicate the code as:

if (kernelOnDevice) 
{
   #pragma omp target teams distribute parallel for reduction(+:sum)
   for (int num_face=0; num_face<10000; num_face++)
       sum += 1;
}
else
{
     for (int num_face=0; num_face<10000; num_face++)
       sum += 1;
}

Thanks again, and hope this regression will be fixed.

Is the “if” clause on a new line or is it just how it’s shown in the post?

If it is on a new line, then it’s no longer part of the pragma so yes, this could cause an error. You’d need to add an escape character at the end of the pragma in order for it to continue to a new line.

Indeed Mat, you are right, I can add \ at the end of the line. Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.