<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic and which version of Octave in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-5-times-slower-when-called-from-a-MEX-function-in-Octave/m-p/1152580#M27262</link>
    <description>&lt;P&gt;and which version of Octave do you use?&lt;/P&gt;</description>
    <pubDate>Fri, 15 Feb 2019 09:53:18 GMT</pubDate>
    <dc:creator>Gennady_F_Intel</dc:creator>
    <dc:date>2019-02-15T09:53:18Z</dc:date>
    <item>
      <title>MKL 5 times slower when called from a MEX function in Octave</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-5-times-slower-when-called-from-a-MEX-function-in-Octave/m-p/1152578#M27260</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to use Intel MKL library in an Octave MEX function, but the performance that I achieve using some MKL functions such as cblas_cgemm is 5 time slower when called from Octave rather than a compiled C executable. I'm using the same compilation flags for both C code and MEX functions in my testing, where I basically compare the speed of a very simple C matrix multiplication script and the same script wrapped in a MEX function (find this short example attached).&lt;/P&gt;&lt;P&gt;This is how I compile the C code:&lt;/P&gt;
&lt;PRE class="brush:; class-name:dark;"&gt;gcc -I/opt/intel/compilers_and_libraries_2019.0.117/linux/mkl/include -Wall -L/opt/intel/compilers_and_libraries_2019.0.117/linux/mkl/lib/intel64 -o cgemm_test_c matmult_c.c -lmkl_gnu_thread -lmkl_rt -lmkl_core -lmkl_intel_ilp64 -lgomp -lpthread -lm -ldl
&lt;/PRE&gt;

&lt;P&gt;This is how I compile the MEX function:&lt;/P&gt;

&lt;PRE class="brush:; class-name:dark;"&gt;mex -v -I/opt/intel/compilers_and_libraries_2019.0.117/linux/mkl/include -Wall -L/opt/intel/compilers_and_libraries_2019.0.117/linux/mkl/lib/intel64 -o cgemm_test_mex matmult_c.c matmult_mex.c -lmkl_gnu_thread -lmkl_rt -lmkl_core -lmkl_intel_ilp64 -lgomp -lpthread -lm -ldl
&lt;/PRE&gt;

&lt;P&gt;And this is what the mex command is really doing:&lt;/P&gt;

&lt;PRE class="brush:; class-name:dark;"&gt;gcc -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-4.2.2/octave/.. -I/usr/include/octave-4.2.2/octave -I/usr/include/hdf5/serial  -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-DtqyIg/octave-4.2.2=. -fstack-protector-strong -Wformat -Werror=format-security  -Wall  -I. -I/opt/intel/compilers_and_libraries_2019.0.117/linux/mkl/include  -DMEX_DEBUG matmult_c.c -o matmult_c.o

gcc -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/octave-4.2.2/octave/.. -I/usr/include/octave-4.2.2/octave -I/usr/include/hdf5/serial  -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-DtqyIg/octave-4.2.2=. -fstack-protector-strong -Wformat -Werror=format-security  -Wall  -I. -I/opt/intel/compilers_and_libraries_2019.0.117/linux/mkl/include  -DMEX_DEBUG matmult_mex.c -o matmult_mex.o

g++ -I/usr/include/octave-4.2.2/octave/.. -I/usr/include/octave-4.2.2/octave -I/usr/include/hdf5/serial -I/usr/include/mpi  -pthread -fopenmp -g -O2 -fdebug-prefix-map=/build/octave-DtqyIg/octave-4.2.2=. -fstack-protector-strong -Wformat -Werror=format-security -shared -Wl,-Bsymbolic  -Wall -o cgemm_test_mex.mex  matmult_c.o matmult_mex.o   -L/opt/intel/compilers_and_libraries_2019.0.117/linux/mkl/lib/intel64 -lmkl_gnu_thread -lmkl_rt -lmkl_core -lmkl_intel_ilp64 -lgomp -lpthread -lm -ldl -L/usr/lib/x86_64-linux-gnu/octave/4.2.2 -L/usr/lib/x86_64-linux-gnu -loctinterp -loctave -Wl,-Bsymbolic-functions -Wl,-z,relro

&lt;/PRE&gt;

&lt;P&gt;Test results:&lt;/P&gt;
&lt;P&gt;C code: Elapsed time per multiplication: ~1.86 ms&lt;/P&gt;
&lt;P&gt;MEX code: Elapsed time per multiplication: ~8.55ms&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tested different optimisation flags but the results are virtually the same thing. This has been tested in 2 Intel machines with Ubuntu 18.04 and Ubuntu 14.04, yielding very similar results in all cases. MKL environment variables are set as per "source /opt/intel/mkl/bin/mklvars.sh intel64"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks in advance,&lt;/P&gt;
&lt;P&gt;Juan.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 09:03:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-5-times-slower-when-called-from-a-MEX-function-in-Octave/m-p/1152578#M27260</guid>
      <dc:creator>Garcia__Juan</dc:creator>
      <dc:date>2019-02-14T09:03:42Z</dc:date>
    </item>
    <item>
      <title>that's interesting .... could</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-5-times-slower-when-called-from-a-MEX-function-in-Octave/m-p/1152579#M27261</link>
      <description>&lt;P&gt;that's interesting .... could you check if the performance gap will be the same in the case of square matrixes?&amp;nbsp; m=n=k == for example 8000.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2019 08:55:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-5-times-slower-when-called-from-a-MEX-function-in-Octave/m-p/1152579#M27261</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2019-02-15T08:55:18Z</dc:date>
    </item>
    <item>
      <title>and which version of Octave</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-5-times-slower-when-called-from-a-MEX-function-in-Octave/m-p/1152580#M27262</link>
      <description>&lt;P&gt;and which version of Octave do you use?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2019 09:53:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-5-times-slower-when-called-from-a-MEX-function-in-Octave/m-p/1152580#M27262</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2019-02-15T09:53:18Z</dc:date>
    </item>
  </channel>
</rss>

