About reduction clause

Discussion of the OpenMP 3.1 draft specifications closed May 1, 2011. (Read only)

About reduction clause

Postby ftinetti » Wed Feb 23, 2011 1:14 pm

From a post in the "Using OpenMP" forum, specifically


I've seen that there is nothing in the spec. preventing

Code: Select all

i.e. using an operator in the clause and another in the actual code.

Do you think it would be good to add something like a Restriction in the reduction clause to avoid this mixture so that compilers can check an generate an error or it is better to leave this as a bug?

Thanks in advance.
Posts: 556
Joined: Wed Feb 10, 2010 2:44 pm

Re: About reduction clause

Postby lfm » Tue Mar 08, 2011 9:26 am

There are at least three reasons that this shouldn't be a restriction:
- It can't in general be checked at compile time
- The obvious implementations are unable to enforce such a restriction
- We want to leave the door open for future extensions for user-defined reductions

The opinion of the ARB is that we made a mistake a long time ago in describing reductions as we did. A proper description of reductions requires only a private copy, an identity, and a combination operation. The compiler and runtime have no control over anything that happens to the private copy. The specification then specifies only how the private copies are initialized, how they are combined, and that the result is assigned to the original shared variable.


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

Re: About reduction clause

Postby ftinetti » Tue Mar 08, 2011 1:07 pm

I see, thanks.

It can't in general be checked at compile time

I thought that having explicitly declared the variable and the operator it would be "easy" for a compiler to check for that restriction (I have the AST in mind...), but I'm not a compiler writer, I was just guessing.

Thank you very much again,

Posts: 556
Joined: Wed Feb 10, 2010 2:44 pm

Re: About reduction clause

Postby ejd » Fri Mar 11, 2011 8:13 am

It is not necessarily easy for the compiler to check. What happens if the reduction code is in a subroutine compiled separately. Then to do the check, you have to require that the compiler does interprocedural analysis, which not all compilers do. Or what about the case with min or max where you are checking the values with an if statement (if x < y) then max = y). Then the compiler has to be smart enough to know what a min and max looks like. As lfm stated, there are many cases where it is just not possible to check without limiting the functionality greatly.
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Return to Draft 3.1 Public Comment

Who is online

Users browsing this forum: No registered users and 0 guests