mjdgges and block_trust_region MEX: optimise by marking some function arguments as contiguous

This avoids unnecessary array copies before calling BLAS/LAPACK functions.
time-shift
Sébastien Villemot 2021-06-03 19:00:09 +02:00
parent 3a2335975a
commit dc2695a11f
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
2 changed files with 11 additions and 6 deletions

View File

@ -2,7 +2,7 @@
!
! Implementation heavily inspired from the hybrj function from MINPACK
! Copyright © 2019 Dynare Team
! Copyright © 2019-2021 Dynare Team
!
! This file is part of Dynare.
!
@ -223,11 +223,14 @@ contains
! designates element-by-element multiplication),
! x is a convex combination of the Gauss-Newton and scaled gradient
subroutine dogleg(r, b, d, delta, x, gn, recompute_gn)
real(real64), dimension(:), intent(in) :: b, d
real(real64), dimension(:,:), intent(in) :: r
! The arrays used in BLAS/LAPACK calls are required to be contiguous, to
! avoid temporary copies before calling BLAS/LAPACK.
real(real64), dimension(:), contiguous, intent(in) :: b
real(real64), dimension(:), intent(in) :: d
real(real64), dimension(:,:), contiguous, intent(in) :: r
real(real64), intent(in) :: delta ! Radius of the trust region
real(real64), dimension(:), intent(out) :: x ! Solution of the problem
real(real64), dimension(:), intent(inout) :: gn ! Gauss-Newton direction
real(real64), dimension(:), contiguous, intent(inout) :: gn ! Gauss-Newton direction
logical, intent(in) :: recompute_gn ! Whether to re-compute Gauss-Newton direction
integer(blint) :: n

View File

@ -18,7 +18,7 @@
! eigval [complex] (n×1) vector of generalized eigenvalues
! info [integer] scalar, error code of dgges (or 30 if eigenvalue close to 0÷0)
! Copyright © 2006-2020 Dynare Team
! Copyright © 2006-2021 Dynare Team
!
! This file is part of Dynare.
!
@ -69,7 +69,9 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
integer(blint) :: n_bl, lwork, info_bl, sdim_bl
real(real64), dimension(:), allocatable :: alpha_r, alpha_i, beta, work
logical(bllog), dimension(:), allocatable :: bwork
real(real64), dimension(:), pointer :: s, t, z, info, sdim, vsl
! The pointers used in the LAPACK call are marked as contiguous, to
! avoid temporary copies beforehand.
real(real64), dimension(:), pointer, contiguous :: s, t, z, info, sdim, vsl
#if MX_HAS_INTERLEAVED_COMPLEX
complex(real64), dimension(:), pointer :: gev
#else