让我们编译以下 Fortran 程序:
program main
implicit none
integer::j
complex::y(2)
real::x(2)
x(1)=1.0
x(2)=2.0
do j=1,2
y(j)=FF(x(j))
enddo
write(6,*)
write(6,*) y,"by DO"
forall (integer::i=1:2)
y(i)=FF(x(i))
end forall
write(6,*)
write(6,*) y,"by FORALL"
do concurrent (integer::i=1:2)
y(i)=FF(x(i))
enddo
write(6,*)
write(6,*) y,"by DO CONCURRENT"
write(6,*)
contains
complex pure function FF(xx)
real,intent(in)::xx
FF=cmplx(xx)
end function
end program
ifort (ver. 19.0.4.243) 没有选项。然后,我们得到结果:
$ ./a.out
(1.000000,0.0000000E+00) (2.000000,0.0000000E+00) by DO
(1.000000,0.0000000E+00) (2.000000,0.0000000E+00) by FORALL
(2.000000,0.0000000E+00) (2.000000,0.0000000E+00) by DO CONCURRENT
第一个和第二个结果符合预期。为什么 DO CONCURRENT 不给出相同的结果?