Linking MKL with pgfortran

Hello,

I’m trying to work one of the example files in MKL, namely pardiso_sym_f90.f90. I obtained a c makefile from someone else, modified it for Intel fortran compiler. I am able to get this code working with that. To use the pgi compiler, I only changed the ifort command to pgfortran. The current makefile I’m using is:

#-------------------------------------------------------------------#
#Define executable
#-------------------------------------------------------------------#
EXEC := exp


#-------------------------------------------------------------------#
#Define constant
#-------------------------------------------------------------------#
RM := rm -f

#-------------------------------------------------------------------#
#Define directories
#-------------------------------------------------------------------#
SRCDIR := ./
HDRDIR := 
SRCEXT := f90


#-------------------------------------------------------------------#
#Define directories    for object and dependency files
#-------------------------------------------------------------------#
OBJDIR := .o

DEPDIR = .d


#-------------------------------------------------------------------#
#Generate source files list
#-------------------------------------------------------------------#
SRCS := $(wildcard $(SRCDIR)/*.$(SRCEXT))


#-------------------------------------------------------------------#
#Generate object and dependency files
#-------------------------------------------------------------------#
OBJS := $(patsubst %,$(OBJDIR)/%.o,$(basename $(SRCS)))

DEPS := $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))

$(shell mkdir -p $(dir $(OBJS)) >/dev/null)

$(shell mkdir -p $(dir $(DEPS)) >/dev/null)


#-------------------------------------------------------------------#
#Define compiler and library flags
#-------------------------------------------------------------------#
FC := pgfortran	

LD := pgfortran

FFLAGS := -warn all -O2 -i8 -I${MKLROOT}/include

LDFLAGS := -L${MKLROOT}/lib/intel64

LDLIBS = -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl

#-------------------------------------------------------------------#
#Define dependencies
#-------------------------------------------------------------------#
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td


#-------------------------------------------------------------------#
#Define compiling and linking commands
#-------------------------------------------------------------------#
COMPILE.f90 = $(FC) $(DEPFLAGS) $(FFLAGS) $(TARGET_ARCH) -c -o $@

LINK.o = $(LD) $(LDFLAGS) $(TARGET_ARCH) -o $@

POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d


#-------------------------------------------------------------------#
#Define rules
#-------------------------------------------------------------------#

all: $(EXEC)

.PHONY: clean
clean:
	$(RM) -r $(OBJDIR) $(DEPDIR)

.PHONY: distclean
distclean: clean
	$(RM) $(EXEC)


$(EXEC): $(OBJS)
	#$(LD) $(LDFLAGS) $(TARGET_ARCH) -o $@ $^ $(LDLIBS)
	$(LINK.o) $^ $(LDLIBS)

$(OBJDIR)/%.o: %.f90
$(OBJDIR)/%.o: %.f90 $(DEPDIR)/%.d
	$(COMPILE.f90) $<
	$(POSTCOMPILE)


.PRECIOUS: $(DEPDIR)/%.d
$(DEPDIR)/%.d: ;

-include $(DEPS)

The error I get:

pgfortran -MT .o/.//pardiso_sym_f90.o -MMD -MP -MF .d/.//pardiso_sym_f90.Td -warn all -O2 -i8 -I/home/kaan/intel/compilers_and_libraries_2019.3.199/linux/mkl/include -c -o .o/.//pardiso_sym_f90.o pardiso_sym_f90.f90
pgfortran-Error-Unknown switch: -MT
pgfortran-Error-Unknown switch: -MMD
pgfortran-Error-Unknown switch: -MP
pgfortran-Error-Unknown switch: -MF
pgfortran-Error-Unknown switch: -warn
Makefile:97: recipe for target ‘.o/.//pardiso_sym_f90.o’ failed
make: *** [.o/.//pardiso_sym_f90.o] Error 1

When I close the unknown switches; makefile becomes:

#-------------------------------------------------------------------#
#Define executable
#-------------------------------------------------------------------#
EXEC := exp


#-------------------------------------------------------------------#
#Define constant
#-------------------------------------------------------------------#
RM := rm -f

#-------------------------------------------------------------------#
#Define directories
#-------------------------------------------------------------------#
SRCDIR := ./
HDRDIR := 
SRCEXT := f90


#-------------------------------------------------------------------#
#Define directories    for object and dependency files
#-------------------------------------------------------------------#
OBJDIR := .o

DEPDIR = .d


#-------------------------------------------------------------------#
#Generate source files list
#-------------------------------------------------------------------#
SRCS := $(wildcard $(SRCDIR)/*.$(SRCEXT))


#-------------------------------------------------------------------#
#Generate object and dependency files
#-------------------------------------------------------------------#
OBJS := $(patsubst %,$(OBJDIR)/%.o,$(basename $(SRCS)))

DEPS := $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))

$(shell mkdir -p $(dir $(OBJS)) >/dev/null)

$(shell mkdir -p $(dir $(DEPS)) >/dev/null)


#-------------------------------------------------------------------#
#Define compiler and library flags
#-------------------------------------------------------------------#
FC := pgfortran	

LD := pgfortran

#FFLAGS := -warn all -O2 -i8 -I${MKLROOT}/include

LDFLAGS := -L${MKLROOT}/lib/intel64

LDLIBS = -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl

#-------------------------------------------------------------------#
#Define dependencies
#-------------------------------------------------------------------#
#DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td


#-------------------------------------------------------------------#
#Define compiling and linking commands
#-------------------------------------------------------------------#
COMPILE.f90 = $(FC) $(DEPFLAGS) $(FFLAGS) $(TARGET_ARCH) -c -o $@

LINK.o = $(LD) $(LDFLAGS) $(TARGET_ARCH) -o $@

POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d


#-------------------------------------------------------------------#
#Define rules
#-------------------------------------------------------------------#

all: $(EXEC)

.PHONY: clean
clean:
	$(RM) -r $(OBJDIR) $(DEPDIR)

.PHONY: distclean
distclean: clean
	$(RM) $(EXEC)


$(EXEC): $(OBJS)
	#$(LD) $(LDFLAGS) $(TARGET_ARCH) -o $@ $^ $(LDLIBS)
	$(LINK.o) $^ $(LDLIBS)

$(OBJDIR)/%.o: %.f90
$(OBJDIR)/%.o: %.f90 $(DEPDIR)/%.d
	$(COMPILE.f90) $<
	$(POSTCOMPILE)


.PRECIOUS: $(DEPDIR)/%.d
$(DEPDIR)/%.d: ;

-include $(DEPS)

The error I get:

pgfortran -c -o .o/.//pardiso_sym_f90.o pardiso_sym_f90.f90
PGF90-S-0017-Unable to open include file: mkl_pardiso.f90 (pardiso_sym_f90.f90: 22)
PGF90-F-0004-Unable to open MODULE file mkl_pardiso.mod (pardiso_sym_f90.f90: 24)
PGF90/x86-64 Linux 18.10-1: compilation aborted
Makefile:97: recipe for target ‘.o/.//pardiso_sym_f90.o’ failed
make: *** [.o/.//pardiso_sym_f90.o] Error 2

I’m fairly new to makefile concept, any help with this specific problem or in general is appreciated.

Thank you in advance.

Hi kkb,

The problem here is that the compiler doesn’t can’t find the include file.

To fix, update you’re make file with the path to the file.

#FFLAGS := -warn all -O2 -i8 -I${MKLROOT}/include
FFLAGS := -O2 -i8 -I${MKLROOT}/include

Hope this helps,
Mat

Thanks Mat.

With your suggestion, I’m able to create the module files mkl_pardio.mod and mkl_pardiso_private.mod. However, now I’m faced with this result.

pgfortran -O2 -i8 -I/home/kaan/intel/compilers_and_libraries_2019.3.199/linux/mkl/include -c -o .o/.//pardiso_sym_f90.o pardiso_sym_f90.f90
PGF90-W-0155-END statement for internal procedure should be END FUNCTION (/home/kaan/intel/compilers_and_libraries_2019.3.199/linux/mkl/include/mkl_pardiso.f90: 485)
PGF90-W-0155-END statement for internal procedure should be END SUBROUTINE (/home/kaan/intel/compilers_and_libraries_2019.3.199/linux/mkl/include/mkl_pardiso.f90: 496)
PGF90-W-0155-END statement for internal procedure should be END SUBROUTINE (/home/kaan/intel/compilers_and_libraries_2019.3.199/linux/mkl/include/mkl_pardiso.f90: 504)
PGF90-W-0155-END statement for internal procedure should be END SUBROUTINE (/home/kaan/intel/compilers_and_libraries_2019.3.199/linux/mkl/include/mkl_pardiso.f90: 518)
PGF90-W-0155-END statement for internal procedure should be END SUBROUTINE (/home/kaan/intel/compilers_and_libraries_2019.3.199/linux/mkl/include/mkl_pardiso.f90: 528)
PGF90-W-0155-END statement for internal procedure should be END SUBROUTINE (/home/kaan/intel/compilers_and_libraries_2019.3.199/linux/mkl/include/mkl_pardiso.f90: 538)
PGF90-W-0155-END statement for internal procedure should be END SUBROUTINE (/home/kaan/intel/compilers_and_libraries_2019.3.199/linux/mkl/include/mkl_pardiso.f90: 548)
0 inform, 7 warnings, 0 severes, 0 fatal for mkl_pardiso
mv -f .d/.//pardiso_sym_f90.Td .d/.//pardiso_sym_f90.d
mv: cannot stat ‘.d/.//pardiso_sym_f90.Td’: No such file or directory
Makefile:98: recipe for target ‘.o/.//pardiso_sym_f90.o’ failed
make: *** [.o/.//pardiso_sym_f90.o] Error 1

I think my mistake is that I’m trying to create the dependencies automatically, but because of the wrong flag options I’m faced with errors. What else can I fix or are there any suggestions?

Thanks in advance.

We do have some flags for creating makefile dependencies. If you do pgfortran -help, you will see things like -Mcpp[=m|md|mm…] You should see if those map to what you were using with ifort.