Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libraries affecting other libraries in a Makefile

I am facing a weird problem in the following Makefile:

# Mosek path
MOSEKPATH = /autofs/fs1.ece/fs1.eecg.najm/b/b1/power_grid_code/mosek

# Include paths
INCPATHS = -I$(MOSEKPATH)/7/tools/platform/linux64x86/h -I/usr/include/suitesparse -I../include

# Libraries paths
LIBPATHS = -L$(MOSEKPATH)/7/tools/platform/linux64x86/bin

# Link libraries
LIBS = -lboost_timer-mt -lboost_system -lumfpack -lamd -lcolamd -lcholmod -lccolamd -lcamd -lbtf -lcsparse -lcxsparse -lklu -lldl -lspqr -llapack -lblas
MOSEKLIB = -lmosek64
LDOPT = -Wl,-rpath-link,$(MOSEKPATH)/7/tools/platform/linux64x86/bin -Wl,-rpath,'/autofs/fs1.ece/fs1.eecg.najm/b/b1/power_grid_code/mosek/7/tools/platform/linux64x86/bin' -pthread -lc -lm

# Specify compiler
CC = g++-4.7 -m64

# Compiler flags
FLAGS = -O3 -Wall -g

lo1: lo1.c
    $(CC) $(FLAGS) -c $(INCPATHS)          -o lo1.o lo1.c
    $(CC) $(FLAGS) $(LIBPATHS) lo1.o $(LIBS) $(MOSEKLIB) $(LDOPT) -o lo1 

clean:
    rm -f lo1 *.o 

I got most of the content from the examples provided by MOSEK. The Makefile works fine and the results are as expected. The issue is that, the version of MOSEK that I'm using is multi-threaded (MOSEK 7.1). MOSEK is supposed to detect the number of cores on the machine, and use all of them. When I use the Makefile as is, MOSEK only detects one core, and uses only one thread:

Computer
  Platform               : Linux/64-X86    
  Cores                  : 1              

However, when i compile without $(LIBS), MOSEK does detect 4 cores:

Computer
  Platform               : Linux/64-X86    
  Cores                  : 4               

The code that I have in lo1.c does not use $(LIBS) for now, but I will need those libraries later on, in lo1.c. How come those libraries are affecting the behavior of MOSEK?

Thank you.

like image 210
Mohammad Fawaz Avatar asked Nov 08 '22 22:11

Mohammad Fawaz


1 Answers

It turns out that the problem was with BLAS. Some of the libraries from SuiteSparse require BLAS and the BLAS libraries on the server messes up with OpenMP, which is apparently required by MOSEK to parallelize its code. In any case, the solution was to use OpenBLAS, compiled with the flag "USE_OPENMP=1".

like image 85
Mohammad Fawaz Avatar answered Nov 15 '22 05:11

Mohammad Fawaz