我正在实施Ising模型的模拟。编译工作正常,但是当我运行它时,我总是发现程序在同一点停止并显示错误“分段错误:无效的内存引用”。我已经检查过,我并没有尝试访问数组的非现有位置,这是我遇到此问题时可能发生的主要问题,据我所知。所以我的想法已经用完了。有人能帮助我吗?
program main
parameter (L=80,N=L*L)
implicit double precision(a-h,o-z)
integer s(N),n1(N),n2(N),n3(N),n4(N)
integer:: Q,QQ,QQQ,cont
Real:: T
Real, dimension (1,40):: Temps
dimension h(-4:4)
data M,M0,mc /8192,1000,1/
do QQQ=1,40
Temps(1,QQQ)=4 - ((QQQ-1)*0.1)
end do
do ix=1,L
do iy=1,L
i=(iy-1)*L+ix
ix1=ix+1
if (ix1.eq.L+1) ix1=1
n1(i)=(iy-1)*L+ix1
iy2=iy+1
if (iy2.eq.L+1) iy2=1
n2(i)=(iy2-1)*L+ix
ix3=ix-1
if (ix3.eq.0) ix3=L
n3(i)=(iy-1)*L+ix3
iy4=iy-1
if (iy4.eq.0) iy4=L
n4(i)=(iy4-1)*L+ix
enddo
enddo
do i=1,N !Initial condition
if (ran_u() < 0.5d0) then
s(i)=+1
else
s(i)=-1
endif
enddo
do QQ=1,40
do Q=1,999
T=Temps(1,QQ)! Loop over temperatures
do j=-4,4,2 ! Create the array with the
h(j)=min(1.0,exp(-2*j/T)) ! Boltzmann-Gibbs factors
enddo
do ij=1,M0*N ! Thermalizing steps
i=floor((N*ran_u())+1)
ib=s(i)*(s(n1(i))+s(n2(i))+s(n3(i))+s(n4(i)))
if (ran_u() < h(ib)) then
s(i)=-s(i)
end if
enddo
c=0.0 ! Initialize averages
rm=0.0
rm2=0.0
rm1=real(abs(sum(s)))/N
do im=1,M ! Updating steps
cont=0
do ij=1,mc*N
i=floor((N*ran_u())+1)
cont=cont+1;
ib=s(i)*(s(n1(i))+s(n2(i))+s(n3(i))+s(n4(i)))
if (ran_u() < h(ib)) then
s(i)=-s(i)
end if
enddo
rm0=real(abs(sum(s)))/N ! Begin measures
open(88,file='counting.txt')
!write(88,*) im
rm=rm+rm0
rm2=rm2+rm0*rm0
c=c+rm0*rm1
rm1=rm0
enddo
!Final averages
rm=rm/M
rm2=rm2/M-rm*rm
c=(c/M-rm*rm)/rm2
if (c.ne.1.0) tau=c/(1.0d0-c)
error=sqrt(rm2*(2*tau+1)/M)
open(99,file='file.txt')
write(99,*) T,rm,rm2,error,mc*tau,c
enddo
enddo
end
其中ran_u函数是
function ran_u()
integer, save :: m=1234567
parameter (rm=2.0**(-32),ia=1812433253,ic=1)
m=m*ia+ic
ran_u=rm*m
if (ran_u < 0.0) ran_u=1.0+ran_u
end function ran_u