lapack zheev 出现数组越界错误如何更改
在跑今天下面的这个代码的时候,算本征值和本征向量,但是报错,问了一下应该是数组越界错误,应该如何改呢rogram workfile
Implicit none
integer , parameter :: q = 1000
real , parameter :: t1 = 3.12 , t2 = 0.29 , t3 = -0.0103
complex , parameter :: i = (0, 1) , t0 = (0,0)
real , parameter :: PI = acos(-1.0) , a0 = 1.42e-10
real :: b1(2), b2(2) , a1(2) , a2(2) , m1 , m2
! complex H(6, 6)
real , allocatable :: k(:,:,:)
complex :: f1 , f2
integer :: x , y
! Output of the Hamiltonian matrix
! integer::i1
! Eigenvalue and Eigenvector of the Hamiltonian matrix
CHARACTER JOBZ , UPLO
integer :: INFO=0
integer , parameter :: N=6, LDA=N ! , LWORK=3*N
real*8 RWORK(3*N-2), W(N)
complex*16 H(LDA,N), WORK(3*N)
allocate(k(2,q-1,q-1))
b1 = [ 2*PI/a0*sqrt(3.0) , 2*PI/a0 ]
b2 = [ 2*PI/a0*sqrt(3.0) , -2*PI/a0 ]
a1 = [ a0*sqrt(3.0)/2 , a0/2 ]
a2 = [ a0*sqrt(3.0)/2 , -a0/2 ]
Forall(x=1:size(k,2), y=1:size(k,3))
k(:,x,y) = (b1*x+b2*y)/q
End Forall
m1 = dot_product(a1 , k(:,1,2))
m2 = dot_product(a2 , k(:,1,2))
f1 = 1+exp(i*m1)+exp(i*m2)
f2 = 1+exp(-i*m1)+exp(-i*m2)
H = reshape([complex::&
t0, t1*f1, t0, t0, t0, t0,&
t1*f2, t0, t0, t2, t0, t3,&
t0, t0, t0, t1*f2, t0 ,t0,&
t0, t2, t1*f1,t0, t0, t2, &
t0, t0, t0, t0, t0, t1*f1,&
t0, t3, t0, t0, t1*f2, t0],)
! Output of the Hamiltonian matrix
! do i1=1,6
! write(*,*)H(i1,:)
! end do
!print *, H(:,:)
! Eigenvalue and eigenvector of the Hamiltonian matrix
call myzheev(N,W,H)
call ZHEEV('V', 'U', N, H(6,6), N, W, WORK, 3*N, RWORK, INFO)
print *,W
contains
subroutine myzheev(N,W,H)
implicit none
integer::N, INFO=0
real*8::W(N),RWORK(3*N-2)
complex*16::H(N,N),WORK(3*N)
call ZHEEV('V', 'U', N, H, N, W, WORK, 3*N, RWORK, INFO)
endsubroutine
End Program workfile
出现了以下报错:
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#00x7f8e4ef818a0 in ???
#10x7f8e4ef80a45 in ???
#20x7f8e4ec9451f in ???
at ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
#30x5626f8c2f1e3 in ???
段错误 (核心已转储)
最后还是把结果返还给了我,如果是数组越界的话应该如何修改呢,由于这里用了lapack的包,所以在print的时候也不太好print
你调用了两次zheev,50行那个没有必要,传入了H(6,6)会直接访问到未知的内存区域,造成段错误 Transpose 发表于 2022-3-8 10:18
你调用了两次zheev,50行那个没有必要,传入了H(6,6)会直接访问到未知的内存区域,造成段错误 ...
好的,十分感谢! Transpose 发表于 2022-3-8 10:18
你调用了两次zheev,50行那个没有必要,传入了H(6,6)会直接访问到未知的内存区域,造成段错误 ...
另外我还有个问题,就是我在输出本征向量的时候,输出的是复数,但是加上一个real后,如real(H(:,:)),输出的便是实型,这两种数据类型是如何转换的呢?谢谢! real如果参数是复数的话,返回的是复数的实部。最好注明对应的kind值 例如 real(H(:,:),kind=4) Transpose 发表于 2022-3-8 16:55
real如果参数是复数的话,返回的是复数的实部。最好注明对应的kind值 例如 real(H(:,:),kind=4) ...
好的谢谢!
页:
[1]