On 2/12/2009 1:44 PM, Sturla Molden wrote:
Here is an example of SciPy's ckdtree.pyx modified to use OpenMP.
It seems I managed to post an errorneous C file. :( S.M.
/* * Parallel query for faster kd-tree searches on SMP computers. * This function will release the GIL around the lengthy query loop and * use OpenMP for multithreading. * * OpenMP is supported on GCC (since version 4.2) and MS Visual C++ 2005 * and later. Mingw builds of GCC supports OpenMP through a pthread * layer (pthreadGC2.dll). * * Compile with -fopenmp and link -lgomp -lpthread on GCC. * * Written by Sturla Molden, Univ. Oslo, Jan. 24 2009 * * * This code is released to public domain. * */ #include <Python.h> #include <omp.h> typedef void (*queryfun_t)(void *self, double *result_distances, int*result_indices, double*x, int k, double eps, double p, double distance_upper_bound); void parallel_query(queryfun_t query, int nthreads, int niter, void *self, double*result_distances, int *result_indices, double*x, int k, int m, double eps, double p, double distance_upper_bound) { int c; /* allow the number of threads to be specified */ if (nthreads == 0) { Py_BEGIN_ALLOW_THREADS { #pragma omp parallel for private(c) schedule(guided) for (c=0; c<niter; c++) { (*query)(self, result_distances + c*k, result_indices + c*k, x + c*m, k, eps, p, distance_upper_bound); } } Py_END_ALLOW_THREADS } else { /* parallel queries with GIL released */ Py_BEGIN_ALLOW_THREADS { #pragma omp parallel for private(c) schedule(guided) num_threads(nthreads) for (c=0; c<niter; c++) { (*query)(self, result_distances + c*k, result_indices + c*k, x + c*m, k, eps, p, distance_upper_bound); } } Py_END_ALLOW_THREADS } }
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion