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)”.
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.