Does gfortran (gcc-9) automatically parallelize the matmul() intrinsic function if compiled with -fopenmp (and run whith OMP_NUM_THREADS > 1 in Linux)? If so, is there a way to turn it off?

There is no -fextrnal-blas flag applied to call a parallel BLAS for the matmuls.


Solution 1:

You can easily see for yourself in the code of GCC:

https://github.com/gcc-mirror/gcc/blob/master/libgfortran/generated/matmul_r4.c

Many Fortran intrinsic calls are actually implemented as external functions provided by the library libgfortran, and matmul is not an exception. There is a separate C code of matmul for all basic numerical types (and their kinds), and also alternative forms for various target vector instructions sets (AVX, FMA, etc). But none of them apparently uses any OpenMP directives.