title: Numpy sort much slower than Matlab sort
body: <p>I am turning some codes from Matlab to Python. I am sometimes quite surprised by the performance loss. Here is an example on sorting arrays, which turns me nuts.</p>
  <p><strong>Matlab :</strong></p>
  <pre class="lang-matlab prettyprint-override"><code>a=rand(50000,1000);tic;b=sort(a,1);toc
  </code></pre>
  <p><em>Elapsed time is 0.624460 seconds.</em></p>
  <p><strong>Python :</strong></p>
  <pre class="lang-python prettyprint-override"><code>import numpy as np
  import time
  a=np.random.rand(50000,1000);
  t0=time.time();b=np.sort(a,axis=0);print(time.time()-t0)
  </code></pre>
  <p><em>4.192200422286987</em></p>
  <p>Can someone explain why there is a factor 7 in performance for such a basic operation? I see that sort is not multi-threaded on Python and this should be the main reason on my 20 cores machine.</p>
  <p>For now I tried (following <a href="https://docs.anaconda.com/mkl-optimizations/index.html" rel="nofollow noreferrer">this link</a>):</p>
  <pre class="lang-bash prettyprint-override"><code>sudo apt update
  sudo apt install intel-mkl-full
  conda install -c intel numpy 
  </code></pre>
  <p>But this did not change the behavior. In a terminal I also typed</p>
  <pre class="lang-bash prettyprint-override"><code>export MKL_NUM_THREADS=20
  export NUMEXPR_NUM_THREADS=20
  export OMP_NUM_THREADS=20
  </code></pre>
  <p>In Python, the following command</p>
  <pre class="lang-python prettyprint-override"><code>np.show_config()
  </code></pre>
  <p>returns</p>
  <pre><code>blas_mkl_info:
      libraries = ['mkl_rt', 'pthread']
      library_dirs = ['/home/pierre/anaconda3/lib']
      define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
      include_dirs = ['/home/pierre/anaconda3/include']
  blas_opt_info:
      libraries = ['mkl_rt', 'pthread']
      library_dirs = ['/home/pierre/anaconda3/lib']
      define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
      include_dirs = ['/home/pierre/anaconda3/include']
  lapack_mkl_info:
      libraries = ['mkl_rt', 'pthread']
      library_dirs = ['/home/pierre/anaconda3/lib']
      define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
      include_dirs = ['/home/pierre/anaconda3/include']
  lapack_opt_info:
      libraries = ['mkl_rt', 'pthread']
      library_dirs = ['/home/pierre/anaconda3/lib']
      define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
      include_dirs = ['/home/pierre/anaconda3/include']
  </code></pre>
  <p>Which seems to indicate that I am really using MKL. Is there a way to have np.sort work in parallel for arrays?</p>