看看你是否可以从编译器中得到一些优化报告......
英特尔的示例:
program A
real a,b
integer i
a=1.234
!DIR$ SIMD
do i=1,100000000
b=exp(a)
end do
stop
end program A
使用 OpenMP 的示例:
program A2
USE OMP_LIB
real a,b
integer i
a=1.234
!DIR$ SIMD
do i=1,100000000
b=exp(a)
end do
stop
end program A2
当然,在这个微不足道的情况下......
program B2
real a,c
real, DIMENSION(100000000) ::b
a=1.234
c=exp(a)
b=c
! which is mathematically the same as
!b(1:100000000) = c
! or
!b(:) = c
stop
end program B2
我通常将这些类型的函数放入库中,然后使用 !DIR@ 或 !$OMP 对其进行编译并对其进行调整,而与主程序的优化级别无关。
MODULE MyFuncs
PRIVATE
PUBLIC, B2
CONTAINS
PURE SUBROUTINE B2(a,n,b)
IMPLICIT NONE
real , INTENT(IN ) :: a
INTEGER , INTENT(IN ) :: n
real, DIMENSION(n), INTENT( OUT) :: b
c=exp(a)
!DIR$ SIMD
b=c
RETURN
END SUBROUTINE myB2
END MODULE MyFuncs
program A
IMPLICIT NONE
USE myFuncs
INTEGER :: n=100000000
real :: a
real, DIMENSION(n) :: b
a=1.234
CALL MyB2(a, n, b)
end program A