Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Alex8
Beginner
47 Views

Compiling Applications with MKL

Hi all,

I have MKL installed on my Ubuntu Server 16.04. I've used the Intel-provided mklvars.sh script to provide the directories with the MKL libraries. Every time I try to use these directories with a compiler (such as gcc or gfortran), I'm never able to reference the libraries without providing the -L option and the directory manually. I thought the script would set the environment variables so I wouldn't have to provide these entries in the dynamic links. The script is sets MKLROOT, LD_LIBRARY_PATH, and LIBRARY_PATH successfully, but when I attempt to run compilers without the directory, I'm told the files cannot be found. 

Any suggestions are tremendously appreciated!

0 Kudos
5 Replies
mecej4
Black Belt
47 Views

The Intel compiler drivers icc and ifort recognize the -mkl option for this very purpose. When you use a non-Intel compiler, if you do not have a compiler driver with the equivalent option, you can write a shell-script that will convert a "-mkl" shell-script option to the corresponding -I, -L and -l options.

Alex8
Beginner
47 Views

Thanks for the response. Could you please provide an example of what you've proposed? I'm not quite sure I understand. 

Thanks so much!

TimP
Black Belt
47 Views

The mkl link advisor covers include and library options for gcc and gfortran on the supported platforms.  As you said, they require explicit L and I specification, so you may consider make or some other scripting option worth while.  The built in ability of icc and ifort to set up an ld script is limited to a few basic cases.

Joseph_A_
Beginner
47 Views

I have a sample C program that makes use of trigonometric functions. I want to compile it using GCC 6.2.0.

On using the following command, 

gcc -liomp5 -lmkl_core -lmkl_intel_thread -lmkl_intel_lp64 example_tignometry.c

I get,

example_tignometry.c:(.text+0x35): undefined reference to `sin'
example_tignometry.c:(.text+0x48): undefined reference to `cos'
example_tignometry.c:(.text+0x5b): undefined reference to `tan'
example_tignometry.c:(.text+0x6e): undefined reference to `sinh'
example_tignometry.c:(.text+0x81): undefined reference to `cosh'
example_tignometry.c:(.text+0x94): undefined reference to `tanh'
example_tignometry.c:(.text+0xa7): undefined reference to `log'
example_tignometry.c:(.text+0xba): undefined reference to `log10'
example_tignometry.c:(.text+0xcd): undefined reference to `exp'

The contents of example_tignometry.c are

#include <stdio.h>
#include <math.h>
int main(){
float i = 0.314;
       float j = 0.25;
       float k = 6.25;
       float sin_value = sin(i);
       float cos_value = cos(i);
       float tan_value = tan(i);
       float sinh_value = sinh(j);
       float cosh_value = cosh(j);
       float tanh_value = tanh(j);
       float log_value = log(k);
       float log10_value = log10(k);
       float exp_value = exp(k);

       printf("The value of sin(%f) : %f \n", i, sin_value);
       printf("The value of cos(%f) : %f \n", i, cos_value);
       printf("The value of tan(%f) : %f \n", i, tan_value);
       printf("The value of sinh(%f) : %f \n", j, sinh_value);
       printf("The value of cosh(%f) : %f \n", j, cosh_value);
       printf("The value of tanh(%f) : %f \n", j, tanh_value);
       printf("The value of log(%f) : %f \n", k, log_value);
       printf("The value of log10(%f) : %f \n",k,log10_value);
       printf("The value of exp(%f) : %f \n",k, exp_value);
       return 0;
}

 

 

TimP
Black Belt
47 Views

As mentioned earlier in the thread, the MKL link advisor applet ought to get you much closer to the answer, in case you do decide to use MKL.  From the looks of it you would need -lm (requirement unrelated to mkl).  As you apparently are linking dynamic libraries, you may not need attention to correct order and use of start-group...end-group directives, but since your example doesn't actually use MKL, you can do anything you like with the MKL references.

Reply