"double free or corruption (out)" when requesting eigenvectors in complex generalized eigenvalue problem
edvinolo opened this issue · 1 comments
Description
Calling the eig subroutine for a generalized eigenvalue problem with complex A and B matrices leads to a memory fault when right or left eigenvectors are requested. The error seems to only occur for this specific combination, if I change A and B to real, or remove the optional left and right eigenvector arguments there are no problems.
Here is a reproducer:
program test
use stdlib_linalg, only: eig
implicit none
double complex, dimension(3,3) :: A_Z,S_Z
double precision, dimension(3,3) :: A_D,S_D
double complex, dimension(3,3) :: vecs_r
double complex,dimension(3) :: eigs
integer :: i
! Set matrix
A_Z = reshape( [ [1, 6, 3], &
[9, 2, 1], &
[8, 3, 4] ], [3,3] )
S_Z = 0
do i= 1,3
S_Z(i,i) = i
end do
A_D = real(A_Z)
S_D = real(S_Z)
call eig(A_D,S_D,eigs,right=vecs_r) !Works
call eig(A_Z,S_Z,eigs,right=vecs_r) !Fails
write(6,*) eigs
end program test
and here is the error message and backtrace:
double free or corruption (out)
Program received signal SIGABRT: Process abort signal.
Backtrace for this error:
#0 0x7f0809780d11 in ???
#1 0x7f080977fee5 in ???
#2 0x7f08093d108f in ???
at /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
#3 0x7f08093d100b in __GI_raise
at ../sysdeps/unix/sysv/linux/raise.c:51
#4 0x7f08093b0858 in __GI_abort
at /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:79
#5 0x7f080941b26d in __libc_message
at ../sysdeps/posix/libc_fatal.c:155
#6 0x7f08094232fb in malloc_printerr
at /build/glibc-LcI20x/glibc-2.31/malloc/malloc.c:5347
#7 0x7f0809424f9f in _int_free
at /build/glibc-LcI20x/glibc-2.31/malloc/malloc.c:4314
#8 0x556798caef27 in ???
#9 0x556798c98f6c in test
at /home/edvinolofsson/stdlib_gen_eig_bug/test.f90:25
#10 0x556798c99092 in main
at /home/edvinolofsson/stdlib_gen_eig_bug/test.f90:2
Aborted (core dumped)
Expected Behaviour
The call to eig should return the eigenvalues and eigenvectors also for complex A and B.
Version of stdlib
Platform and Architecture
Ubuntu 20.04, x86 , gfortran 10.5.0 (but can reproduce it also on compiler explorer with latest gfortran)
Additional Information
compiler explorer link: https://godbolt.org/z/bYW6v6jso
I copied the actual routines running your example at https://godbolt.org/z/T8TT1nsx4
It looks like there is insufficient work size for rwork
.
Rwork is initialized at 2*n
which is OK for the standard problem (GEEV) but not for the generalized problem (GGEV), that wants 8*n
I have overlooked that when implementing generalized eigs, will deploy a fix soon