在Fortran中获取OpenMP线程中的最大值 [英] Get the maximum value among OpenMP threads in Fortran

查看:468
本文介绍了在Fortran中获取OpenMP线程中的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个do循环,该循环更新T值并计算迭代期间的最大差异,称为dumax.

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

我需要初始化dumax,因此将其设置为

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

firstprivate

然后我将无法使用:

reduction(max: dumax)

归约运算符似乎接受私有变量. 那么在结束并行操作之前如何获得dumax的最大值?

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

我的程序如下所示:

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

推荐答案

您不应将dumax设置为firstprivate.归约变量应为shared.使其共享,然后使用reduction(max: dumax).您的初始化将保留.

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.

这篇关于在Fortran中获取OpenMP线程中的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆