Using the Fortran 90 wrappers for Accelerate BLAS and LAPACK
Call BLAS and LAPACK routines from Fortran 90 source code.
Overview
Accelerate ships a set of Fortran 90 interface modules that bind Fortran source to the ACCELERATE_NEW_LAPACK symbols in the Accelerate framework. The modules declare every BLAS and LAPACK routine with explicit Fortran interfaces, so the compiler can check argument types and shapes at the call site. You don’t link a separate library — the interface module compiles alongside your program and resolves directly to Accelerate.
Four interface modules ship with the SDK:
Module file | API | Integer width |
|---|---|---|
| BLAS | LP64 — default |
| BLAS | ILP64 — |
| LAPACK | LP64 — default |
| LAPACK | ILP64 — |
Use the LP64 modules with code that relies on Fortran’s default 4-byte integer. Use the ILP64 modules when you need 8-byte integers — for example, problems whose leading dimensions or array indices don’t fit in a 32-bit signed integer. The LP64 modules bind to the $NEWLAPACK symbol suffix; the ILP64 modules bind to the $NEWLAPACK$ILP64 suffix.
Adopt a wrapper module in your source
Add a use statement for the module that matches the API and integer width you need, then call the routine directly. The example below calls dgemm from the ILP64 BLAS wrapper:
use accelerate_blas_ilp64
integer(8) :: m, n, k, lda, ldb, ldc
! declare alpha, beta, and arrays a, b, c with matching kinds
call dgemm('N', 'N', m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)LAPACK routines that take a callback, such as the SELECT argument to SGEES, DGEES, CGEES, or ZGEES, expect a type(c_funptr) value. Use c_funloc from iso_c_binding to obtain a function pointer from a Fortran procedure.
Compile and link against Accelerate
Pass the interface module’s source file on the gfortran command line ahead of your own source. The command below compiles example_program.f90 against the ILP64 BLAS wrappers and links the resulting binary to the Accelerate framework:
gfortran -o example_program \
$(xcrun -sdk macosx --show-sdk-path)/usr/include/accelerate_blas_ilp64.f90 \
example_program.f90 \
-F$(xcrun -sdk macosx --show-sdk-path)/System/Library/Frameworks \
-framework Accelerate \
-L$(xcrun -sdk macosx --show-sdk-path)/usr/libEach argument plays a specific role:
-o example_programnames the output binary.$(xcrun -sdk macosx --show-sdk-path)/usr/include/accelerate_blas_ilp64.f90is the interface module to compile. Substitute one ofaccelerate_blas_lp64.f90,accelerate_lapack_lp64.f90, oraccelerate_lapack_ilp64.f90to select a different API or integer width. If your program uses both BLAS and LAPACK, pass both interface files.example_program.f90is your Fortran source. It must appear after the interface module so the compiler resolves theusestatement by the time it reaches your code.-F$(xcrun -sdk macosx --show-sdk-path)/System/Library/Frameworks -framework Acceleratepoints the linker at the Accelerate framework in the selected SDK and links it.-L$(xcrun -sdk macosx --show-sdk-path)/usr/libadds the SDK’s library directory to the link search path for any standard librariesgfortranneeds.
The xcrun -sdk macosx --show-sdk-path invocation expands to the active macOS SDK on the build machine, so the same command line works across Xcode versions without hard-coded paths.