!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!  This file is AUTOMATICALLY GENERATED by:
!!  ../tools/fortran_wrappers.pl ../include/magma_s.i
!!  Do not edit.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

module magma_sfortran

use magma_param

implicit none

!---- Fortran interfaces to MAGMA subroutines ----
interface

subroutine magmaf_get_slaex3_m_nb(  )
end subroutine magmaf_get_slaex3_m_nb

integer function magmaf_get_spotrf_nb( m )
    integer :: m
end function magmaf_get_spotrf_nb

integer function magmaf_get_sgetrf_nb( m )
    integer :: m
end function magmaf_get_sgetrf_nb

integer function magmaf_get_sgetri_nb( m )
    integer :: m
end function magmaf_get_sgetri_nb

integer function magmaf_get_sgeqp3_nb( m )
    integer :: m
end function magmaf_get_sgeqp3_nb

integer function magmaf_get_sgeqrf_nb( m )
    integer :: m
end function magmaf_get_sgeqrf_nb

integer function magmaf_get_sgeqlf_nb( m )
    integer :: m
end function magmaf_get_sgeqlf_nb

integer function magmaf_get_sgehrd_nb( m )
    integer :: m
end function magmaf_get_sgehrd_nb

integer function magmaf_get_ssytrd_nb( m )
    integer :: m
end function magmaf_get_ssytrd_nb

integer function magmaf_get_ssytrf_nb( m )
    integer :: m
end function magmaf_get_ssytrf_nb

integer function magmaf_get_ssytrf_nopiv_nb( m )
    integer :: m
end function magmaf_get_ssytrf_nopiv_nb

integer function magmaf_get_sgelqf_nb( m )
    integer :: m
end function magmaf_get_sgelqf_nb

integer function magmaf_get_sgebrd_nb( m )
    integer :: m
end function magmaf_get_sgebrd_nb

integer function magmaf_get_ssygst_nb( m )
    integer :: m
end function magmaf_get_ssygst_nb

integer function magmaf_get_sgesvd_nb( m )
    integer :: m
end function magmaf_get_sgesvd_nb

integer function magmaf_get_ssygst_nb_m( m )
    integer :: m
end function magmaf_get_ssygst_nb_m

subroutine magmaf_get_sbulge_nb( m, nbthreads )
    integer          :: m
    integer          :: nbthreads
end subroutine magmaf_get_sbulge_nb

subroutine magmaf_sbulge_get_Vblksiz( m, nb, nbthreads )
    integer          :: m
    integer          :: nb
    integer          :: nbthreads
end subroutine magmaf_sbulge_get_Vblksiz

subroutine magmaf_get_sbulge_gcperf(  )
end subroutine magmaf_get_sbulge_gcperf

subroutine magmaf_smove_eig( range, n, w, il, iu, vl, vu, m )
    character        :: range
    integer          :: n
    real             :: w(*)
    integer          :: il(*)
    integer          :: iu(*)
    real             :: vl
    real             :: vu
    integer          :: m
end subroutine magmaf_smove_eig

subroutine magmaf_svrange( k, d, il, iu, vl, vu )
    integer          :: k
    real             :: d(*)
    integer          :: il(*)
    integer          :: iu(*)
    real             :: vl
    real             :: vu
end subroutine magmaf_svrange

subroutine magmaf_sirange( k, indxq, iil, iiu, il, iu )
    integer          :: k
    integer          :: indxq(*)
    integer          :: iil(*)
    integer          :: iiu(*)
    integer          :: il
    integer          :: iu
end subroutine magmaf_sirange

subroutine magmaf_sgebrd( m, n, A, lda, d, e, tauq, taup, work, lwork, info )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: d(*)
    real             :: e(*)
    real             :: tauq(*)
    real             :: taup(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgebrd

subroutine magmaf_sgeev( jobvl, jobvr, n, A, lda, wr, wi, VL, ldvl, VR, ldvr, work,  &
        lwork, info )
    character        :: jobvl
    character        :: jobvr
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: wr(*)
    real             :: wi(*)
    real             :: VL(*)
    integer          :: ldvl
    real             :: VR(*)
    integer          :: ldvr
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeev

subroutine magmaf_sgehrd( n, ilo, ihi, A, lda, tau, work, lwork, dT, info )
    integer          :: n
    integer          :: ilo
    integer          :: ihi
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    magma_devptr_t   :: dT
    integer          :: info
end subroutine magmaf_sgehrd

subroutine magmaf_sgehrd2( n, ilo, ihi, A, lda, tau, work, lwork, info )
    integer          :: n
    integer          :: ilo
    integer          :: ihi
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgehrd2

subroutine magmaf_sgelqf( m, n, A, lda, tau, work, lwork, info )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgelqf

subroutine magmaf_sgeqlf( m, n, A, lda, tau, work, lwork, info )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeqlf

subroutine magmaf_sgeqp3( m, n, A, lda, jpvt, tau, work, lwork, info )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: jpvt(*)
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeqp3

subroutine magmaf_sgeqrf( m, n, A, lda, tau, work, lwork, info )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeqrf

subroutine magmaf_sgeqrf_ooc( m, n, A, lda, tau, work, lwork, info )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeqrf_ooc

subroutine magmaf_sgeqrf4( ngpu, m, n, A, lda, tau, work, lwork, info )
    integer          :: ngpu
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeqrf4

subroutine magmaf_sgesdd( jobz, m, n, A, lda, s, U, ldu, VT, ldvt, work, lwork, iwork,  &
        info )
    character        :: jobz
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: s(*)
    real             :: U(*)
    integer          :: ldu
    real             :: VT(*)
    integer          :: ldvt
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: info
end subroutine magmaf_sgesdd

subroutine magmaf_sgesv( n, nrhs, A, lda, ipiv, B, ldb, info )
    integer          :: n
    integer          :: nrhs
    real             :: A(*)
    integer          :: lda
    integer          :: ipiv(*)
    real             :: B(*)
    integer          :: ldb
    integer          :: info
end subroutine magmaf_sgesv

subroutine magmaf_sgesv_rbt( ref, n, nrhs, A, lda, B, ldb, info )
    character        :: ref
    integer          :: n
    integer          :: nrhs
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    integer          :: info
end subroutine magmaf_sgesv_rbt

subroutine magmaf_sgesvd( jobu, jobvt, m, n, A, lda, s, U, ldu, VT, ldvt, work, lwork,  &
        info )
    character        :: jobu
    character        :: jobvt
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: s(*)
    real             :: U(*)
    integer          :: ldu
    real             :: VT(*)
    integer          :: ldvt
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgesvd

subroutine magmaf_sgetf2_nopiv( m, n, A, lda, info )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: info
end subroutine magmaf_sgetf2_nopiv

subroutine magmaf_sgetrf( m, n, A, lda, ipiv, info )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: ipiv(*)
    integer          :: info
end subroutine magmaf_sgetrf

subroutine magmaf_sgetrf_nopiv( m, n, A, lda, info )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: info
end subroutine magmaf_sgetrf_nopiv

subroutine magmaf_sgetrf_piv( m, n, NB, A, lda, ipiv, info )
    integer          :: m
    integer          :: n
    integer          :: NB
    real             :: A(*)
    integer          :: lda
    integer          :: ipiv(*)
    integer          :: info
end subroutine magmaf_sgetrf_piv

subroutine magmaf_ssyevd( jobz, uplo, n, A, lda, w, work, lwork, iwork, liwork, info )
    character        :: jobz
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssyevd

subroutine magmaf_ssyevdx( jobz, range, uplo, n, A, lda, vl, vu, il, iu, m, w, work,  &
        lwork, iwork, liwork, info )
    character        :: jobz
    character        :: range
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    integer          :: m
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssyevdx

subroutine magmaf_ssyevdx_2stage( jobz, range, uplo, n, A, lda, vl, vu, il, iu, m, w,  &
        work, lwork, iwork, liwork, info )
    character        :: jobz
    character        :: range
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    integer          :: m
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssyevdx_2stage

subroutine magmaf_ssygst( itype, uplo, n, A, lda, B, ldb, info )
    integer          :: itype
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    integer          :: info
end subroutine magmaf_ssygst

subroutine magmaf_ssygvd( itype, jobz, uplo, n, A, lda, B, ldb, w, work, lwork, iwork,  &
        liwork, info )
    integer          :: itype
    character        :: jobz
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssygvd

subroutine magmaf_ssygvdx( itype, jobz, range, uplo, n, A, lda, B, ldb, vl, vu, il, iu,  &
        m, w, work, lwork, iwork, liwork, info )
    integer          :: itype
    character        :: jobz
    character        :: range
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    integer          :: m
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssygvdx

subroutine magmaf_ssygvdx_2stage( itype, jobz, range, uplo, n, A, lda, B, ldb, vl, vu,  &
        il, iu, m, w, work, lwork, iwork, liwork, info )
    integer          :: itype
    character        :: jobz
    character        :: range
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    integer          :: m
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssygvdx_2stage

subroutine magmaf_ssysv( uplo, n, nrhs, A, lda, ipiv, B, ldb, info )
    character        :: uplo
    integer          :: n
    integer          :: nrhs
    real             :: A(*)
    integer          :: lda
    integer          :: ipiv(*)
    real             :: B(*)
    integer          :: ldb
    integer          :: info
end subroutine magmaf_ssysv

subroutine magmaf_ssytrd( uplo, n, A, lda, d, e, tau, work, lwork, info )
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: d(*)
    real             :: e(*)
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_ssytrd

subroutine magmaf_ssytrf( uplo, n, A, lda, ipiv, info )
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: ipiv(*)
    integer          :: info
end subroutine magmaf_ssytrf

subroutine magmaf_ssytrf_nopiv( uplo, n, a, lda, info )
    character        :: uplo
    integer          :: n
    real             :: a(*)
    integer          :: lda
    integer          :: info
end subroutine magmaf_ssytrf_nopiv

subroutine magmaf_ssytrd_sb2st( uplo, n, nb, Vblksiz, A, lda, d, e, V, ldv, TAU, compT,  &
        T, ldt )
    character        :: uplo
    integer          :: n
    integer          :: nb
    integer          :: Vblksiz
    real             :: A(*)
    integer          :: lda
    real             :: d(*)
    real             :: e(*)
    real             :: V(*)
    integer          :: ldv
    real             :: TAU(*)
    integer          :: compT
    real             :: T(*)
    integer          :: ldt
end subroutine magmaf_ssytrd_sb2st

subroutine magmaf_ssytrd_sy2sb( uplo, n, nb, A, lda, tau, work, lwork, dT, info )
    character        :: uplo
    integer          :: n
    integer          :: nb
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    magma_devptr_t   :: dT
    integer          :: info
end subroutine magmaf_ssytrd_sy2sb

subroutine magmaf_slaln2( trans, na, nw, smin, ca, A, lda, d1, d2, B, ldb, wr, wi, X,  &
        ldx, scale, xnorm, info )
    integer          :: trans
    integer          :: na
    integer          :: nw
    real             :: smin
    real             :: ca
    real             :: A(*)
    integer          :: lda
    real             :: d1
    real             :: d2
    real             :: B(*)
    integer          :: ldb
    real             :: wr
    real             :: wi
    real             :: X(*)
    integer          :: ldx
    real             :: scale(*)
    real             :: xnorm(*)
    integer          :: info
end subroutine magmaf_slaln2

subroutine magmaf_slaqtrsd( trans, n, T, ldt, x, ldx, cnorm, info )
    character        :: trans
    integer          :: n
    real             :: T(*)
    integer          :: ldt
    real             :: x(*)
    integer          :: ldx
    real             :: cnorm(*)
    integer          :: info
end subroutine magmaf_slaqtrsd

subroutine magmaf_slauum( uplo, n, A, lda, info )
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: info
end subroutine magmaf_slauum

subroutine magmaf_sposv( uplo, n, nrhs, A, lda, B, ldb, info )
    character        :: uplo
    integer          :: n
    integer          :: nrhs
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    integer          :: info
end subroutine magmaf_sposv

subroutine magmaf_spotrf( uplo, n, A, lda, info )
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: info
end subroutine magmaf_spotrf

subroutine magmaf_spotri( uplo, n, A, lda, info )
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: info
end subroutine magmaf_spotri

subroutine magmaf_sstedx( range, n, vl, vu, il, iu, d, e, Z, ldz, rwork, lrwork, iwork,  &
        liwork, dwork, info )
    character        :: range
    integer          :: n
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    real             :: d(*)
    real             :: e(*)
    real             :: Z(*)
    integer          :: ldz
    real             :: rwork(*)
    integer          :: lrwork
    integer          :: iwork(*)
    integer          :: liwork
    magma_devptr_t   :: dwork
    integer          :: info
end subroutine magmaf_sstedx

subroutine magmaf_strevc3( side, howmany, select, n, T, ldt, VL, ldvl, VR, ldvr, mm,  &
        mout, work, lwork, info )
    character        :: side
    character        :: howmany
    integer          :: select(*)
    integer          :: n
    real             :: T(*)
    integer          :: ldt
    real             :: VL(*)
    integer          :: ldvl
    real             :: VR(*)
    integer          :: ldvr
    integer          :: mm
    integer          :: mout(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_strevc3

subroutine magmaf_strevc3_mt( side, howmany, select, n, T, ldt, VL, ldvl, VR, ldvr, mm,  &
        mout, work, lwork, info )
    character        :: side
    character        :: howmany
    integer          :: select(*)
    integer          :: n
    real             :: T(*)
    integer          :: ldt
    real             :: VL(*)
    integer          :: ldvl
    real             :: VR(*)
    integer          :: ldvr
    integer          :: mm
    integer          :: mout(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_strevc3_mt

subroutine magmaf_strtri( uplo, diag, n, A, lda, info )
    character        :: uplo
    character        :: diag
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: info
end subroutine magmaf_strtri

subroutine magmaf_sorghr( n, ilo, ihi, A, lda, tau, dT, nb, info )
    integer          :: n
    integer          :: ilo
    integer          :: ihi
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    magma_devptr_t   :: dT
    integer          :: nb
    integer          :: info
end subroutine magmaf_sorghr

subroutine magmaf_sorgqr( m, n, k, A, lda, tau, dT, nb, info )
    integer          :: m
    integer          :: n
    integer          :: k
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    magma_devptr_t   :: dT
    integer          :: nb
    integer          :: info
end subroutine magmaf_sorgqr

subroutine magmaf_sorgqr2( m, n, k, A, lda, tau, info )
    integer          :: m
    integer          :: n
    integer          :: k
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    integer          :: info
end subroutine magmaf_sorgqr2

subroutine magmaf_sormbr( vect, side, trans, m, n, k, A, lda, tau, C, ldc, work, lwork,  &
        info )
    character        :: vect
    character        :: side
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: k
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: C(*)
    integer          :: ldc
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sormbr

subroutine magmaf_sormlq( side, trans, m, n, k, A, lda, tau, C, ldc, work, lwork, info )
    character        :: side
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: k
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: C(*)
    integer          :: ldc
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sormlq

subroutine magmaf_sormql( side, trans, m, n, k, A, lda, tau, C, ldc, work, lwork, info )
    character        :: side
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: k
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: C(*)
    integer          :: ldc
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sormql

subroutine magmaf_sormqr( side, trans, m, n, k, A, lda, tau, C, ldc, work, lwork, info )
    character        :: side
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: k
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: C(*)
    integer          :: ldc
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sormqr

subroutine magmaf_sormtr( side, uplo, trans, m, n, A, lda, tau, C, ldc, work, lwork, info  &
        )
    character        :: side
    character        :: uplo
    character        :: trans
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: C(*)
    integer          :: ldc
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sormtr

subroutine magmaf_sgeev_m( jobvl, jobvr, n, A, lda, wr, wi, VL, ldvl, VR, ldvr, work,  &
        lwork, info )
    character        :: jobvl
    character        :: jobvr
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: wr(*)
    real             :: wi(*)
    real             :: VL(*)
    integer          :: ldvl
    real             :: VR(*)
    integer          :: ldvr
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeev_m

subroutine magmaf_sgehrd_m( n, ilo, ihi, A, lda, tau, work, lwork, T, info )
    integer          :: n
    integer          :: ilo
    integer          :: ihi
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    real             :: T(*)
    integer          :: info
end subroutine magmaf_sgehrd_m

subroutine magmaf_sgetrf_m( ngpu, m, n, A, lda, ipiv, info )
    integer          :: ngpu
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: ipiv(*)
    integer          :: info
end subroutine magmaf_sgetrf_m

subroutine magmaf_ssyevd_m( ngpu, jobz, uplo, n, A, lda, w, work, lwork, iwork, liwork,  &
        info )
    integer          :: ngpu
    character        :: jobz
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssyevd_m

subroutine magmaf_ssyevdx_2stage_m( ngpu, jobz, range, uplo, n, A, lda, vl, vu, il, iu,  &
        m, w, work, lwork, iwork, liwork, info )
    integer          :: ngpu
    character        :: jobz
    character        :: range
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    integer          :: m
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssyevdx_2stage_m

subroutine magmaf_ssyevdx_m( ngpu, jobz, range, uplo, n, A, lda, vl, vu, il, iu, m, w,  &
        work, lwork, iwork, liwork, info )
    integer          :: ngpu
    character        :: jobz
    character        :: range
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    integer          :: m
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssyevdx_m

subroutine magmaf_ssygst_m( ngpu, itype, uplo, n, A, lda, B, ldb, info )
    integer          :: ngpu
    integer          :: itype
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    integer          :: info
end subroutine magmaf_ssygst_m

subroutine magmaf_ssygvd_m( ngpu, itype, jobz, uplo, n, A, lda, B, ldb, w, work, lwork,  &
        iwork, liwork, info )
    integer          :: ngpu
    integer          :: itype
    character        :: jobz
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssygvd_m

subroutine magmaf_ssygvdx_2stage_m( ngpu, itype, jobz, range, uplo, n, A, lda, B, ldb,  &
        vl, vu, il, iu, m, w, work, lwork, iwork, liwork, info )
    integer          :: ngpu
    integer          :: itype
    character        :: jobz
    character        :: range
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    integer          :: m
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssygvdx_2stage_m

subroutine magmaf_ssygvdx_m( ngpu, itype, jobz, range, uplo, n, A, lda, B, ldb, vl, vu,  &
        il, iu, m, w, work, lwork, iwork, liwork, info )
    integer          :: ngpu
    integer          :: itype
    character        :: jobz
    character        :: range
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    integer          :: m
    real             :: w(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssygvdx_m

subroutine magmaf_spotrf_m( ngpu, uplo, n, A, lda, info )
    integer          :: ngpu
    character        :: uplo
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: info
end subroutine magmaf_spotrf_m

subroutine magmaf_sstedx_m( ngpu, range, n, vl, vu, il, iu, d, e, Z, ldz, rwork, lrwork,  &
        iwork, liwork, info )
    integer          :: ngpu
    character        :: range
    integer          :: n
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    real             :: d(*)
    real             :: e(*)
    real             :: Z(*)
    integer          :: ldz
    real             :: rwork(*)
    integer          :: lrwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_sstedx_m

subroutine magmaf_strsm_m( ngpu, side, uplo, transa, diag, m, n, alpha, A, lda, B, ldb )
    integer          :: ngpu
    character        :: side
    character        :: uplo
    character        :: transa
    character        :: diag
    integer          :: m
    integer          :: n
    real             :: alpha
    real             :: A(*)
    integer          :: lda
    real             :: B(*)
    integer          :: ldb
end subroutine magmaf_strsm_m

subroutine magmaf_sorghr_m( n, ilo, ihi, A, lda, tau, T, nb, info )
    integer          :: n
    integer          :: ilo
    integer          :: ihi
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: T(*)
    integer          :: nb
    integer          :: info
end subroutine magmaf_sorghr_m

subroutine magmaf_sorgqr_m( m, n, k, A, lda, tau, T, nb, info )
    integer          :: m
    integer          :: n
    integer          :: k
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: T(*)
    integer          :: nb
    integer          :: info
end subroutine magmaf_sorgqr_m

subroutine magmaf_sormqr_m( ngpu, side, trans, m, n, k, A, lda, tau, C, ldc, work, lwork,  &
        info )
    integer          :: ngpu
    character        :: side
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: k
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: C(*)
    integer          :: ldc
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sormqr_m

subroutine magmaf_sormtr_m( ngpu, side, uplo, trans, m, n, A, lda, tau, C, ldc, work,  &
        lwork, info )
    integer          :: ngpu
    character        :: side
    character        :: uplo
    character        :: trans
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    real             :: tau(*)
    real             :: C(*)
    integer          :: ldc
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sormtr_m

subroutine magmaf_sgegqr_gpu( ikind, m, n, dA, ldda, dwork, work, info )
    integer          :: ikind
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dwork
    real             :: work(*)
    integer          :: info
end subroutine magmaf_sgegqr_gpu

subroutine magmaf_sgelqf_gpu( m, n, dA, ldda, tau, work, lwork, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgelqf_gpu

subroutine magmaf_sgels_gpu( trans, m, n, nrhs, dA, ldda, dB, lddb, hwork, lwork, info )
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dB
    integer          :: lddb
    real             :: hwork(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgels_gpu

subroutine magmaf_sgels3_gpu( trans, m, n, nrhs, dA, ldda, dB, lddb, hwork, lwork, info )
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dB
    integer          :: lddb
    real             :: hwork(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgels3_gpu

subroutine magmaf_sgeqp3_gpu( m, n, dA, ldda, jpvt, tau, dwork, lwork, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: jpvt(*)
    real             :: tau(*)
    magma_devptr_t   :: dwork
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeqp3_gpu

subroutine magmaf_sgeqr2x_gpu( m, n, dA, ldda, dtau, dT, ddA, dwork, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dtau
    magma_devptr_t   :: dT
    magma_devptr_t   :: ddA
    magma_devptr_t   :: dwork
    integer          :: info
end subroutine magmaf_sgeqr2x_gpu

subroutine magmaf_sgeqr2x2_gpu( m, n, dA, ldda, dtau, dT, ddA, dwork, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dtau
    magma_devptr_t   :: dT
    magma_devptr_t   :: ddA
    magma_devptr_t   :: dwork
    integer          :: info
end subroutine magmaf_sgeqr2x2_gpu

subroutine magmaf_sgeqr2x3_gpu( m, n, dA, ldda, dtau, dT, ddA, dwork, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dtau
    magma_devptr_t   :: dT
    magma_devptr_t   :: ddA
    magma_devptr_t   :: dwork
    integer          :: info
end subroutine magmaf_sgeqr2x3_gpu

subroutine magmaf_sgeqr2x4_gpu( m, n, dA, ldda, dtau, dT, ddA, dwork, queue, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dtau
    magma_devptr_t   :: dT
    magma_devptr_t   :: ddA
    magma_devptr_t   :: dwork
    integer          :: queue
    integer          :: info
end subroutine magmaf_sgeqr2x4_gpu

subroutine magmaf_sgeqrf_gpu( m, n, dA, ldda, tau, dT, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    magma_devptr_t   :: dT
    integer          :: info
end subroutine magmaf_sgeqrf_gpu

subroutine magmaf_sgeqrf2_gpu( m, n, dA, ldda, tau, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    integer          :: info
end subroutine magmaf_sgeqrf2_gpu

subroutine magmaf_sgeqrf3_gpu( m, n, dA, ldda, tau, dT, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    magma_devptr_t   :: dT
    integer          :: info
end subroutine magmaf_sgeqrf3_gpu

subroutine magmaf_sgeqrs_gpu( m, n, nrhs, dA, ldda, tau, dT, dB, lddb, hwork, lwork, info  &
        )
    integer          :: m
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    magma_devptr_t   :: dT
    magma_devptr_t   :: dB
    integer          :: lddb
    real             :: hwork(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeqrs_gpu

subroutine magmaf_sgeqrs3_gpu( m, n, nrhs, dA, ldda, tau, dT, dB, lddb, hwork, lwork,  &
        info )
    integer          :: m
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    magma_devptr_t   :: dT
    magma_devptr_t   :: dB
    integer          :: lddb
    real             :: hwork(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgeqrs3_gpu

subroutine magmaf_sgerbt_gpu( gen, n, nrhs, dA, ldda, dB, lddb, U, V, info )
    character        :: gen
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dB
    integer          :: lddb
    real             :: U(*)
    real             :: V(*)
    integer          :: info
end subroutine magmaf_sgerbt_gpu

subroutine magmaf_sgessm_gpu( order, m, n, k, ib, ipiv, dL1, lddl1, dL, lddl, dA, ldda,  &
        info )
    character        :: order
    integer          :: m
    integer          :: n
    integer          :: k
    integer          :: ib
    integer          :: ipiv(*)
    magma_devptr_t   :: dL1
    integer          :: lddl1
    magma_devptr_t   :: dL
    integer          :: lddl
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: info
end subroutine magmaf_sgessm_gpu

subroutine magmaf_sgesv_gpu( n, nrhs, dA, ldda, ipiv, dB, lddb, info )
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: ipiv(*)
    magma_devptr_t   :: dB
    integer          :: lddb
    integer          :: info
end subroutine magmaf_sgesv_gpu

subroutine magmaf_sgesv_nopiv_gpu( n, nrhs, dA, ldda, dB, lddb, info )
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dB
    integer          :: lddb
    integer          :: info
end subroutine magmaf_sgesv_nopiv_gpu

subroutine magmaf_sgetf2_gpu( m, n, dA, ldda, ipiv, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: ipiv(*)
    integer          :: info
end subroutine magmaf_sgetf2_gpu

subroutine magmaf_sgetrf_gpu( m, n, dA, ldda, ipiv, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: ipiv(*)
    integer          :: info
end subroutine magmaf_sgetrf_gpu

subroutine magmaf_sgetrf_nopiv_gpu( m, n, dA, ldda, info )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: info
end subroutine magmaf_sgetrf_nopiv_gpu

subroutine magmaf_sgetri_gpu( n, dA, ldda, ipiv, dwork, lwork, info )
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: ipiv(*)
    magma_devptr_t   :: dwork
    integer          :: lwork
    integer          :: info
end subroutine magmaf_sgetri_gpu

subroutine magmaf_sgetrs_gpu( trans, n, nrhs, dA, ldda, ipiv, dB, lddb, info )
    character        :: trans
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: ipiv(*)
    magma_devptr_t   :: dB
    integer          :: lddb
    integer          :: info
end subroutine magmaf_sgetrs_gpu

subroutine magmaf_sgetrs_nopiv_gpu( trans, n, nrhs, dA, ldda, dB, lddb, info )
    character        :: trans
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dB
    integer          :: lddb
    integer          :: info
end subroutine magmaf_sgetrs_nopiv_gpu

subroutine magmaf_ssyevd_gpu( jobz, uplo, n, dA, ldda, w, wA, ldwa, work, lwork, iwork,  &
        liwork, info )
    character        :: jobz
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: w(*)
    real             :: wA(*)
    integer          :: ldwa
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssyevd_gpu

subroutine magmaf_ssyevdx_gpu( jobz, range, uplo, n, dA, ldda, vl, vu, il, iu, m, w, wA,  &
        ldwa, work, lwork, iwork, liwork, info )
    character        :: jobz
    character        :: range
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: vl
    real             :: vu
    integer          :: il
    integer          :: iu
    integer          :: m
    real             :: w(*)
    real             :: wA(*)
    integer          :: ldwa
    real             :: work(*)
    integer          :: lwork
    integer          :: iwork(*)
    integer          :: liwork
    integer          :: info
end subroutine magmaf_ssyevdx_gpu

subroutine magmaf_ssygst_gpu( itype, uplo, n, dA, ldda, dB, lddb, info )
    integer          :: itype
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dB
    integer          :: lddb
    integer          :: info
end subroutine magmaf_ssygst_gpu

subroutine magmaf_ssytrd_gpu( uplo, n, dA, ldda, d, e, tau, wA, ldwa, work, lwork, info )
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: d(*)
    real             :: e(*)
    real             :: tau(*)
    real             :: wA(*)
    integer          :: ldwa
    real             :: work(*)
    integer          :: lwork
    integer          :: info
end subroutine magmaf_ssytrd_gpu

subroutine magmaf_ssytrd2_gpu( uplo, n, dA, ldda, d, e, tau, wA, ldwa, work, lwork,  &
        dwork, ldwork, info )
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: d(*)
    real             :: e(*)
    real             :: tau(*)
    real             :: wA(*)
    integer          :: ldwa
    real             :: work(*)
    integer          :: lwork
    magma_devptr_t   :: dwork
    integer          :: ldwork
    integer          :: info
end subroutine magmaf_ssytrd2_gpu

subroutine magmaf_ssytrf_nopiv_gpu( uplo, n, da, ldda, info )
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: da
    integer          :: ldda
    integer          :: info
end subroutine magmaf_ssytrf_nopiv_gpu

subroutine magmaf_slarf_gpu( m, n, dv, dtau, dC, lddc )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dv
    magma_devptr_t   :: dtau
    magma_devptr_t   :: dC
    integer          :: lddc
end subroutine magmaf_slarf_gpu

subroutine magmaf_slarfb_gpu( side, trans, direct, storev, m, n, k, dV, lddv, dT, lddt,  &
        dC, lddc, dwork, ldwork )
    character        :: side
    character        :: trans
    character        :: direct
    character        :: storev
    integer          :: m
    integer          :: n
    integer          :: k
    magma_devptr_t   :: dV
    integer          :: lddv
    magma_devptr_t   :: dT
    integer          :: lddt
    magma_devptr_t   :: dC
    integer          :: lddc
    magma_devptr_t   :: dwork
    integer          :: ldwork
end subroutine magmaf_slarfb_gpu

subroutine magmaf_slarfb_gpu_gemm( side, trans, direct, storev, m, n, k, dV, lddv, dT,  &
        lddt, dC, lddc, dwork, ldwork, dworkvt, ldworkvt )
    character        :: side
    character        :: trans
    character        :: direct
    character        :: storev
    integer          :: m
    integer          :: n
    integer          :: k
    magma_devptr_t   :: dV
    integer          :: lddv
    magma_devptr_t   :: dT
    integer          :: lddt
    magma_devptr_t   :: dC
    integer          :: lddc
    magma_devptr_t   :: dwork
    integer          :: ldwork
    magma_devptr_t   :: dworkvt
    integer          :: ldworkvt
end subroutine magmaf_slarfb_gpu_gemm

subroutine magmaf_slarfb2_gpu( m, n, k, dV, lddv, dT, lddt, dC, lddc, dwork, ldwork )
    integer          :: m
    integer          :: n
    integer          :: k
    magma_devptr_t   :: dV
    integer          :: lddv
    magma_devptr_t   :: dT
    integer          :: lddt
    magma_devptr_t   :: dC
    integer          :: lddc
    magma_devptr_t   :: dwork
    integer          :: ldwork
end subroutine magmaf_slarfb2_gpu

subroutine magmaf_slauum_gpu( uplo, n, dA, ldda, info )
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: info
end subroutine magmaf_slauum_gpu

subroutine magmaf_sposv_gpu( uplo, n, nrhs, dA, ldda, dB, lddb, info )
    character        :: uplo
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dB
    integer          :: lddb
    integer          :: info
end subroutine magmaf_sposv_gpu

subroutine magmaf_spotf2_gpu( uplo, n, dA, ldda, info )
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: info
end subroutine magmaf_spotf2_gpu

subroutine magmaf_spotrf_gpu( uplo, n, dA, ldda, info )
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: info
end subroutine magmaf_spotrf_gpu

subroutine magmaf_spotri_gpu( uplo, n, dA, ldda, info )
    character        :: uplo
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: info
end subroutine magmaf_spotri_gpu

subroutine magmaf_spotrs_gpu( uplo, n, nrhs, dA, ldda, dB, lddb, info )
    character        :: uplo
    integer          :: n
    integer          :: nrhs
    magma_devptr_t   :: dA
    integer          :: ldda
    magma_devptr_t   :: dB
    integer          :: lddb
    integer          :: info
end subroutine magmaf_spotrs_gpu

subroutine magmaf_sssssm_gpu( order, m1, n1, m2, n2, k, ib, dA1, ldda1, dA2, ldda2, dL1,  &
        lddl1, dL2, lddl2, ipiv, info )
    character        :: order
    integer          :: m1
    integer          :: n1
    integer          :: m2
    integer          :: n2
    integer          :: k
    integer          :: ib
    magma_devptr_t   :: dA1
    integer          :: ldda1
    magma_devptr_t   :: dA2
    integer          :: ldda2
    magma_devptr_t   :: dL1
    integer          :: lddl1
    magma_devptr_t   :: dL2
    integer          :: lddl2
    integer          :: ipiv(*)
    integer          :: info
end subroutine magmaf_sssssm_gpu

subroutine magmaf_strtri_gpu( uplo, diag, n, dA, ldda, info )
    character        :: uplo
    character        :: diag
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: info
end subroutine magmaf_strtri_gpu

subroutine magmaf_sorgqr_gpu( m, n, k, dA, ldda, tau, dT, nb, info )
    integer          :: m
    integer          :: n
    integer          :: k
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    magma_devptr_t   :: dT
    integer          :: nb
    integer          :: info
end subroutine magmaf_sorgqr_gpu

subroutine magmaf_sormql2_gpu( side, trans, m, n, k, dA, ldda, tau, dC, lddc, wA, ldwa,  &
        info )
    character        :: side
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: k
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    magma_devptr_t   :: dC
    integer          :: lddc
    real             :: wA(*)
    integer          :: ldwa
    integer          :: info
end subroutine magmaf_sormql2_gpu

subroutine magmaf_sormqr_gpu( side, trans, m, n, k, dA, ldda, tau, dC, lddc, hwork,  &
        lwork, dT, nb, info )
    character        :: side
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: k
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    magma_devptr_t   :: dC
    integer          :: lddc
    real             :: hwork(*)
    integer          :: lwork
    magma_devptr_t   :: dT
    integer          :: nb
    integer          :: info
end subroutine magmaf_sormqr_gpu

subroutine magmaf_sormqr2_gpu( side, trans, m, n, k, dA, ldda, tau, dC, lddc, wA, ldwa,  &
        info )
    character        :: side
    character        :: trans
    integer          :: m
    integer          :: n
    integer          :: k
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    magma_devptr_t   :: dC
    integer          :: lddc
    real             :: wA(*)
    integer          :: ldwa
    integer          :: info
end subroutine magmaf_sormqr2_gpu

subroutine magmaf_sormtr_gpu( side, uplo, trans, m, n, dA, ldda, tau, dC, lddc, wA, ldwa,  &
        info )
    character        :: side
    character        :: uplo
    character        :: trans
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    real             :: tau(*)
    magma_devptr_t   :: dC
    integer          :: lddc
    real             :: wA(*)
    integer          :: ldwa
    integer          :: info
end subroutine magmaf_sormtr_gpu

subroutine magmaf_snan_inf( uplo, m, n, A, lda, cnt_nan, cnt_inf )
    character        :: uplo
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
    integer          :: cnt_nan(*)
    integer          :: cnt_inf(*)
end subroutine magmaf_snan_inf

subroutine magmaf_snan_inf_gpu( uplo, m, n, dA, ldda, cnt_nan, cnt_inf )
    character        :: uplo
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
    integer          :: cnt_nan(*)
    integer          :: cnt_inf(*)
end subroutine magmaf_snan_inf_gpu

subroutine magmaf_sprint( m, n, A, lda )
    integer          :: m
    integer          :: n
    real             :: A(*)
    integer          :: lda
end subroutine magmaf_sprint

subroutine magmaf_sprint_gpu( m, n, dA, ldda )
    integer          :: m
    integer          :: n
    magma_devptr_t   :: dA
    integer          :: ldda
end subroutine magmaf_sprint_gpu

end interface

!---- Fortran-only subroutines (see ../tools/fortran_wrappers.pl to edit) ----
contains

subroutine magmaf_soff1d( ptrNew, ptrOld, inc, i)
    magma_devptr_t   :: ptrNew
    magma_devptr_t   :: ptrOld
    integer          :: inc, i

    ptrNew = ptrOld + (i-1) * inc * sizeof_real
end subroutine magmaf_soff1d

subroutine magmaf_soff2d( ptrNew, ptrOld, lda, i, j)
    magma_devptr_t   :: ptrNew
    magma_devptr_t   :: ptrOld
    integer          :: lda, i, j

    ptrNew = ptrOld + ((j-1) * lda + (i-1)) * sizeof_real
end subroutine magmaf_soff2d

end module magma_sfortran


!***************************************************************************************************
! xnet_controls.f90 10/18/17
! This file contains modules and subroutines to control the execution of XNet.
!***************************************************************************************************

Module xnet_controls
  !-------------------------------------------------------------------------------------------------
  ! This module contains the values of the flags and limits which control the behavior of the
  ! network. Generally read from the control file.
  !-------------------------------------------------------------------------------------------------
  Use, Intrinsic :: iso_fortran_env, Only: lun_stderr=>error_unit, lun_stdin=>input_unit, lun_stdout=>output_unit
  Use xnet_types, Only: dp
  Implicit None

  ! Problem Description
  Character(80) :: descript(3)

  ! Job Controls
  Integer              :: szone      ! starting zone
  Integer              :: nzone      ! Number of zones
  Integer, Allocatable :: zone_id(:,:) ! Current zone index map (ix,block)
  Integer, Allocatable :: iweak(:)   ! If >0, strong and weak reactions are used
                                     ! If =0, weak reactions are ignored
                                     ! If <0, only weak reactions are used
  Integer              :: iweak0     ! Saves input iweak flag
  Integer              :: iscrn      ! If =0, screening is ignored
  Integer              :: iprocess   ! If =0, assume network has been pre-processed.
                                     ! If >0, then run network pre-processing (slows calculation)

  ! Zone Batching Controls
  Integer  :: nzevolve                ! Number of zones being simultaneously evolved
  Integer  :: nzbatchmx               ! Maximum number of zones in a batch
  Integer  :: nzbatch                 ! Active number of zones in a batch
  Integer  :: szbatch                 ! Starting zone for a batch
  Integer  :: zb_offset               ! Zone-batch offset in nzevolve
  Integer  :: zb_lo                   ! Lower extent of zone-batch in nzevolve
  Integer  :: zb_hi                   ! Upper extent of zone-batch in nzevolve
  Logical, Allocatable, Target :: lzactive(:) ! Mask for active zones
  !$omp threadprivate(nzbatch,szbatch,zb_offset,zb_lo,zb_hi)

  ! Integration Controls
  Integer  :: isolv                 ! Sets the integration method (1=BE, 2=BD)
  Integer  :: kstmx                 ! Max # of timesteps before exit
  Integer  :: kitmx                 ! Max # of iterations or substeps within a timestep
  Integer  :: ijac                  ! Rebuild the Jacobian every ijac iterations after the first
  Integer  :: iconvc                ! Controls type of convergence condition (0=mass)
  Real(dp) :: changemx              ! Relative abundance change used to guess timestep
  Real(dp) :: yacc                  ! Min abundance required to be accuracte, used in timestep determination.
  Real(dp) :: tolc                  ! The iterative convergence test limit
  Real(dp) :: tolm                  ! Max network mass error
  Real(dp) :: ymin                  ! Minimum abundance, y < ymin = 0
  Real(dp) :: tdel_maxmult          ! new timestep <= tdel_maxmult * previous timestep
  Integer, Allocatable :: kmon(:,:) ! Solver-dependent behaviour monitors
  Integer, Allocatable :: ktot(:,:) ! Cumulative solver-dependent behaviour monitors
  Real(dp) :: t9min = 0.01          ! Temperature minimum for turning strong reactions off

  ! Self-heating Controls
  Integer  :: iheat        ! If >0, then implicitly couple network to temperature (self-heating)
  Real(dp) :: changemxt    ! Relative temperature change used to guess timestep
  Real(dp) :: tolt9        ! The iterative convergence test limit

  ! NSE Initial Conditions Controls
  Real(dp) :: t9nse = 8.0  ! Temperature maximum for switching to NSE

  ! Neutrinos Controls
  Integer  :: ineutrino    ! If >0, the include neutrino capture reactions

  ! Output controls
  Integer                   :: nnucout         ! Number of species to be output in condensed form
  Character(4)              :: nnucout_string  ! For output formatting
  Integer, Allocatable      :: inucout(:)      ! List of species to output in condensed form
  Character(5), Allocatable :: output_nuc(:)   ! Names of nuclei to be output in condensed form
  Integer       :: idiag                       ! Sets level of diagnostic output
  Integer       :: itsout                      ! Sets level of time series output
  Character(80) :: ev_file_base, bin_file_base ! Output filename bases
  Integer       :: lun_diag                    ! Logical units for per-thread diagnostic output file
  Integer, Allocatable :: lun_ts(:), lun_ev(:) ! Logical units for per-zone output files
  !$omp threadprivate(lun_diag)

  ! Input controls
  Character(80) :: inab_file_base, thermo_file_base ! Input filename bases
  Character(80), Allocatable :: inab_file(:)        ! Initial abundance files for each zone
  Character(80), Allocatable :: thermo_file(:)      ! Thermo trajectory files for each zone
  Integer       :: lun_th, lun_ab                   ! Logical units for input files
  Integer, Allocatable :: iaux(:)                   ! Logical units for use of aux nucleus
  !$omp threadprivate(lun_th,lun_ab)

  ! Job indentifiers
  Integer :: myid, nproc, mythread, nthread ! task & thread ids and counts
  !$omp threadprivate(mythread)

  ! Sweep identifier
  Character(LEN=1) :: sweep ! Current hydro sweep: x, y, z
  !$omp threadprivate(sweep)

Contains

  Subroutine find_controls_block(lun_control,block_string,ifcb)
    !-----------------------------------------------------------------------------------------------
    ! This routine scans the control file for the input control block identifier string and
    ! positions the file to read that subset of the controls.
    !-----------------------------------------------------------------------------------------------
    Use, Intrinsic :: iso_fortran_env, Only: iostat_end
    Implicit None

    ! Input variables
    Integer, Intent(in)      :: lun_control
    Character(*), Intent(in) :: block_string

    ! Output variables
    Integer, Intent(out)     :: ifcb

    ! Local variables
    Integer, Parameter       :: line_limit = 1000
    Character(2)             :: test_marker, block_marker="##"
    Character(80)            :: test_read
    Integer                  :: ierr, itest
    Integer                  :: ii ! Loop Indicies

    ! Initialize return status
    ifcb = 1

    ! Rewind control file to the beginning
    Rewind(lun_control,iostat=ierr)

    ! Cycle through file
    Do ii = 1, line_limit
      Read(lun_control,"(a2,a80)",iostat=ierr) test_marker,test_read

      ! Test status of file
      If ( ierr == iostat_end ) Then ! EOF reached
        ifcb = 0
        Exit
      ElseIf ( ierr /= 0 ) Then ! Format Error
        Write(lun_stdout,*) 'Problem Finding Control Block ',trim(block_string)
      EndIf

      ! For lines begining with the block marker
      If ( test_marker == block_marker ) Then

        ! Search for the desired control block identifier string
        itest = index(test_read,block_string)

        ! If the string is found, exit loop, leaving file at desired location
        If ( itest > 0 ) Exit
      EndIf
    EndDo
    If ( ii >= line_limit .or. ifcb == 0 ) Then
      Write(lun_stdout,*) block_string,' not found!'
    EndIf

    Return
  End Subroutine find_controls_block

  Subroutine read_controls(data_dir)
    !-----------------------------------------------------------------------------------------------
    ! The control file contains the parameters which determine the actions of XNet.
    !-----------------------------------------------------------------------------------------------
    Use, Intrinsic :: iso_fortran_env, Only: iostat_end
    Use xnet_parallel, Only: parallel_bcast, parallel_IOProcessor
    Use xnet_util, Only: name_ordered, xnet_terminate
    Implicit None

    ! Output variables
    Character(80), Intent(out) :: data_dir ! Nuclear data directory

    ! Local variables
    Integer :: lun_control, i, ierr, izone, nzone_read

    ! Read Problem Description
    If ( parallel_IOProcessor() ) Then
      Open(newunit=lun_control, file='control', status='old')
      Call find_controls_block(lun_control,'Problem Description',ierr)
      Read(lun_control,"(a80)") (descript(i), i=1,3) ! text description of the problem.
    EndIf
    Call parallel_bcast(descript)

    ! Read Job Controls
    If ( parallel_IOProcessor() ) Then
      Call find_controls_block(lun_control,'Job Controls',ierr)
      Read(lun_control,*) szone        ! number of the zone with which to begin
      Read(lun_control,*) nzone        ! total # of zones
      Read(lun_control,*) iweak0       ! controls the treatment of weak reactions
      Read(lun_control,*) iscrn        ! controls the treatment of nuclear screening
      Read(lun_control,*) iprocess     ! controls the runtime pre-processing of the network data
    EndIf
    Call parallel_bcast(szone)
    Call parallel_bcast(nzone)
    Call parallel_bcast(iweak0)
    Call parallel_bcast(iscrn)

    ! Read Zone Batching Controls
    If ( parallel_IOProcessor() ) Then
      Call find_controls_block(lun_control,'Zone Batching Controls',ierr)
      If ( ierr /= 0 ) Then
        Read(lun_control,*) nzbatchmx  ! maximum number of zones in a batch
      Else
        Write(lun_stdout,*) 'Using Default Zone Batching behavior'
        nzbatchmx = 1
      EndIf
    EndIf
    Call parallel_bcast(nzbatchmx)
    nzevolve = nzbatchmx * nthread
    Allocate (zone_id(3,nzevolve))
    Allocate (lzactive(nzevolve))
    Allocate (iweak(nzevolve),lun_ev(nzevolve),lun_ts(nzevolve))
    Allocate (kmon(2,nzevolve),ktot(5,nzevolve))
    !$omp parallel default(shared)
    zb_offset = (mythread-1) * nzbatchmx
    zb_lo = zb_offset + 1
    zb_hi = zb_offset + nzbatchmx
    !$omp end parallel

    ! Read Integration Controls
    If ( parallel_IOProcessor() ) Then
      Call find_controls_block(lun_control,'Integration Controls',ierr)
      Read(lun_control,*) isolv        ! Choice of integrations scheme
      Read(lun_control,*) kstmx        ! max # of timesteps for each zone
      Read(lun_control,*) kitmx        ! max # of iterations before retry
      Read(lun_control,*) ijac         ! rebuild jacobian every ijac iterations after the first
      Read(lun_control,*) iconvc       ! determines which convergence condition is Used
      Read(lun_control,*) changemx     ! allowed abundance change used to set the timestep.
      Read(lun_control,*) yacc         ! abundances > yacc Used for timestep calculation
      Read(lun_control,*) tolm         ! mass conservation convergence criterion
      Read(lun_control,*) tolc         ! convergence limit on the iterative abundance change
      Read(lun_control,*) ymin         ! abundance < ymin is set to 0.0
      Read(lun_control,*) tdel_maxmult ! max factor by which the timestep is changed
    EndIf
    Call parallel_bcast(isolv)
    Call parallel_bcast(kstmx)
    Call parallel_bcast(kitmx)
    Call parallel_bcast(ijac)
    Call parallel_bcast(iconvc)
    Call parallel_bcast(changemx)
    Call parallel_bcast(yacc)
    Call parallel_bcast(tolm)
    Call parallel_bcast(tolc)
    Call parallel_bcast(ymin)
    Call parallel_bcast(tdel_maxmult)

    ! Read Self-heating Controls (off by default)
    If ( parallel_IOProcessor() ) Then
      Call find_controls_block(lun_control,'Self-heating Controls',ierr)
      If ( ierr /= 0 ) Then
        Read(lun_control,*) iheat      ! controls the coupling of the network to temperature
        Read(lun_control,*) changemxt  ! allowed temperature change used to set the timestep.
        Read(lun_control,*) tolt9      ! convergence limit on the iterative temperature change
      Else
        Write(lun_stdout,*) 'Using Default Self-heating behavior'
        iheat = 0
        changemxt = 1.0e-2
        tolt9 = 1.0e-4
      EndIf
    EndIf
    Call parallel_bcast(iheat)
    Call parallel_bcast(changemxt)
    Call parallel_bcast(tolt9)

    ! If using higher-order solver, XNet does not need to further limit the timestep size
    If ( isolv == 3 ) Then
      changemx = 1.0e+10
      changemxt = 1.0e+10
    EndIf

    ! Read NSE Initial Conditions Controls (t9nse = 8.0 by default)
    If ( parallel_IOProcessor() ) Then
      Call find_controls_block(lun_control,'NSE Initial Conditions',ierr)
      If ( ierr /= 0 ) Then
        Read(lun_control,*) t9nse
      Else
        Write(lun_stdout,*) 'Using Default NSE behavior'
        t9nse = 8.0
      EndIf
    EndIf
    Call parallel_bcast(t9nse)

    ! Read Neutrino Controls
    If ( parallel_IOProcessor() ) Then
      Call find_controls_block(lun_control,'Neutrinos',ierr)
      If ( ierr /= 0 ) Then
        Read(lun_control,*) ineutrino
      Else
        Write(lun_stdout,*) 'Using Default Neutrinos behavior'
        ineutrino = 0
      EndIf
    EndIf
    Call parallel_bcast(ineutrino)

    !-----------------------------------------------------------------------------------------------
    ! XNet output controls include the base of the filenames to which ASCII and binary output are
    ! written at the end of each timestep, and a subset of nuclei to be included in the per timestep
    ! ASCII output file.
    !-----------------------------------------------------------------------------------------------
    ! Read Output Controls
    If ( parallel_IOProcessor() ) Then
      Call find_controls_block(lun_control,'Output Controls',ierr)
      Read(lun_control,*) idiag        ! sets diagnostic output level
      Read(lun_control,*) itsout       ! sets per timestep output level
      Read(lun_control,*)
      Read(lun_control,"(a80)") ev_file_base
      Read(lun_control,*)
      Read(lun_control,"(a80)") bin_file_base
      Read(lun_control,"(50x,i4)") nnucout
    EndIf
    Call parallel_bcast(idiag)
    Call parallel_bcast(itsout)
    Call parallel_bcast(ev_file_base)
    Call parallel_bcast(bin_file_base)
    Call parallel_bcast(nnucout)
    Allocate(output_nuc(nnucout),inucout(nnucout))
    Write(nnucout_string,"(i4)") nnucout
    nnucout_string = adjustl(nnucout_string)
    If ( parallel_IOProcessor() ) Then
!     Read(lun_control,"("//nnucout_string//"a5)") output_nuc
      Read(lun_control,"(14a5)") output_nuc
      Write(lun_stdout,*) 'nnucout',nnucout
    EndIf
    Call parallel_bcast(output_nuc)

    !-----------------------------------------------------------------------------------------------
    ! XNet input controls include the relative directory from which the nuclear data should be
    ! loaded, as well as the names of the files containing the initial abundances and thermodynamic
    ! trajectories.
    !-----------------------------------------------------------------------------------------------
    ! Read Input Controls
    Allocate (inab_file(nzone),thermo_file(nzone))
    If ( parallel_IOProcessor() ) Then
      Call find_controls_block(lun_control,'Input Controls',ierr)
      Read(lun_control,*)
      Read(lun_control,"(a80)") data_dir
      Read(lun_control,*)
      nzone_read = nzone
    !-----------------------------------------------------------------------------------------------
    ! XNet generally expects individual files for the thermodynamic history and initial abundances
    ! for each zone
    !-----------------------------------------------------------------------------------------------
      Do izone = 1, nzone
        Read(lun_control,"(a80)",iostat=ierr) inab_file(izone)
        If ( ierr == iostat_end ) Then
          Exit
        ElseIf ( ierr /= 0 ) Then
          Write(lun_stdout,*) 'Problem reading Input Filenames'
        EndIf
        Read(lun_control,"(a80)",iostat=ierr) thermo_file(izone)
        If ( ierr == iostat_end ) Then
          Exit
        ElseIf ( ierr /= 0 ) Then
          Write(lun_stdout,*) 'Problem reading Input Filenames'
        EndIf
      EndDo
      Close(lun_control)
      nzone_read = izone - 1
    !-----------------------------------------------------------------------------------------------
    ! If the number of thermodynamic history and initial abundances is less than one per zone...
    !-----------------------------------------------------------------------------------------------
      If (index(thermo_file(1),'.h5')>0 .or. index(thermo_file(1),'.hdf')>0 ) Then
        Write(lun_stdout,"(a,i4,a)") 'Read ', nzone_read, ' HDF files.'
      ElseIf ( nzone_read == 1 .and. nzone_read < nzone ) Then
        inab_file_base = inab_file(1)
        thermo_file_base = thermo_file(1)
        Do izone = 1, nzone
          thermo_file(izone) = trim(thermo_file_base)
          Call name_ordered(thermo_file(izone),izone,nzone)
          inab_file(izone) = trim(inab_file_base)
          Call name_ordered(inab_file(izone),izone,nzone)
        EndDo
      ElseIf ( nzone_read /= nzone ) Then
        Write(lun_stdout,*) 'Number of datafiles does not match number of zones!'
!       Call xnet_terminate('Number of datafiles does not match number of zones!')
      Else
        inab_file_base = ''
        thermo_file_base = ''
      EndIf
    EndIf
    Call parallel_bcast(data_dir)
    Call parallel_bcast(inab_file)
    Call parallel_bcast(thermo_file)

    Return
  End Subroutine read_controls

End Module xnet_controls