From dffab8492e33a83ff588cac104e5e8669ac50129 Mon Sep 17 00:00:00 2001 From: Jacob Williams Date: Sun, 7 Jan 2024 15:25:00 -0600 Subject: [PATCH] allow for using the HAS_BLAS compiler directive to use an external BLAS --- README.md | 22 ++++++-- src/{slsqp_support.f90 => slsqp_support.F90} | 58 ++++++++++++++++++++ 2 files changed, 74 insertions(+), 6 deletions(-) rename src/{slsqp_support.f90 => slsqp_support.F90} (80%) diff --git a/README.md b/README.md index ced5953..49df2d9 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,6 @@ Updates to the original code include: * The documentation strings in the code have been converted to [FORD](https://github.com/Fortran-FOSS-Programmers/ford) format, allowing for [nicely formatted documentation](https://jacobwilliams.github.io/slsqp/) to be auto-generated. * A couple of bug fixes noted elsewhere have been applied. -### License - - * The original sourcecode and the modifications are released under a [permissive BSD-style license](https://github.com/jacobwilliams/slsqp/blob/master/LICENSE). - ### Building SLSQP #### **Fortran Package Manager** @@ -69,14 +65,28 @@ or, to use a specific version: slsqp = { git="https://github.com/jacobwilliams/slsqp.git", tag = "1.3.0" } ``` -### Development +## Dependencies - * Development continues on [GitHub](https://github.com/jacobwilliams/slsqp). +The library requires some [BLAS](https://netlib.org/blas/) routines, which are included. However, the user may also choose to link to an external BLAS library. This can be done by using the `HAS_BLAS` compiler directive. For example: + +``` +fpm build --compiler gfortran --flag "-DHAS_BLAS -lblas" +``` + +However, note that an external BLAS can only be used if the library is compiled with double precision (`real64`) reals. ### Documentation The latest API documentation can be found [here](https://jacobwilliams.github.io/slsqp/). This was generated from the source code using [FORD](https://github.com/Fortran-FOSS-Programmers/ford). +### License + + * The original sourcecode and the modifications are released under a [permissive BSD-style license](https://github.com/jacobwilliams/slsqp/blob/master/LICENSE). + +### Development + + * Development continues on [GitHub](https://github.com/jacobwilliams/slsqp). + ### References * [Original sourcecode at NETLIB](http://www.netlib.org/toms/733) diff --git a/src/slsqp_support.f90 b/src/slsqp_support.F90 similarity index 80% rename from src/slsqp_support.f90 rename to src/slsqp_support.F90 index db91435..5f4aadc 100644 --- a/src/slsqp_support.f90 +++ b/src/slsqp_support.F90 @@ -23,6 +23,62 @@ module slsqp_support public :: daxpy,dcopy,ddot,dnrm2,dscal +#ifdef HAS_BLAS + + ! linking with an external BLAS library. + ! Define the interfaces here. Note that this + ! will only work if the `wp` is the same kind + ! as used in the BLAS library. + + interface + pure subroutine daxpy(n,da,dx,incx,dy,incy) + import :: wp + implicit none + integer,intent(in) :: n + real(wp),intent(in) :: da + real(wp),dimension(*),intent(in) :: dx + integer,intent(in) :: incx + real(wp),dimension(*),intent(inout) :: dy + integer,intent(in) :: incy + end subroutine daxpy + pure subroutine dcopy(n,dx,incx,dy,incy) + import :: wp + implicit none + integer,intent(in) :: n + real(wp),dimension(*),intent(in) :: dx + integer,intent(in) :: incx + real(wp),dimension(*),intent(out) :: dy + integer,intent(in) :: incy + end subroutine dcopy + pure real(wp) function ddot(n,dx,incx,dy,incy) + import :: wp + implicit none + integer,intent(in) :: n + real(wp),dimension(*),intent(in) :: dx + integer,intent(in) :: incx + real(wp),dimension(*),intent(in) :: dy + integer,intent(in) :: incy + end function ddot + pure function dnrm2(n,x,incx) result(norm) + import :: wp + implicit none + integer,intent(in) :: incx + integer,intent(in) :: n + real(wp),dimension(*),intent(in) :: x + real(wp) :: norm + end function dnrm2 + pure subroutine dscal(n,da,dx,incx) + import :: wp + implicit none + integer,intent(in) :: n + real(wp),intent(in) :: da + real(wp),dimension(*),intent(inout) :: dx + integer,intent(in) :: incx + end subroutine dscal + end interface + +#else + contains !******************************************************************************* @@ -333,6 +389,8 @@ pure subroutine dscal(n,da,dx,incx) end subroutine dscal !******************************************************************************* +#endif + !******************************************************************************* end module slsqp_support !*******************************************************************************