Last active
December 19, 2015 04:28
-
-
Save pv/5897301 to your computer and use it in GitHub Desktop.
Lapack 3.4.2 ZGESDD RWORK array size seems wrong in their documentation. 5*MIN(M,N) is not enough, 7*MIN(m,n) seems required
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ! | |
| ! In ZGESDD in LAPACK 3.4.2, the documented size of the RWORK parameter for | |
| ! JOBZ='N' is apparently incorrect. | |
| ! | |
| ! This program demonstrates that LAPACK writes out-of-bounds in the RWORK array, | |
| ! which results to memory corruption and crashes in some cases. | |
| ! https://github.com/scipy/scipy/issues/2609 | |
| ! | |
| program main | |
| integer, parameter :: m = 1500, n = 2800, pad = 10000 | |
| integer, parameter :: lwork = 140600 | |
| double precision, parameter :: guard = 123456 | |
| ! Work array sizes as per LAPACK 3.4.2 documentation | |
| integer, parameter :: lrwork = 5*min(m,n) | |
| integer, parameter :: liwork = 8*min(m,n) | |
| integer, parameter :: ls = min(m,n) | |
| ! Work arrays | |
| integer, dimension(liwork) :: iwork | |
| double precision, dimension(lrwork + pad) :: rwork | |
| complex*16, dimension(lwork) :: work | |
| complex*16, dimension(m,n) :: A | |
| double precision, dimension(ls) :: S | |
| complex*16 zdummy | |
| integer :: i, j | |
| ! Fill in some matrix | |
| do j = 1, n | |
| do i = 1, m | |
| A(i,j) = i+j | |
| end do | |
| end do | |
| ! Insert guard value to rwork | |
| rwork(:) = guard | |
| ! Run | |
| call ZGESDD('N', m, n, A, m, S, zdummy, 1, zdummy, 1, work, lwork, rwork, iwork, info) | |
| ! Check guard | |
| do i = lrwork+1, lrwork+pad | |
| if (rwork(i).ne.guard) then | |
| write(*,*) 'ERROR: rwork memory corrupted at index', i | |
| end if | |
| end do | |
| end program main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment