在并行计算中如果我想要在运行了50步时交换t1和t2的数值,在100步的时候交换t2和t3的数值,150步的时候交换t1和t2的数值,在200步的时候交换t2和t3的数值.依次类推,直到循环完为止。以下是代码
[Fortran] 纯文本查看 复制代码 program main
implicit none
real(kind=8) :: a,b,c,e0,e1,e2,t1,t2,t3,x,r1,r2,de,p
integer :: i
OPEN(31,FILE='Ea.CIR80',STATUS='unknown')
OPEN(32,FILE='Eb.CIR80',STATUS='unknown')
OPEN(33,FILE='Gc.CIR80',STATUS='unknown')
t1 = 300.d0
t2 = 310.d0
t3 = 320.d0
e0 = 10000
call random_seed ()
!$OMP PARALLEL SECTIONS
!$OMP SECTION
do i = 1,10000
call random_number (x)
r1 = dble(x)
r2 = dble(x) * 2
e1 = t1 * e0
e2 = e1 * r2
de = e2 - e1
if(de.le.0) then
p = 1.d0
else
p = dexp(-de)
end if
if(p.le.r1) then
e2 = e1
else
e1 = e2
write(*,*) i
write(31,*) i,e2
end if
end do
close(31)
!$OMP SECTION
do i = 1,10000
call random_number (x)
r1 = dble(x)
r2 = dble(x) * 2
e1 = t2 * e0
e2 = e1 * r2
de = e2 - e1
if(de.le.0) then
p = 1.d0
else
p = dexp(-de)
end if
if(p.le.r1) then
e2 = e1
else
e1 = e2
write(*,*) ' ',i
write(32,*) i,e2
end if
end do
close(32)
!$OMP SECTION
do i = 1,10000
call random_number (x)
r1 = dble(x)
r2 = dble(x) * 2
e1 = t3 * e0
e2 = e1 * r2
de = e2 - e1
if(de.le.0) then
p = 1.d0
else
p = dexp(-de)
end if
if(p.le.r1) then
e2 = e1
else
e1 = e2
write(*,*) ' ',i
write(33,*) i,e2
end if
end do
close(33)
!$OMP END PARALLEL SECTIONS
end program main
|