I’m working on a scientific computation project in Fortran that uses Intel’s Math Kernel Library (MKL), managed through a Conda environment. I’m encountering issues with the DLAMCH function from LAPACK and with MKL module files.
Environment:
- OS: Ubuntu (latest LTS)
- Compiler: gfortran (version 14.1.0)
- MKL version: 2024.2.0 (intel_663 build)
- Conda environment
Initially, I was getting this error:
Error: Function 'dlamch' at (1) has no IMPLICIT type
To address this, I added an explicit interface for DLAMCH in my module:
module m_model
use iso_fortran_env, only: int64, real64, character_storage_size, int8, int32
use iso_c_binding
use m_myio
use m_myxyz
use mkl_service
use mkl_spblas
use mkl_solvers_ee
implicit none
interface
function dlamch(cmach) bind(C, name='dlamch_')
use, intrinsic :: iso_c_binding
implicit none
character(1), value :: cmach
real(c_double) :: dlamch
end function dlamch
end interface
! ... rest of the module ...
end module m_model
However, after adding this interface, I’m now encountering new errors during the linking stage:
f951: Warning: Nonexistent include directory '/include' [-Wmissing-include-dirs]
gfortran: error: ./obj/mkl_service.mod: Modula-2 compiler not installed on this system
gfortran: error: ./obj/mkl_spblas.mod: Modula-2 compiler not installed on this system
gfortran: error: ./obj/mkl_solvers_ee.mod: Modula-2 compiler not installed on this system
make: *** [makefile:36: main.exe] Error 1
My questions are:
- Why is gfortran treating the .mod files as Modula-2 files instead of Fortran module files?
- How can I properly link against the MKL modules in this Conda-managed environment?
- Is the DLAMCH interface correct, and if so, why am I still having issues with the MKL modules?
- Are there any special considerations when using MKL in a Conda environment that I’m missing?
Here are the relevant parts of my makefile:
FORT = gfortran
FLAGS = -fdefault-integer-8 -O3 -m64 -Wl,--no-as-needed -Wunused -std=gnu
INCLUDE = -I$(obj) -I$(MKLROOT)/include -I$(CONDA_PREFIX)/include
LIBS = -L$(MKLROOT)/lib/intel64 -lmkl_gf_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
MKL_MODULES = mkl_service.mod mkl_spblas.mod mkl_solvers_ee.mod
${EXE} : ${obj} $(addprefix ${obj}/, $(MKL_MODULES)) main.o myio.o myxyz.o model.o
$(CONDA_ACTIVATE) $(CONDA_ENV) && source $(SETUP_SCRIPT) &&
${FORT} $(addprefix ${obj}/,$(^F)) -o $@ ${FLAGS} ${INCLUDE} ${LIBS}