Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Makefile and MKL

Georgios_S_
New Contributor II
1,763 Views

Hi,

  I am using MKL (the student version) with MPICH2.In my Makefile, the paths for MKL are hardcoded. How can I make it that they get more general? I mean, that now that my professor will check the project, assuming he was MKL installed in his system, how can he compile it? I would like to provide a Makefile that would be (almost) ready to run.

OBJSDIR    =   obj
OBJS    = $(OBJSDIR)/main.o	$(OBJSDIR)/IO.o	$(OBJSDIR)/alloc.o	$(OBJSDIR)/communication.o	$(OBJSDIR)/accuracy.o
SOURCE  = main.cpp	src/IO.cpp	src/alloc.cpp	src/communication.cpp	src/accuracy.cpp
HEADER =	headers/IO.h	headers/alloc.h	headers/communication.h	headers/accuracy.h
OUT     =       test
CXX     = ../../mpich-install/bin/mpic++
CXXFLAGS	=	-I../../intel/mkl/include	-Wl,--start-group	 -Wl,--end-group	-lpthread	-lm	-ldl	-Wall
LDFLAGS   =       ../../intel/mkl/lib/intel64/libmkl_scalapack_lp64.a       -Wl,--start-group       ../../intel/mkl/lib/intel64/libmkl_intel_lp64.a ../../intel/mkl/lib/intel64/libmkl_core.a  ../../intel/mkl/lib/intel64/libmkl_sequential.a    -Wl,--end-group ../../intel/mkl/lib/intel64/libmkl_blacs_intelmpi_lp64.a -lpthread       -lm     -ldl

all:	$(OBJSDIR)	$(OUT)

$(OBJSDIR):
	mkdir	$(OBJSDIR)

$(OUT):	$(OBJS)
	$(CXX)	$(OBJS)	-o	$(OUT)	$(CXXFLAGS)	$(LDFLAGS)
#	make	-f	Makefile	clean

# create/compile the individual files >>separately<<
$(OBJSDIR)/main.o:    main.cpp
	$(CXX)	-c	main.cpp	$(CXXFLAGS)	-o	$@

$(OBJSDIR)/IO.o:	src/IO.cpp
	$(CXX)	-c	src/IO.cpp	$(CXXFLAGS)	-o	$@
	
$(OBJSDIR)/alloc.o:    src/alloc.cpp
	$(CXX)	-c	src/alloc.cpp	$(CXXFLAGS)	-o	$@
	
$(OBJSDIR)/communication.o:    src/communication.cpp
	$(CXX)	-c	src/communication.cpp	$(CXXFLAGS)	-o	$@
	
$(OBJSDIR)/accuracy.o:	src/accuracy.cpp
	$(CXX)	-c	src/accuracy.cpp	$(CXXFLAGS)	-o	$@

.PHONY:	clean
clean:
	rm	-rf	$(OBJSDIR)/*.o

 

So, how to modify CXXFLAGS and LDFLAGS? The linker advisor didn't help much.

0 Kudos
1 Solution
Roman_D_Intel1
Employee
1,763 Views

Sourcing mklvars.sh/csh or compilervars.sh/csh sets MKLROOT environment variable pointing to the MKL installation directory. Therefore you can use $(MKLROOT) in your Makefile. For example:

CXXFLAGS = -I$(MKLROOT)/include	
LDFLAGS  = $(MKLROOT)/lib/intel64/libmkl_scalapack_lp64.a -Wl,--start-group $(MKLROOT)/lib/intel64/libmkl_intel_lp64.a $(MKLROOT)/lib/intel64/libmkl_core.a $(MKLROOT)/lib/intel64/libmkl_sequential.a -Wl,--end-group $(MKLROOT)/lib/intel64/libmkl_blacs_intelmpi_lp64.a -lpthread -lm -ldl

 

View solution in original post

0 Kudos
4 Replies
Roman_D_Intel1
Employee
1,764 Views

Sourcing mklvars.sh/csh or compilervars.sh/csh sets MKLROOT environment variable pointing to the MKL installation directory. Therefore you can use $(MKLROOT) in your Makefile. For example:

CXXFLAGS = -I$(MKLROOT)/include	
LDFLAGS  = $(MKLROOT)/lib/intel64/libmkl_scalapack_lp64.a -Wl,--start-group $(MKLROOT)/lib/intel64/libmkl_intel_lp64.a $(MKLROOT)/lib/intel64/libmkl_core.a $(MKLROOT)/lib/intel64/libmkl_sequential.a -Wl,--end-group $(MKLROOT)/lib/intel64/libmkl_blacs_intelmpi_lp64.a -lpthread -lm -ldl

 

0 Kudos
Georgios_S_
New Contributor II
1,763 Views

Hi Roman,

  this didn't work, since I am getting errors of this nature: g++: error: /lib/intel64/libmkl_scalapack_lp64.a: No such file or directory

How to fix it?

George

0 Kudos
TimP
Honored Contributor III
1,763 Views

MKLROOT is set by sourcing the mklvars script in the MKL installation.  Of course, it requires such an installation.

0 Kudos
Georgios_S_
New Contributor II
1,763 Views

That's it Tim, nice. I am going to accept Roman's answer, but I would like Roman to edit his post with the information of Tim.

 

Thanks,

George

0 Kudos
Reply