Skip to content

Commit

Permalink
add explict interfaces to blas; change to pure when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMVale committed Aug 1, 2024
1 parent c01da77 commit 82f6c04
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 95 deletions.
4 changes: 2 additions & 2 deletions c/odrpack_capi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ pure subroutine diwinf_c(m, np, nq, iworkidx) bind(C)

end subroutine diwinf_c

subroutine dwinf_c(n, m, np, nq, ldwe, ld2we, isodr, workidx) bind(C)
pure subroutine dwinf_c(n, m, np, nq, ldwe, ld2we, isodr, workidx) bind(C)
!! Get storage locations within real work space.
integer(c_int), intent(in) :: n
!! Number of observations.
Expand Down Expand Up @@ -562,7 +562,7 @@ subroutine dwinf_c(n, m, np, nq, ldwe, ld2we, isodr, workidx) bind(C)

end subroutine dwinf_c

subroutine workspace_dimensions_c(n, m, np, nq, isodr, lwork, liwork) bind(C)
pure subroutine workspace_dimensions_c(n, m, np, nq, isodr, lwork, liwork) bind(C)
!! Calculate the dimensions of the workspace arrays.
integer(c_int), intent(in) :: n
!! Number of observations.
Expand Down
190 changes: 190 additions & 0 deletions src/blas_interfaces.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
module blas_interfaces
!! Single and double precision interfaces for the BLAS procedures used by odrpack.
use odrpack_kinds, only: sp, dp
implicit none

interface

pure real(sp) function sasum(n, x, incx)
import :: sp
integer, intent(in) :: n
real(sp), intent(in) :: x(*)
integer, intent(in) :: incx
end function sasum

pure real(dp) function dasum(n, x, incx)
!! Takes the sum of the absolute values.
import :: dp
integer, intent(in) :: n
real(dp), intent(in) :: x(*)
integer, intent(in) :: incx
end function dasum

pure subroutine saxpy(n, a, x, incx, y, incy)
import :: sp
integer, intent(in) :: n
real(sp), intent(in) :: a
real(sp), intent(in) :: x(*)
integer, intent(in) :: incx
real(sp), intent(inout) :: y(*)
integer, intent(in) :: incy
end subroutine saxpy

pure subroutine daxpy(n, a, x, incx, y, incy)
!! Constant times a vector plus a vector.
import :: dp
integer, intent(in) :: n
real(dp), intent(in) :: a
real(dp), intent(in) :: x(*)
integer, intent(in) :: incx
real(dp), intent(inout) :: y(*)
integer, intent(in) :: incy
end subroutine daxpy

pure subroutine scopy(n, x, incx, y, incy)
import :: sp
integer, intent(in) :: n
real(sp), intent(in) :: x(*)
integer, intent(in) :: incx
real(sp), intent(inout) :: y(*)
integer, intent(in) :: incy
end subroutine scopy

pure subroutine dcopy(n, x, incx, y, incy)
!! Copies a vector, x, to a vector, y.
import :: dp
integer, intent(in) :: n
real(dp), intent(in) :: x(*)
integer, intent(in) :: incx
real(dp), intent(inout) :: y(*)
integer, intent(in) :: incy
end subroutine dcopy

pure real(sp) function sdot(n, x, incx, y, incy)
import :: sp
integer, intent(in) :: n
real(sp), intent(in) :: x(*)
integer, intent(in) :: incx
real(sp), intent(in) :: y(*)
integer, intent(in) :: incy
end function sdot

pure real(dp) function ddot(n, x, incx, y, incy)
!! Forms the dot product of two vectors.
import :: dp
integer, intent(in) :: n
real(dp), intent(in) :: x(*)
integer, intent(in) :: incx
real(dp), intent(in) :: y(*)
integer, intent(in) :: incy
end function ddot

pure real(sp) function snrm2(n, x, incx)
import :: sp
integer, intent(in) :: n
real(sp), intent(in) :: x(*)
integer, intent(in) :: incx
end function snrm2

pure real(dp) function dnrm2(n, x, incx)
!! Euclidean norm of a vector.
import :: dp
integer, intent(in) :: n
real(dp), intent(in) :: x(*)
integer, intent(in) :: incx
end function dnrm2

pure subroutine srot(n, x, incx, y, incy, c, s)
import :: sp
integer, intent(in) :: n
real(sp), intent(inout) :: x(*)
integer, intent(in) :: incx
real(sp), intent(inout) :: y(*)
integer, intent(in) :: incy
real(sp), intent(in) :: c
real(sp), intent(in) :: s
end subroutine srot

pure subroutine drot(n, x, incx, y, incy, c, s)
!! Applies a plane rotation.
import :: dp
integer, parameter :: wp = dp
integer, intent(in) :: n
real(dp), intent(inout) :: x(*)
integer, intent(in) :: incx
real(dp), intent(inout) :: y(*)
integer, intent(in) :: incy
real(dp), intent(in) :: c
real(dp), intent(in) :: s
end subroutine drot

pure subroutine srotg(a, b, c, s)
import :: sp
real(sp), intent(in) :: a
real(sp), intent(in) :: b
real(sp), intent(out) :: c
real(sp), intent(out) :: s
end subroutine srotg

pure subroutine drotg(a, b, c, s)
import :: dp
real(dp), intent(in) :: a
real(dp), intent(in) :: b
real(dp), intent(out) :: c
real(dp), intent(out) :: s
end subroutine drotg

pure subroutine sscal(n, a, x, incx)
import :: sp
integer, intent(in) :: n
real(sp), intent(in) :: a
real(sp), intent(inout) :: x(*)
integer, intent(in) :: incx
end subroutine sscal

pure subroutine dscal(n, a, x, incx)
!! Scales a vector by a constant.
import :: dp
integer, intent(in) :: n
real(dp), intent(in) :: a
real(dp), intent(inout) :: x(*)
integer, intent(in) :: incx
end subroutine dscal

pure subroutine sswap(n, x, incx, y, incy)
import :: sp
integer, intent(in) :: n
real(sp), intent(in) :: x(*)
integer, intent(in) :: incx
real(sp), intent(inout) :: y(*)
integer, intent(in) :: incy
end subroutine sswap

pure subroutine dswap(n, x, incx, y, incy)
!! Interchanges two vectors.
import :: dp
integer, intent(in) :: n
real(dp), intent(in) :: x(*)
integer, intent(in) :: incx
real(dp), intent(inout) :: y(*)
integer, intent(in) :: incy
end subroutine dswap

pure integer function isamax(n, x, incx)
import :: sp
integer, intent(in) :: n
real(sp), intent(in) :: x(*)
integer, intent(in) :: incx
end function isamax

pure integer function idamax(n, x, incx)
!! Finds the index of the first element having maximum absolute value.
import :: dp
integer, intent(in) :: n
real(dp), intent(in) :: x(*)
integer, intent(in) :: incx
end function idamax

end interface

end module blas_interfaces
56 changes: 12 additions & 44 deletions src/linpack.f
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MODULE LINPACK
C
CONTAINS
*DCHEX
SUBROUTINE DCHEX(R,LDR,P,K,L,Z,LDZ,NZ,C,S,JOB)
PURE SUBROUTINE DCHEX(R,LDR,P,K,L,Z,LDZ,NZ,C,S,JOB)
C***Begin Prologue DCHEX
C***Date Written 780814 (YYMMDD)
C***Revision Date 820801 (YYMMDD)
Expand Down Expand Up @@ -95,6 +95,7 @@ SUBROUTINE DCHEX(R,LDR,P,K,L,Z,LDZ,NZ,C,S,JOB)

C...Used modules
use odrpack_kinds, only: wp
use blas_interfaces, only: drotg

C...Scalar arguments
INTEGER, INTENT(IN) :: JOB
Expand All @@ -117,10 +118,6 @@ SUBROUTINE DCHEX(R,LDR,P,K,L,Z,LDZ,NZ,C,S,JOB)
INTEGER
& I,II,IL,IU,J,JJ,KM1,KP1,LM1,LMK

C...External subroutines
EXTERNAL
& DROTG

C...Intrinsic functions
INTRINSIC
& MAX0,MIN0
Expand Down Expand Up @@ -263,7 +260,7 @@ SUBROUTINE DCHEX(R,LDR,P,K,L,Z,LDZ,NZ,C,S,JOB)
RETURN
END
*DPODI
SUBROUTINE DPODI(A,LDA,N,DET,JOB)
PURE SUBROUTINE DPODI(A,LDA,N,DET,JOB)
C***Begin Prologue DPODI
C***Date Written 780814 (YYMMDD)
C***Revision Date 820801 (YYMMDD)
Expand Down Expand Up @@ -318,6 +315,7 @@ SUBROUTINE DPODI(A,LDA,N,DET,JOB)

C...Used modules
use odrpack_kinds, only: wp
use blas_interfaces, only: daxpy, dscal

C...Scalar arguments
INTEGER, INTENT(IN) :: JOB
Expand All @@ -332,9 +330,6 @@ SUBROUTINE DPODI(A,LDA,N,DET,JOB)
REAL(wp) S,T
INTEGER I,J,JM1,K,KP1

C...External subroutines
EXTERNAL DAXPY,DSCAL

C...Intrinsic functions
INTRINSIC MOD

Expand Down Expand Up @@ -398,7 +393,7 @@ SUBROUTINE DPODI(A,LDA,N,DET,JOB)
RETURN
END
*DQRDC
SUBROUTINE DQRDC(X,LDX,N,P,QRAUX,JPVT,WORK,JOB)
PURE SUBROUTINE DQRDC(X,LDX,N,P,QRAUX,JPVT,WORK,JOB)
C***Begin Prologue DQRDC
C***Date Written 780814 (YYMMDD)
C***Revision Date 820801 (YYMMDD)
Expand Down Expand Up @@ -472,6 +467,7 @@ SUBROUTINE DQRDC(X,LDX,N,P,QRAUX,JPVT,WORK,JOB)

C...Used modules
use odrpack_kinds, only: wp
use blas_interfaces, only: ddot, dnrm2, daxpy, dscal, dswap

C...Scalar arguments
INTEGER, INTENT(IN) :: JOB
Expand All @@ -493,16 +489,6 @@ SUBROUTINE DQRDC(X,LDX,N,P,QRAUX,JPVT,WORK,JOB)
LOGICAL
& NEGJ,SWAPJ

C...External functions
REAL(wp)
& DDOT,DNRM2
EXTERNAL
& DDOT,DNRM2

C...External subroutines
EXTERNAL
& DAXPY,DSCAL,DSWAP

C...Intrinsic functions
INTRINSIC
& DABS,DMAX1,DSIGN,DSQRT,MIN0
Expand Down Expand Up @@ -627,7 +613,7 @@ SUBROUTINE DQRDC(X,LDX,N,P,QRAUX,JPVT,WORK,JOB)
RETURN
END
*DQRSL
SUBROUTINE DQRSL(X,LDX,N,K,QRAUX,Y,QY,QTY,B,RSD,XB,JOB,INFO)
PURE SUBROUTINE DQRSL(X,LDX,N,K,QRAUX,Y,QY,QTY,B,RSD,XB,JOB,INFO)
C***Begin Prologue DQRSL
C***Date Written 780814 (YYMMDD)
C***Revision Date 820801 (YYMMDD)
Expand Down Expand Up @@ -743,6 +729,7 @@ SUBROUTINE DQRSL(X,LDX,N,K,QRAUX,Y,QY,QTY,B,RSD,XB,JOB,INFO)

C...Used modules
use odrpack_kinds, only: wp
use blas_interfaces, only: ddot, daxpy, dcopy

C...Scalar arguments
INTEGER, INTENT(OUT) :: INFO
Expand All @@ -769,13 +756,6 @@ SUBROUTINE DQRSL(X,LDX,N,K,QRAUX,Y,QY,QTY,B,RSD,XB,JOB,INFO)
LOGICAL
& CB,CQTY,CQY,CR,CXB

C...External functions
REAL(wp), EXTERNAL :: DDOT

C...External subroutines
EXTERNAL
& DAXPY,DCOPY

C...Intrinsic functions
INTRINSIC
& MIN0,MOD
Expand Down Expand Up @@ -907,7 +887,7 @@ SUBROUTINE DQRSL(X,LDX,N,K,QRAUX,Y,QY,QTY,B,RSD,XB,JOB,INFO)
RETURN
END
*DTRCO
SUBROUTINE DTRCO(T,LDT,N,RCOND,Z,JOB)
PURE SUBROUTINE DTRCO(T,LDT,N,RCOND,Z,JOB)
C***Begin Prologue DTRCO
C***Date Written 780814 (YYMMDD)
C***Revision Date 820801 (YYMMDD)
Expand Down Expand Up @@ -959,6 +939,7 @@ SUBROUTINE DTRCO(T,LDT,N,RCOND,Z,JOB)

C...Used modules
use odrpack_kinds, only: wp
use blas_interfaces, only: dasum, daxpy, dscal

C...Scalar arguments
REAL(wp), INTENT(OUT) :: RCOND
Expand All @@ -978,13 +959,6 @@ SUBROUTINE DTRCO(T,LDT,N,RCOND,Z,JOB)
LOGICAL
& LOWER

C...External functions
REAL(wp), EXTERNAL :: DASUM

C...External subroutines
EXTERNAL
& DAXPY,DSCAL

C...Intrinsic functions
INTRINSIC
& DABS,DMAX1,DSIGN
Expand Down Expand Up @@ -1094,7 +1068,7 @@ SUBROUTINE DTRCO(T,LDT,N,RCOND,Z,JOB)
RETURN
END
*DTRSL
SUBROUTINE DTRSL(T,LDT,N,B,JOB,INFO)
PURE SUBROUTINE DTRSL(T,LDT,N,B,JOB,INFO)
C***Begin Prologue DTRSL
C***Date Written 780814 (YYMMDD)
C***Revision Date 820801 (YYMMDD)
Expand Down Expand Up @@ -1146,6 +1120,7 @@ SUBROUTINE DTRSL(T,LDT,N,B,JOB,INFO)

C...Used modules
use odrpack_kinds, only: wp
use blas_interfaces, only: ddot, daxpy

C...Scalar arguments
INTEGER, INTENT(OUT) :: INFO
Expand All @@ -1163,13 +1138,6 @@ SUBROUTINE DTRSL(T,LDT,N,B,JOB,INFO)
INTEGER
& CASE,J,JJ

C...External functions
REAL(wp), EXTERNAL :: DDOT

C...External subroutines
EXTERNAL
& DAXPY

C...Intrinsic functions
INTRINSIC
& MOD
Expand Down
Loading

0 comments on commit 82f6c04

Please sign in to comment.