title: Cython's prange not improving performance
body: <p>I'm trying to improve the performance of some metric computations with Cython's <code>prange</code>. Here are my codes:</p>
  
  <pre><code>def shausdorff(float64_t[:,::1] XA not None, float64_t[:,:,::1] XB not None):
      cdef:
          Py_ssize_t i
          Py_ssize_t n  = XB.shape[2]
          float64_t[::1] hdist = np.zeros(n)
  
      #arrangement to fix contiguity
      XB = np.asanyarray([np.ascontiguousarray(XB[:,:,i]) for i in range(n)])
  
      for i in range(n):
          hdist[i] = _hausdorff(XA, XB[i])
      return hdist
  
  def phausdorff(float64_t[:,::1] XA not None, float64_t[:,:,::1] XB not None):
      cdef:
          Py_ssize_t i
          Py_ssize_t n  = XB.shape[2]
          float64_t[::1] hdist = np.zeros(n)
  
      #arrangement to fix contiguity (EDITED)
      cdef float64_t[:,:,::1] XC = np.asanyarray([np.ascontiguousarray(XB[:,:,i]) for i in range(n)])
  
      with nogil, parallel(num_threads=4):
          for i in prange(n, schedule='static', chunksize=1):
              hdist[i] = _hausdorff(XA, XC[i])
      return hdist
  </code></pre>
  
  <p>Basically, in each iteration the hausdorff metric is computed between <code>XA</code> and each <code>XB[i]</code>. Here is the signature of the <code>_hausdorff</code> function:</p>
  
  <pre><code>cdef inline float64_t _hausdorff(float64_t[:,::1] XA, float64_t[:,::1] XB) nogil:
      ...
  </code></pre>
  
  <p>my problem is that both the sequential <code>shausdorff</code> and the parallel <code>phausdorff</code> have the same timings. Furthermore, it seems that <code>phausdorff</code> is not creating any thread at all.</p>
  
  <p>So my question is what is wrong with my code, and how can I fix it to get threading working.</p>
  
  <p>Here is my <code>setup.py</code>:</p>
  
  <pre><code>from distutils.core import setup
  from distutils.extension import Extension
  from Cython.Build import cythonize
  from Cython.Distutils import build_ext
  
  ext_modules=[
      Extension("custom_metric",
                ["custom_metric.pyx"],
                libraries=["m"],
                extra_compile_args = ["-O3", "-ffast-math", "-march=native", "-fopenmp" ],
                extra_link_args=['-fopenmp']
                ) 
  ]
  
  setup( 
    name = "custom_metric",
    cmdclass = {"build_ext": build_ext},
    ext_modules = ext_modules
  ) 
  </code></pre>
  
  <p><strong>EDIT 1:</strong> Here is a link to the html generated by <code>cython -a</code>: <a href="http://csrg.cl/~mavillan/custom_metric.html" rel="nofollow noreferrer">custom_metric.html</a></p>
  
  <p><strong>EDIT 2:</strong> Here is an example on how to call the corresponding functions (you need to compile <a href="http://csrg.cl/~mavillan/custom_metric.pyx" rel="nofollow noreferrer">the Cython file</a> first)</p>
  
  <pre><code>import custom_metric as cm
  import numpy as np
  
  XA = np.random.random((9000, 210))
  XB = np.random.random((1000, 210, 9))
  
  #timing 'parallel' version
  %timeit cm.phausdorff(XA, XB)
  
  #timing sequential version
  %timeit cm.shausdorff(XA, XB)
  </code></pre>