linuxgccmakefileblasintel-mkl

Compiling "binica" with Intel MKL BLAS LAPACK on Ubuntu 16.04


For a specific data analysis, I use the pre-compiled ica_linux binary from this repository. In the README.md of that repository, the authors state that you can achieve a major speedup when compiling the binary with architecture specific BLAS/LAPACK implementations.

In our case, the speedup might actually save days of computing time, so I am very eager to compile the file with the appropriate libraries. Now, I don't have a lot of experience with makefiles, so I am a bit confused by the process.

My system is a HP ProLiant DL360 Server with two Intel Xeon E5-2650 v3 deca-core processors and Ubuntu 16.04.6 x64 (Xenial Xerus).

I tried the following

Clone repository

sudo git clone https://github.com/sccn/binica
cd binica

install Intel MKL

I used this manual.

sudo wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
sudo rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB
sudo wget https://apt.repos.intel.com/setup/intelproducts.list -O /etc/apt/sources.list.d/intelproducts.list
sudo apt update
sudo apt install intel-mkl-2020.0-088

Adjust file Makefile.linux

This is the point where I don't really understand which libraries I have to add. I tried the following, but I am not sure whether that is the correct way to proceed.

PLAT = _linux

CC        = gcc
CFLAGS    = -O3 -ansi
#BLASLIB   = ./CLAPACK/lsblaspii1.2f_03.00.a
#BLASLIB   = ./CLAPACK/blas$(PLAT).a
#LAPACKLIB = ./CLAPACK/lapack$(PLAT).a
#F2CLIB    = ./CLAPACK/F2CLIBS/libF77$(PLAT).a ./CLAPACK/F2CLIBS/libI77$(PLAT).a
#LIBS      = $(LAPACKLIB) $(BLASLIB) $(F2CLIB) -lm
LIBS      = /opt/intel/mkl/lib/intel64_lin/libmkl_intel_ilp64.a
OBJS      = ica.o interfc.o r250.o randlcg.o dsum.o

ica_linux: Makefile.linux ica.h memap.h $(OBJS)
    $(CC) -o ica_linux $(OBJS) $(LIBS)

ica.o: Makefile.linux ica.h memap.h ica.c
    $(CC) -c ica.c $(CFLAGS)

interfc.o: Makefile.linux ica.h memap.h interfc.c
    $(CC) -c interfc.c $(CFLAGS)

memap.o: Makefile.linux memap.h memap.c
    $(CC) -c memap.c $(CFLAGS)

r250.o: Makefile.linux r250.h r250.c
    $(CC) -c r250.c $(CFLAGS)

randlcg.o: Makefile.linux randlcg.h randlcg.c
    $(CC) -c randlcg.c $(CFLAGS)

dsum.o: Makefile.linux dsum.c
    $(CC) -c dsum.c $(CFLAGS)

clean:
    rm -f *.o

Make file

I then ran:

sudo make Makefile.linux clean
sudo make Makefile.linux ica_linux

Which unfortunately fails with this error message:

cd ~/Downloads/binica
sudo make Makefile.linux ica_linux

Output:

make: Nothing to be done for 'Makefile.linux'.
gcc -c ica.c -O3 -ansi
ica.c: In function ‘sigproc’:
ica.c:565:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘integer {aka long int}’ [-Wformat=]
   printf("number of components = %d\n",COMP_NUMBER);
          ^
ica.c:566:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘integer {aka long int}’ [-Wformat=]
   printf("number of channels = %d\n",CH_NUMBER);
          ^
ica.c: In function ‘runica’:
ica.c:904:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘integer {aka long int}’ [-Wformat=]
       printf("step %d - lrate %5f, wchange %7.6f, angledelta %4.1f deg\n",step,lrate,change,DEGCONST*angledelta);
              ^
ica.c:907:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘integer {aka long int}’ [-Wformat=]
       printf("step %d - lrate %5f, wchange %7.6f, angledelta %4.1f deg, %d subgauss\n",step,lrate,change,DEGCONST*angledelta,j);
              ^
ica.c:907:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 6 has type ‘integer {aka long int}’ [-Wformat=]
ica.c:914:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘integer {aka long int}’ [-Wformat=]
       printf("step %d - lrate %5f, wchange %7.6f\n",step,lrate,change);
              ^
ica.c:917:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘integer {aka long int}’ [-Wformat=]
       printf("step %d - lrate %5f, wchange %7.6f, %d subgauss\n",step,lrate,change,j);
              ^
ica.c:917:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘integer {aka long int}’ [-Wformat=]
gcc -c interfc.c -O3 -ansi
interfc.c:50:17: warning: missing terminating " character
 #define HELPMSG "# ica - Perform Independent Component Analysis, standalone-version
                 ^
interfc.c:52:5: error: invalid preprocessing directive #Run
 #   Run the ICA algorithm of Bell & Sejnowski (1996) or the extended-ICA
     ^
interfc.c:53:5: error: invalid preprocessing directive #of
 #   of Lee, Girolami & Sejnowski (1998). Original Matlab code: Scott Makeig,
     ^
interfc.c:54:5: error: invalid preprocessing directive #Tony
 #   Tony Bell, et al.; C++ code: Sigurd Enghoff, CNL / Salk Institute 7/98
     ^
interfc.c:56:5: error: invalid preprocessing directive #Usage
 #   Usage:   % ica < my.sc
     ^
interfc.c:58:5: error: invalid preprocessing directive #Leading
 #   Leading # -> use default values
     ^
interfc.c:59:5: error: invalid preprocessing directive #Edit
 #   Edit a copy of this file to run an ica decomposition
     ^
interfc.c:60:5: error: invalid preprocessing directive #Contacts
 #   Contacts: {enghoff,scott,terry,tony,tewon}@salk.edu
     ^
interfc.c:62:3: error: invalid preprocessing directive #Required
 # Required variables:
   ^
interfc.c:63:5: error: unknown type name ‘DataFile’
     DataFile     berger/modeldata # Input data to decompose (floats multiplexed
     ^
interfc.c:63:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘/’ token
     DataFile     berger/modeldata # Input data to decompose (floats multiplexed
                        ^
interfc.c:63:35: error: stray ‘#’ in program
     DataFile     berger/modeldata # Input data to decompose (floats multiplexed
                                   ^
interfc.c:64:32: error: invalid preprocessing directive #by
                            #   by channel (i.e., chan1, chan2, ...))
                                ^
interfc.c:65:28: error: stray ‘#’ in program
     chans        31        # Number of data channels (= data rows)
                            ^
interfc.c:66:28: error: stray ‘#’ in program
     frames       768       # Number of data points per epoch (= data columns)
                            ^
interfc.c:67:28: error: stray ‘#’ in program
     epochs       436       # Number of epochs
                            ^
interfc.c:69:3: error: invalid preprocessing directive #FrameWindow
 # FrameWindow  20        # Number of frames per window
   ^
interfc.c:70:3: error: invalid preprocessing directive #FrameStep
 # FrameStep    4         # Number of frames to step per window
   ^
interfc.c:71:3: error: invalid preprocessing directive #EpochWindow
 # EpochWindow  100       # Number of epochs per window
   ^
interfc.c:72:3: error: invalid preprocessing directive #EpochStep
 # EpochStep    25        # Number of epochs to step per window
   ^
interfc.c:73:3: error: invalid preprocessing directive #Baseline
 # Baseline     25        # Number of data points contained in baseline
   ^
interfc.c:75:36: error: stray ‘#’ in program
     WeightsOutFile berger/data.wts # Output ICA weight matrix (floats)
                                    ^
interfc.c:76:35: error: stray ‘#’ in program
     SphereFile   berger/data.sph  # Output sphering matrix (floats)
                                   ^
interfc.c:78:3: error: invalid preprocessing directive #Processing
 # Processing options:
   ^
interfc.c:80:5: error: invalid preprocessing directive #sphering
 #   sphering     on        # Flag sphering of data (on/off)   {default: on}
     ^
interfc.c:81:5: error: invalid preprocessing directive #bias
 #   bias         on        # Perform bias adjustment (on/off) {default: on}
     ^
interfc.c:82:5: error: stray ‘\’ in program
     \exextended     1         # Perform \"extended-ICA\" using tnah() with kurtosis
     ^
interfc.c:82:31: error: stray ‘#’ in program
     \exextended     1         # Perform \"extended-ICA\" using tnah() with kurtosis
                               ^
interfc.c:82:5: error: stray ‘\’ in program
     \exextended     1         # Perform \"extended-ICA\" using tnah() with kurtosis
     ^
interfc.c:82:42: warning: missing terminating " character
     \exextended     1         # Perform \"extended-ICA\" using tnah() with kurtosis
                                          ^
interfc.c:82:5: error: missing terminating " character
     \exextended     1         # Perform \"extended-ICA\" using tnah() with kurtosis
     ^
interfc.c:83:31: error: invalid preprocessing directive #estimation
                            #  estimation every N training blocks. If N < 0,
                               ^
interfc.c:84:31: error: invalid preprocessing directive #fix
                            #  fix number of sub-Gaussian components to -N
                               ^
interfc.c:85:31: error: invalid preprocessing directive #{
                            #  {default|0: off}
                               ^
interfc.c:86:5: error: invalid preprocessing directive #pca
 #   pca          0         # Decompose a principal component subspace of
     ^
interfc.c:87:31: error: invalid preprocessing directive #the
                            #  the data. Retain this many PCs. {default|0: all}
                               ^
interfc.c:88:3: error: invalid preprocessing directive #Optional
 # Optional input variables:
   ^
interfc.c:90:4: error: invalid preprocessing directive #WeightsInFile
 #  WeightsInFile input.wts # Starting ICA weight matrix (nchans,ncomps)
    ^
interfc.c:91:31: error: invalid preprocessing directive #{
                            #  {default: identity or sphering matrix}
                               ^
interfc.c:92:28: error: stray ‘#’ in program
     lrate        2.0e-3    # Initial ICA learning rate (float << 1)
                            ^
interfc.c:93:31: error: invalid preprocessing directive #{
                            #  {default: heuristic ~5e-4}
                               ^
interfc.c:94:5: error: invalid preprocessing directive #blocksize
 #   blocksize    20        # ICA block size (integer << datalength)
     ^
interfc.c:95:31: error: invalid preprocessing directive #{
                            #  {default: heuristic fraction of log data length}
                               ^
interfc.c:96:5: error: invalid preprocessing directive #stop
 #   stop         1.0e-6    # Stop training when weight-change < this value
     ^
interfc.c:97:31: error: invalid preprocessing directive #{
                            #  {default: heuristic ~0.000001}
                               ^
interfc.c:98:28: error: stray ‘#’ in program
     maxsteps     512       # Max. number of ICA training steps {default: 128}
                            ^
interfc.c:99:5: error: invalid preprocessing directive #posact
 #   posact       on        # Make each component activation net-positive
     ^
interfc.c:100:30: error: invalid preprocessing directive #(
                            # (on/off) {default: on}
                              ^
interfc.c:101:5: error: invalid preprocessing directive #annealstep
 #   annealstep   0.98      # Annealing factor (range (0,1]) - controls
     ^
interfc.c:102:31: error: invalid preprocessing directive #the
                            #  the speed of convergence.
                               ^
interfc.c:103:5: error: invalid preprocessing directive #annealdeg
 #   annealdeg    60        # Angledelta threshold for annealing {default: 60}
     ^
interfc.c:104:5: error: invalid preprocessing directive #momentum
 #   momentum     0.0       # Momentum gain (range [0,1])      {default: 0}
     ^
interfc.c:105:5: error: invalid preprocessing directive #verbose
 #   verbose      off        # Give ascii messages (on/off) {default: on}
     ^
interfc.c:107:3: error: invalid preprocessing directive #Optional
 # Optional outputs:
   ^
interfc.c:109:4: error: invalid preprocessing directive #ActivationsFile
 #  ActivationsFile data.act # Activations of each component (ncomps,points)
    ^
interfc.c:110:4: error: invalid preprocessing directive #BiasFile
 #  BiasFile      data.bs   # Bias weights (ncomps,1)
    ^
interfc.c:111:4: error: invalid preprocessing directive #SignFile
 #  SignFile      data.sgn  # Signs designating (-1) sub- and (1) super-Gaussian
    ^
interfc.c:112:31: error: invalid preprocessing directive #components
                            #  components (ncomps,1)
                               ^
interfc.c:114:3: error: invalid preprocessing directive #This
 # This script, \"ica.sc\" is a sample ica script file. Copy and modify it as
   ^
interfc.c:114:17: warning: missing terminating " character
 # This script, \"ica.sc\" is a sample ica script file. Copy and modify it as
                 ^
interfc.c:115:3: error: invalid preprocessing directive #desired
 # desired. Note that the input data file(s) must be native floats."
   ^
interfc.c:115:67: warning: missing terminating " character
 # desired. Note that the input data file(s) must be native floats."
                                                                   ^
interfc.c: In function ‘help’:
interfc.c:170:3: error: missing terminating " character
   puts(HELPMSG);
   ^
interfc.c:170:3: error: too few arguments to function ‘puts’
interfc.c: In function ‘doit’:
interfc.c:679:12: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘integer {aka long int}’ [-Wformat=]
     printf("PDF will be calculated initially every %d blocks using %d data points.\n",extblocks,pdfsize);
            ^
interfc.c:679:12: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘integer {aka long int}’ [-Wformat=]
interfc.c:681:12: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘integer {aka long int}’ [-Wformat=]
     printf("PDF will not be calculated. Exactly %d sub-Gaussian components assumed.\n",nsub);
            ^
interfc.c:684:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘integer {aka long int}’ [-Wformat=]
   printf("Initial learning rate will be %g, block size %d.\n",lrate,block);
          ^
interfc.c:690:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘integer {aka long int}’ [-Wformat=]
   printf("Training will end when wchange < %g or after %d steps.\n",nochange,maxsteps);
          ^
interfc.c: In function ‘master’:
interfc.c:923:16: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
    keys->token = strdup(token);
                ^
 Makefile:19: recipe for target 'interfc.o' failed
 make: *** [interfc.o] Error 1

Solution

  • I don't really understand which libraries I have to add

    Do understand the list of Intel MKL libraries you need to add. Please refer to the Intel MKL Linker Adviser to choose the list of libraries needed to add. Here is the list of this article:

    Intel oneAPI Math Kernel Library Link Line Advisor