1

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
Shiqi He
  • 95
  • 3
  • 10

1 Answers1

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.

  • So what is the meaning of using firstprivate, since the initialization would be kept? – Shiqi He Feb 17 '19 at 18:06
  • @ShiqiHe They are a special kind of `private`, not of `shared`. See https://stackoverflow.com/questions/15304760/how-are-firstprivate-and-lastprivate-different-than-private-clauses-in-openmp For a `shared` variable you don't need to care about the value of the first or the last thread, there is only one value. – Vladimir F Героям слава Feb 17 '19 at 18:09