shushi_piggy
shushi_piggy

Reputation: 115

Get the maximum value among OpenMP threads in Fortran

I have a do loop which updates T value and calculates the maximum difference during the iteration, called dumax.

I need to initialize dumax, so I set it to be

firstprivate

Then I will not be able to use:

reduction(max: dumax)

Reduction operator seems to accept private variable. Then how can I get the maximum value of dumax before I end the parallel?

My program is shown below:

DUMAX=0.0D0
!$OMP PARALLEL DEFAULT(PRIVATE), SHARED(T_R, T_B), FIRSTPRIVATE(DUMAX)
            !$OMP DO 
            DO I=2, N-1, 2
                DO J=2, N-1, 2
                    T_OLD=T_B(I,J)
                    T_B(I,J)=0.25*(T_R(I,J-1)+T_R(I,J+1)+T_R(I+1,J)+&
                                    T_R(I-1,J)-DX**2*S(I,J))
                    DUMAX=MAX(DUMAX, ABS(T_OLD-T_B(I,J)))
                END DO
            END DO
            !$OMP END DO 
!$OMP END PARALLEL

Upvotes: 1

Views: 746

Answers (1)

You should not set dumax to firstprivate. Reduction variables should be shared. Make it shared and then use reduction(max: dumax). Your initialization will be kept.

Upvotes: 1

Related Questions