Skip to content

Instantly share code, notes, and snippets.

@bgeneto
Last active November 1, 2022 11:34
Show Gist options
  • Save bgeneto/818d86d69aabc73b85694da8eff3a92c to your computer and use it in GitHub Desktop.
Save bgeneto/818d86d69aabc73b85694da8eff3a92c to your computer and use it in GitHub Desktop.
hermitianEigen fortran zheevd bench
! --------------------------------------------------------
! compile command line:
! ifort -O2 -i8 -mcmodel=medium -qmkl=parallel ./hermitianEigen-small.f90 -o ./hermitianEigen-small ${MKLROOT}/lib/intel64/libmkl_lapack95_ilp64.a -L${MKLROOT}/lib/intel64 -lpthread -lm -ldl
! --------------------------------------------------------
program hermitianEigen
use, intrinsic :: iso_fortran_env
use lapack95, only: heevd
! default integer precision
integer, parameter :: ip = INT64
! default real precision
integer, parameter :: fp = REAL64
! square matrix dimension
integer, parameter :: n = 4096
! real matrices
real(fp), dimension(:), allocatable :: w
real(fp), dimension(:,:), allocatable :: a
! complex matrix
complex(fp), dimension(:,:), allocatable :: c, tmp
integer(ip) :: start, end, rate
intrinsic :: random_seed, random_number
! record start time
call system_clock (count_rate=rate)
call system_clock (count=start)
! allocate memory
allocate(w(n), a(n,n), c(n,n), tmp(n,n))
! generate our random (real and imaginary) matrix elements
print*, '01. Generating random numbers for hermitian matrix...'
print*, '02. Building our positive definite hermitian matrix...'
call random_number(a)
tmp%re = a
call random_number(a)
tmp%im = a
! free some memory
deallocate(a)
! ensure its hermitian
!c = c * conjg(transpose(c)) ! FATAL: produces seg fault with ifort, requires tmp to avoid!
c = tmp * conjg(transpose(tmp))
deallocate(tmp)
! positive-definite
do concurrent (i=1:n)
c(i,i) = c(i,i) + n
end do
call heevd(c, w, 'V')
call system_clock (count=end)
write(*,"(a,f8.3,a)") "ZHEEVD took: ", real(end - start)/real(rate), " seconds"
end program hermitianEigen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment