# Compiler option matmul speedup

**URL:** <https://fortran-lang.discourse.group/t/compiler-option-matmul-speedup/6518>\
**Category:** Uncategorized\
**Created:** [September 15, 2023, 4:00pm UTC](https://fortran-lang.discourse.group/t/compiler-option-matmul-speedup/6518 "2023-09-15T16:00:07Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [September 15, 2023, 10:16pm UTC](https://fortran-lang.discourse.group/t/compiler-option-matmul-speedup/6518/8 "2023-09-15T22:16:16Z")

</div>

With **gfortran** you can use the [`-fexternal-blas`](https://gcc.gnu.org/onlinedocs/gfortran/Code-Gen-Options.html#index-fexternal-blas) compiler flag, which inserts calls to BLAS in place of the intrinsic `matmul` function above a certain matrix size. In addition you have to link an optimized BLAS library:

| Library | Link flags | Comment |
| --- | --- | --- |
| [OpenBLAS](https://github.com/xianyi/OpenBLAS) | `-lopenblas` | |
| [BLIS](https://github.com/flame/blis) | `-lblis` | |
| [Intel oneMKL](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-fortran/2023-2/blas-and-sparse-blas-routines.html) | see [Link Line Advisor for OneMKL](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html#gs.57febj) | for Intel processors |
| [Accelerate](https://developer.apple.com/documentation/accelerate?language=objc) | `-framework Accelerate` | for macOS |
| [AOCL-BLAS](https://www.amd.com/en/developer/aocl/dense.html) | `-lblis` | for AMD processors; derived from BLIS |
| [Arm Performance Libraries](https://developer.arm.com/downloads/-/arm-performance-libraries/get-started-with-armpl-free-version/single-page) | `-larmpl_lp64` | for Arm processors |
| [MATLAB BLAS](https://www.mathworks.com/help/matlab/matlab_external/calling-lapack-and-blas-functions-from-mex-files.html) | `-lmwblas` | for MATLAB MEX functions |

---

_[View the full topic](https://fortran-lang.discourse.group/t/compiler-option-matmul-speedup/6518)._
