[Omp] question about reduction

Greg Bronevetsky greg at bronevetsky.com
Thu Feb 15 09:40:27 PST 2007


Looking at the 2.5 spec, I don't see a direct statement to this effect.
Also, thinking from the implementation side, it doesn't seem like a
necessary constraint since each thread gets a private copy of the variable
and it is only at the end of each thread's execution that the different
thread's copies need to be combined using the official reduction
operator. However, using operator x on a variable when it is supposed to
be reduced using operator y does violate the intuition behind reduction
and that may be the reason why the one compiler disallows it.

                             Greg Bronevetsky

On Thu, 15 Feb 2007, James Beyer wrote:

> Does the reduction clause force the user to only use that operator on 
> the object list in the clause?  The following code example the following 
> code compiles with several compilers, however, at least one issues an 
> error message saying that the reduction clause and the expression inside 
> the single construct do not match.
> 
> james
> 
> 
>          program foo
>            integer x,num
>            external omp_get_num_threads
>            integer omp_get_num_threads
> 
>            x = 0
> !$omp parallel reduction(-:x)
>              x = x - 3
> !$omp master
>                num = omp_get_num_threads()
> !$omp end master
> 
> !$omp single
>                x = x + 5
> !$omp end single
> !$omp end parallel
> 
>            if ( x .ne. 5+(-3*num) ) then
>              print *,'Test failed'
>            else
>              print *,'Test passed'
>            endif
> 
>          end
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp
> 




More information about the Omp mailing list