[Fortran] 纯文本查看 复制代码 program test2
implicit none
integer :: me
me = this_image() ! 需要先声明me再赋值,如果直接在声明初始化,会保存到常量区,变成大家共有的变量
if(me > 1) sync images(me-1)!编号高的image需要等待前一个image彻底运行完到程序结束?
write(*,*) "Image from ", this_image(), "out of", num_images()
if(me < num_images()) sync images(me+1)!image1 这里不需要等待image2?
write(*,*) "Image from ", this_image(), "out of", num_images()
end program test2
最诡异的是当image1运行到第二个if时,不需要与其他image同步,于是最终输出结果为
Image from 1 out of 4
Image from 1 out of 4
Image from 2 out of 4
Image from 2 out of 4
Image from 3 out of 4
Image from 3 out of 4
Image from 4 out of 4
Image from 4 out of 4
而我预想的结果是
Image from 1 out of 4
Image from 2 out of 4
Image from 3 out of 4
Image from 4 out of 4
Image from 4 out of 4
Image from 3 out of 4
Image from 2 out of 4
Image from 1 out of 4
|