提问人:DJNZ 提问时间:4/18/2023 最后编辑:DJNZ 更新时间:4/19/2023 访问量:83
如何使用 SAVE 和 ENTRY 语句重写代码以供 OpenMP 使用?
How to rewrite code with SAVE and ENTRY statements for OpenMP usage?
问:
我正在重写一个大型 Fortran-77 程序以供 OpenMP 使用,其中一个文件包含一个子例程,其中标记为 SAVE 的重要变量在第一次调用主程序时初始化,然后在通过 ENTRY 点调用同一子例程时使用它们。 我决定用一个长子例程替换这个文件,其中包含一个包含多个子例程的模块(其功能是通过 ENTRY 点调用的),并在 CONTAINS 语句之前,列出那些在源程序中标记为 SAVE 的重要变量,以便它们在所有模块子例程调用中都可用。
但是,我无法使该功能正常工作。我还如何在子例程中重写 SAVE-ENTRY 结构? 我的最小主程序示例:
c elementary program to add two numbers, using
c a module containing important variables and
c two addition functions, one for the case where
c one number is zero and the second for the case
c of non-zero terms
PROGRAM sum0
USE SUMM
INTEGER i,j
WRITE (6,*) 'Enter two numbers: '
READ (5,*) i,j
IF (i .EQ. 0) THEN
CALL sum1(j)
ELSE IF (j .EQ. 0) THEN
CALL sum1(i)
ELSE
CALL sum2(i,j)
ENDIF
END PROGRAM sum0
和模块:
MODULE SUMM
IMPLICIT NONE
c "important" variables that had the status SAVE:
REAL B(2,2), K
c initialization via DATA works similarly to SAVE (I think so):
DATA B/1.0,-3.7,4.3,0.0/, K/33.0/
CONTAINS
SUBROUTINE sum2(i1,j1)
INTEGER i1,j1
i1 = i1 + j1
WRITE (6,*) 'The first element of B is', B(1,1), '.'
WRITE (6,*) 'The K is', K, '.'
WRITE (6,*) 'The sum of the numbers is', i1, '.'
END SUBROUTINE sum2
SUBROUTINE sum1(i1)
INTEGER i1
WRITE (6,*) 'The first element of B is', B(1,1), '.'
WRITE (6,*) 'The K is', K, '.'
WRITE (6,*) 'The sum of the numbers is', i1, '.'
END SUBROUTINE sum1
END MODULE SUMM
原始文件:
SUBROUTINE SUMM
IMPLICIT REAL*8 (A-H,O-Z)
REAL B(2,2), K
DATA B/1.0,-3.7,4.3,0.0/
SAVE
K = 33.0
RETURN
ENTRY sum2(i,j)
i = i + j
WRITE (6,*) 'The first element of B is', B(1,1), '.'
WRITE (6,*) 'The K is', K, '.'
WRITE (6,*) 'The sum of the numbers is', i, '.'
RETURN
ENTRY sum1(i)
WRITE (6,*) 'The first element of B is', B(1,1), '.'
WRITE (6,*) 'The K is', K, '.'
WRITE (6,*) 'The sum of the numbers is', i, '.'
RETURN
END
欢迎任何帮助!
答: 暂无答案
评论
sum2
sum1
subroutine summ; k = 33.0; end subroutine summ
k
k/33./
data
k
save
implicit none
i
j