Get the maximum value among OpenMP threads in Fortran

大憨熊 提交于 2019-12-11 09:55:31

问题


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

回答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.



来源:https://stackoverflow.com/questions/54735342/get-the-maximum-value-among-openmp-threads-in-fortran

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!