This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: autopar reduction and OMP_ATOMIC gimplify/expand changes - final patch


Hi,

looking at the example, there seem to be two problems with the
transformation:

> after reduction transformation (only relevant parts):
> 
> parloop
> {
> 
> ....
> 
>   # Two new variables are created for each reduction:
>   "reduction" is the variable holding the neutral element for the
>   particular operation, e.g. 0 for PLUS_EXPR, 1 for MULT_EXPR, etc.
>   "reduction_initial" is the initial value given by the user.
>   It is kept and will be used after the parallel computing is done.  #
> 
>   reduction_initial.24_46 = 1;
>   reduction.23_45 = 0;
>   .paral_data_store.32.reduction.23 = reduction.23_45;
>  
>   #pragma omp parallel num_threads(4) 
>   reduction.28_48 = .paral_data_load.33_51->reduction.23;

You cannot do this -- another thread could have already altered the
value of reduction.23.  You need a separate variable holding the initial
value of reduction.28_48 (or preferably, as this initial value is always
a constant, just put the constant here directly).

>   #pragma omp for schedule(static)
>   # sum.27_29 = PHI <sum.27_11, reduction.28_48>
>   sum.27_11 = D.1827_8 + sum.27_29;
>   OMP_CONTINUE
> 
>   # Adding this reduction phi is done at create_phi_for_local_result() #
>   # reduction.23_58 = PHI <sum.27_11(5), 0(23)>
>   OMP_RETURN
>  
>   # Creating the atomic operation is done at 
>   create_call_for_reduction_1()  #
> 
>   #pragma omp atomic_load
>   D.1839_59 = *&.paral_data_load.33_51->reduction.23;
>   D.1840_60 = reduction.23_58 + D.1839_59;
>   #pragma omp atomic_store (D.1840_60);
>  
>   OMP_RETURN
>  
>  # collecting the result after the join of the threads is done at
>   create_loads_for_reductions().
>   a new variable "reduction_final" is created.  It calculates the final
>   value from the initial value and the value computed by the threads #
>  
>   reduction_final.34_53 = .paral_data_load.33_52->reduction.23;
>   sum_37 = reduction_initial.24_46 + reduction_final.34_53;
>   sum_43 = D.1795_41 + sum_37;

There seems to be another error -- paral_data_load is no longer accessible
at this point; you need to load the value from paral_data_store.

Zdenek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]