Is std::complex<T> allowed in the reduction clause?

General OpenMP discussion

Is std::complex<T> allowed in the reduction clause?

Postby ciccio » Tue Jan 29, 2008 6:58 am

Hi I was wondering if a variable of type std::complex<T> is allowed in
the reduction clause?

The following piece of code compiles flawless in g++ but failles in icpc.

Code: Select all
#include <complex>
int main() {
  std::complex<double> tmp = 0.0;
#pragma omp parallel for default(shared) reduction(+:tmp)
  for (register int i = 0; i < 10; ++i)
    tmp += double(i);
  return 0;
}


As far as I understand the spec2.5 of OpenMP, this should not be able to
compile there std::complex<T> is an aggregated type of two variables of
type T.

Am I right here?
ciccio
 
Posts: 8
Joined: Tue Jan 29, 2008 6:57 am

Re: Is std::complex<T> allowed in the reduction clause?

Postby lfm » Tue Jan 29, 2008 3:38 pm

You're correct, it isn't standard OpenMP.
"Aggregate types (including arrays), pointer types and reference types may not appear in a reduction clause"
(from the 3.0 draft, but 2.5 is the same). It is interesting that g++ allows it. It should work if your compiler supports _Complex (not sure about icc status here) and perhaps g++ maps onto that somehow.

-- Larry
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB

Re: Is std::complex<T> allowed in the reduction clause?

Postby ejd » Tue Jan 29, 2008 9:53 pm

lfm wrote:You're correct, it isn't standard OpenMP.
"Aggregate types (including arrays), pointer types and reference types may not appear in a reduction clause"
(from the 3.0 draft, but 2.5 is the same). It is interesting that g++ allows it. It should work if your compiler supports _Complex (not sure about icc status here) and perhaps g++ maps onto that somehow.

-- Larry


I tried g++ 4.2.1 with this example and get:

error: 'tmp' has invalid type for 'reduction'

which is what I would have expected.

We have talked about trying to add a "generic" reduction (one where the user could define what is to be done) to the OpenMP spec, but it has not happened yet. I assume that since you (ciccio) asked the question, you have an example where this would be of value?
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: Is std::complex<T> allowed in the reduction clause?

Postby ciccio » Wed Jan 30, 2008 2:32 am

Okay, first of all thanks for the replies.

I have checked again with g++ and noticed that I made a stupid error, I used the -openmp flag instead of --openmp, so it was rather obvious that the thing compiled.

Nonetheless I notice that g++-4.2.2 can't handle the register keyword
Code: Select all
[... openmp]$ g++ --openmp complex_reduction.cpp
complex_reduction.cpp: In function ‘int main()’:
complex_reduction.cpp:12: error: ‘tmp’ has invalid type for ‘reduction’
complex_reduction.cpp:13: error: expected primary-expression before ‘register’
complex_reduction.cpp:13: error: expected `;' before ‘register’
complex_reduction.cpp:13: error: expected primary-expression before ‘register’
complex_reduction.cpp:13: error: expected `;' before ‘register’
complex_reduction.cpp:13: error: expected primary-expression before ‘register’
complex_reduction.cpp:13: error: expected `)' before ‘register’
complex_reduction.cpp:13: error: expected iteration declaration or initialization
complex_reduction.cpp:13: error: ‘i’ was not declared in this scope
complex_reduction.cpp:13: error: expected `;' before ‘)’ token
[... openmp]$                   

Maybe I should file a bug for this.

Thanks for the replies in any case and I apologize for the error I made here.
ciccio
 
Posts: 8
Joined: Tue Jan 29, 2008 6:57 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 10 guests

cron