diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 74fefe20..9c6aa4ae 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,6 +13,7 @@ on: jobs: tests: strategy: + fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: [3.11] @@ -36,10 +37,24 @@ jobs: conda install -c conda-forge pocl pyopencl python -c 'import pyopencl as cl' if: ${{ runner.os != 'Windows' }} + - name: Setup compyle config on MacOS to use openmp enabled clang from homebrew + run: | + brew install libomp + mkdir -p ~/.compyle + touch ~/.compyle/config.py + echo "import os" >> ~/.compyle/config.py + echo "os.environ['CC'] = '$(brew --prefix llvm@15)/bin/clang'" >> ~/.compyle/config.py + echo "os.environ['CXX'] = '$(brew --prefix llvm@15)/bin/clang++'" >> ~/.compyle/config.py + export CPPFLAGS="-I$(brew --prefix libomp)/include -I$(brew --prefix llvm@15)/include -Xclang -fopenmp" + export LDFLAGS="-L$(brew --prefix libomp)/lib -L$(brew --prefix llvm@15)/lib -lomp" + python -c "import os; OMP_CFLAGS=os.environ.get('CPPFLAGS').split(' '); print(f'{OMP_CFLAGS=}')" >> ~/.compyle/config.py + python -c "import os; OMP_LINK=os.environ.get('LDFLAGS').split(' '); print(f'{OMP_LINK=}')" >> ~/.compyle/config.py + cat ~/.compyle/config.py + if: ${{ runner.os == 'macOS' }} - name: Install dependencies run: | conda info - conda install -c conda-forge numpy 'cython<3.0' h5py + conda install -c conda-forge numpy cython h5py python -m pip install --upgrade pip setuptools wheel python -m pip install https://github.com/pypr/cyarray/zipball/master python -m pip install https://github.com/pypr/compyle/zipball/master @@ -52,7 +67,7 @@ jobs: id: month run: echo "month==$(date +'%m')" >> $GITHUB_OUTPUT - name: Deal with auto-generated code cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.pysph diff --git a/.github/workflows/zoltan-tests.yml b/.github/workflows/zoltan-tests.yml index c947706a..087b496c 100644 --- a/.github/workflows/zoltan-tests.yml +++ b/.github/workflows/zoltan-tests.yml @@ -40,12 +40,12 @@ jobs: - name: Install dependencies run: | conda info - conda install -c conda-forge numpy 'cython<3.0' + conda install -c conda-forge numpy cython python -m pip install --upgrade pip setuptools wheel - python -m pip install mpi4py + python -m pip install "mpi4py<4.0" python -m pip install https://github.com/pypr/cyarray/zipball/master - python -m pip install --no-build-isolation https://github.com/pypr/pyzoltan/zipball/master python -m pip install https://github.com/pypr/compyle/zipball/master + python -m pip install --no-build-isolation https://github.com/pypr/pyzoltan/zipball/master python -m pip install -r requirements.txt python -m pip install -r requirements-test.txt python setup.py develop @@ -55,7 +55,7 @@ jobs: id: month run: echo "month==$(date +'%m')" >> $GITHUB_OUTPUT - name: Deal with auto-generated code cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.pysph diff --git a/pyproject.toml b/pyproject.toml index 5aa017ac..6f6bed96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,11 @@ [build-system] requires = [ "Beaker", - "Cython<3.0", + "Cython>=0.20", "compyle>=0.8", "cyarray", "mako", - "oldest-supported-numpy", + "numpy>=2.0,<3", "pytools", "setuptools>=42.0.0", "wheel>=0.29.0", diff --git a/pysph/base/box_sort_nnps.pxd b/pysph/base/box_sort_nnps.pxd index fb1c0adf..cc3daf45 100644 --- a/pysph/base/box_sort_nnps.pxd +++ b/pysph/base/box_sort_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.map cimport map from .nnps_base cimport * diff --git a/pysph/base/box_sort_nnps.pyx b/pysph/base/box_sort_nnps.pyx index ca1bfb25..6f0ecfb9 100644 --- a/pysph/base/box_sort_nnps.pyx +++ b/pysph/base/box_sort_nnps.pyx @@ -1,4 +1,7 @@ -# cython: language_level=3, language=c++, embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + # Library imports. import numpy as np cimport numpy as np @@ -42,7 +45,7 @@ cdef class BoxSortNNPS(LinkedListNNPS): @cython.boundscheck(False) @cython.wraparound(False) cdef inline long _get_valid_cell_index(self, int cid_x, int cid_y, int cid_z, - int* ncells_per_dim, int dim, int n_cells) nogil: + int* ncells_per_dim, int dim, int n_cells) noexcept nogil: """Return the flattened index for a valid cell""" cdef long ncx = ncells_per_dim[0] cdef long ncy = ncells_per_dim[1] diff --git a/pysph/base/c_kernels.pyx b/pysph/base/c_kernels.pyx index e69e06d4..7a43a7f9 100644 --- a/pysph/base/c_kernels.pyx +++ b/pysph/base/c_kernels.pyx @@ -15,7 +15,7 @@ cdef class CubicSpline: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -56,13 +56,13 @@ cdef class CubicSpline: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 2. / 3 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -81,7 +81,7 @@ cdef class CubicSpline: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -117,7 +117,7 @@ cdef class CubicSpline: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -148,7 +148,7 @@ cdef class CubicSpline: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class CubicSplineWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -192,7 +192,7 @@ cdef class WendlandQuintic: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -221,13 +221,13 @@ cdef class WendlandQuintic: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.5 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -247,7 +247,7 @@ cdef class WendlandQuintic: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -278,7 +278,7 @@ cdef class WendlandQuintic: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -306,7 +306,7 @@ cdef class WendlandQuintic: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -350,7 +350,7 @@ cdef class Gaussian: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -377,7 +377,7 @@ cdef class Gaussian: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: # The inflection point is at q=1/sqrt(2) # the deltap values for some standard kernels # have been tabulated in sec 3.2 of @@ -387,7 +387,7 @@ cdef class Gaussian: cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -407,7 +407,7 @@ cdef class Gaussian: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -436,7 +436,7 @@ cdef class Gaussian: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -461,7 +461,7 @@ cdef class Gaussian: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class GaussianWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -505,7 +505,7 @@ cdef class QuinticSpline: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -551,7 +551,7 @@ cdef class QuinticSpline: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: # The inflection points for the polynomial are obtained as # http://www.wolframalpha.com/input/?i=%28%283-x%29%5E5+-+6*%282-x%29%5E5+%2B+15*%281-x%29%5E5%29%27%27 # the only permissible value is taken @@ -560,7 +560,7 @@ cdef class QuinticSpline: cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -580,7 +580,7 @@ cdef class QuinticSpline: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -633,7 +633,7 @@ cdef class QuinticSpline: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -675,7 +675,7 @@ cdef class QuinticSpline: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class QuinticSplineWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -719,7 +719,7 @@ cdef class SuperGaussian: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -748,7 +748,7 @@ cdef class SuperGaussian: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: # Found inflection point using sympy. if self.dim == 1: return 0.584540507426389 @@ -760,7 +760,7 @@ cdef class SuperGaussian: cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -779,7 +779,7 @@ cdef class SuperGaussian: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double d cdef double fac cdef double h1 @@ -810,7 +810,7 @@ cdef class SuperGaussian: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -837,7 +837,7 @@ cdef class SuperGaussian: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class SuperGaussianWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -881,7 +881,7 @@ cdef class WendlandQuinticC4: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -911,13 +911,13 @@ cdef class WendlandQuinticC4: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.47114274 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -937,7 +937,7 @@ cdef class WendlandQuinticC4: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -970,7 +970,7 @@ cdef class WendlandQuinticC4: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -999,7 +999,7 @@ cdef class WendlandQuinticC4: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC4Wrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -1043,7 +1043,7 @@ cdef class WendlandQuinticC6: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1073,13 +1073,13 @@ cdef class WendlandQuinticC6: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.4305720757 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -1098,7 +1098,7 @@ cdef class WendlandQuinticC6: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -1131,7 +1131,7 @@ cdef class WendlandQuinticC6: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1160,7 +1160,7 @@ cdef class WendlandQuinticC6: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC6Wrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -1204,7 +1204,7 @@ cdef class WendlandQuinticC2_1D: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1233,13 +1233,13 @@ cdef class WendlandQuinticC2_1D: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 2.0/3 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -1259,7 +1259,7 @@ cdef class WendlandQuinticC2_1D: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -1290,7 +1290,7 @@ cdef class WendlandQuinticC2_1D: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1318,7 +1318,7 @@ cdef class WendlandQuinticC2_1D: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC2_1DWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -1362,7 +1362,7 @@ cdef class WendlandQuinticC4_1D: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1391,13 +1391,13 @@ cdef class WendlandQuinticC4_1D: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.55195628 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -1417,7 +1417,7 @@ cdef class WendlandQuinticC4_1D: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -1448,7 +1448,7 @@ cdef class WendlandQuinticC4_1D: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1476,7 +1476,7 @@ cdef class WendlandQuinticC4_1D: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC4_1DWrapper: """Reasonably high-performance convenience wrapper for Kernels. @@ -1520,7 +1520,7 @@ cdef class WendlandQuinticC6_1D: for key, value in kwargs.items(): setattr(self, key, value) - cdef inline double dwdq(self, double rij, double h): + cdef inline double dwdq(self, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1550,13 +1550,13 @@ cdef class WendlandQuinticC6_1D: cpdef double py_dwdq(self, double rij, double h): return self.dwdq(rij, h) - cdef inline double get_deltap(self): + cdef inline double get_deltap(self) noexcept nogil: return 0.47996698 cpdef double py_get_deltap(self): return self.get_deltap() - cdef inline void gradient(self, double* xij, double rij, double h, double* grad): + cdef inline void gradient(self, double* xij, double rij, double h, double* grad) noexcept nogil: cdef double h1 cdef double tmp cdef double wdash @@ -1575,7 +1575,7 @@ cdef class WendlandQuinticC6_1D: cpdef py_gradient(self, double[:] xij, double rij, double h, double[:] grad): self.gradient(&xij[0], rij, h, &grad[0]) - cdef inline double gradient_h(self, double* xij, double rij, double h): + cdef inline double gradient_h(self, double* xij, double rij, double h) noexcept nogil: cdef double dw cdef double fac cdef double h1 @@ -1608,7 +1608,7 @@ cdef class WendlandQuinticC6_1D: cpdef double py_gradient_h(self, double[:] xij, double rij, double h): return self.gradient_h(&xij[0], rij, h) - cdef inline double kernel(self, double* xij, double rij, double h): + cdef inline double kernel(self, double* xij, double rij, double h) noexcept nogil: cdef double fac cdef double h1 cdef double q @@ -1637,7 +1637,7 @@ cdef class WendlandQuinticC6_1D: cpdef double py_kernel(self, double[:] xij, double rij, double h): return self.kernel(&xij[0], rij, h) - + cdef class WendlandQuinticC6_1DWrapper: """Reasonably high-performance convenience wrapper for Kernels. diff --git a/pysph/base/c_kernels.pyx.mako b/pysph/base/c_kernels.pyx.mako index c505ee7d..626a47c7 100644 --- a/pysph/base/c_kernels.pyx.mako +++ b/pysph/base/c_kernels.pyx.mako @@ -1,7 +1,7 @@ # cython: embedsignature=True, language_level=3 # distutils: language=c++ <% -from compyle.api import CythonGenerator +from compyle.api import CythonGenerator, get_config from kernels import ( CubicSpline, WendlandQuintic, Gaussian, QuinticSpline, SuperGaussian, WendlandQuinticC4, WendlandQuinticC6, WendlandQuinticC2_1D, @@ -12,6 +12,7 @@ CLASSES = ( WendlandQuinticC4, WendlandQuinticC6, WendlandQuinticC2_1D, WendlandQuinticC4_1D, WendlandQuinticC6_1D ) +get_config().use_openmp = True; generator = CythonGenerator(python_methods=True) %> @@ -23,7 +24,7 @@ import numpy as np generator.parse(cls()) classname = cls.__name__ %> -${generator.get_code()} +${generator.get_code()} cdef class ${classname}Wrapper: """Reasonably high-performance convenience wrapper for Kernels. diff --git a/pysph/base/cell_indexing_nnps.pxd b/pysph/base/cell_indexing_nnps.pxd index bd68925d..5c932e18 100644 --- a/pysph/base/cell_indexing_nnps.pxd +++ b/pysph/base/cell_indexing_nnps.pxd @@ -1,4 +1,7 @@ -# cython: language_level=3, language=c++, embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.map cimport map from libcpp.pair cimport pair @@ -33,22 +36,22 @@ cdef class CellIndexingNNPS(NNPS): ########################################################################## cdef inline u_int _get_key(self, u_int n, u_int i, u_int j, - u_int k, int pa_index) nogil + u_int k, int pa_index) noexcept nogil - cdef inline int _get_id(self, u_int key, int pa_index) nogil + cdef inline int _get_id(self, u_int key, int pa_index) noexcept nogil - cdef inline int _get_x(self, u_int key, int pa_index) nogil + cdef inline int _get_x(self, u_int key, int pa_index) noexcept nogil - cdef inline int _get_y(self, u_int key, int pa_index) nogil + cdef inline int _get_y(self, u_int key, int pa_index) noexcept nogil - cdef inline int _get_z(self, u_int key, int pa_index) nogil + cdef inline int _get_z(self, u_int key, int pa_index) noexcept nogil cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z) nogil + int* x, int* y, int* z) noexcept nogil cpdef set_context(self, int src_index, int dst_index) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cpdef get_nearest_particles_no_cache(self, int src_index, int dst_index, size_t d_idx, UIntArray nbrs, bint prealloc) @@ -56,7 +59,7 @@ cdef class CellIndexingNNPS(NNPS): cpdef get_spatially_ordered_indices(self, int pa_index, LongArray indices) cdef void fill_array(self, NNPSParticleArrayWrapper pa_wrapper, int pa_index, - UIntArray indices, u_int* current_keys, key_to_idx_t* current_indices) nogil + UIntArray indices, u_int* current_keys, key_to_idx_t* current_indices) noexcept nogil cpdef _refresh(self) diff --git a/pysph/base/cell_indexing_nnps.pyx b/pysph/base/cell_indexing_nnps.pyx index bd6bf7f8..38cc87a4 100644 --- a/pysph/base/cell_indexing_nnps.pyx +++ b/pysph/base/cell_indexing_nnps.pyx @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free @@ -52,7 +53,7 @@ cdef class CellIndexingNNPS(NNPS): cdef NNPSParticleArrayWrapper pa_wrapper cdef int i, num_particles - for i from 0<=i self.pa_wrappers[i] num_particles = pa_wrapper.get_number_of_particles() @@ -80,7 +81,7 @@ cdef class CellIndexingNNPS(NNPS): def __dealloc__(self): cdef int i - for i from 0<=i self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -152,16 +153,16 @@ cdef class CellIndexingNNPS(NNPS): cdef map[u_int, pair[u_int, u_int]].iterator it - cdef int x_boxes[27] - cdef int y_boxes[27] - cdef int z_boxes[27] + cdef int [27]x_boxes + cdef int [27]y_boxes + cdef int [27]z_boxes cdef int num_boxes = self._neighbor_boxes(c_x, c_y, c_z, x_boxes, y_boxes, z_boxes) cdef pair[u_int, u_int] candidate cdef u_int n, idx - for i from 0<=iself._get_id(current_keys[j], pa_index)) cdef void fill_array(self, NNPSParticleArrayWrapper pa_wrapper, int pa_index, - UIntArray indices, u_int* current_keys, key_to_idx_t* current_indices) nogil: + UIntArray indices, u_int* current_keys, key_to_idx_t* current_indices) noexcept nogil: cdef double* x_ptr = pa_wrapper.x.data cdef double* y_ptr = pa_wrapper.y.data cdef double* z_ptr = pa_wrapper.z.data @@ -240,7 +241,7 @@ cdef class CellIndexingNNPS(NNPS): cdef int i, n cdef int c_x, c_y, c_z - for i from 0<=i> self.I[pa_index]) % (1 << self.J) @cython.cdivision(True) - cdef inline int _get_y(self, u_int key, int pa_index) nogil: + cdef inline int _get_y(self, u_int key, int pa_index) noexcept nogil: return (key >> (self.I[pa_index] + self.J)) % (1 << self.K) @cython.cdivision(True) - cdef inline int _get_z(self, u_int key, int pa_index) nogil: + cdef inline int _get_z(self, u_int key, int pa_index) noexcept nogil: return key >> (self.I[pa_index] + self.J + self.K) cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z) nogil: + int* x, int* y, int* z) noexcept nogil: cdef int length = 0 cdef int p, q, r - for p from -1<=p<2: - for q from -1<=q<2: - for r from -1<=r<2: + for p in range(-1, 2): + for q in range(-1, 2): + for r in range(-1, 2): if i+r>=0 and j+q>=0 and k+p>=0: x[length] = i+r y[length] = j+q @@ -343,7 +344,7 @@ cdef class CellIndexingNNPS(NNPS): self.J = (1 + log2(ceil((xmax[0] - xmin[0])/self.cell_size))) self.K = (1 + log2(ceil((xmax[1] - xmin[1])/self.cell_size))) - for i from 0<=ib else b -cdef inline double SQR(double a) nogil: +cdef inline double SQR(double a) noexcept nogil: return a*a -cdef inline double hypot2(double x, double y) nogil: +cdef inline double hypot2(double x, double y) noexcept nogil: return sqrt(x*x+y*y) -cdef double det(double a[3][3]) nogil: +cdef double det(double [3][3]a) noexcept nogil: '''Determinant of symmetrix matrix ''' return (a[0][0]*a[1][1]*a[2][2] + 2*a[1][2]*a[0][2]*a[0][1] - @@ -46,12 +47,12 @@ cpdef double py_det(double[:,:] m): # d:11,22,33; s:23,13,12 # d:00,11,22; s:12,02,01 -cdef void get_eigenvalues(double a[3][3], double *result) nogil: +cdef void get_eigenvalues(double [3][3]a, double *result) noexcept nogil: '''Compute the eigenvalues of symmetric matrix a and return in result array. ''' cdef double m = (a[0][0]+ a[1][1]+a[2][2])/3.0 - cdef double K[3][3] + cdef double [3][3]K memcpy(&K[0][0], &a[0][0], sizeof(double)*9) K[0][0], K[1][1], K[2][2] = a[0][0] - m, a[1][1] - m, a[2][2] - m cdef double q = det(K)*0.5 @@ -89,7 +90,7 @@ cpdef py_get_eigenvalues(double[:,:] m): ############################################################################## -cdef void get_eigenvector_np(double A[n][n], double r, double *res): +cdef void get_eigenvector_np(double [n][n]A, double r, double *res): ''' eigenvector of symmetric matrix for given eigenvalue `r` using numpy ''' cdef numpy.ndarray[ndim=2, dtype=numpy.float64_t] mat=numpy.empty((3,3)), evec @@ -109,7 +110,7 @@ cdef void get_eigenvector_np(double A[n][n], double r, double *res): for i in range(3): res[i] = evec[idx,i] -cdef void get_eigenvector(double A[n][n], double r, double *res): +cdef void get_eigenvector(double [n][n]A, double r, double *res): ''' get eigenvector of symmetric 3x3 matrix for given eigenvalue `r` uses a fast method to get eigenvectors with a fallback to using numpy @@ -134,22 +135,22 @@ cpdef py_get_eigenvector(double[:,:] A, double r): get_eigenvector(&A[0,0], r, &_d[0]) return d -cdef void get_eigenvec_from_val(double A[n][n], double *R, double *e): +cdef void get_eigenvec_from_val(double [n][n]A, double *R, double *e): cdef int i, j - cdef double res[3] + cdef double [3]res for i in range(3): get_eigenvector(A, e[i], &res[0]) for j in range(3): R[j*3+i] = res[j] -cdef bint _nearly_diagonal(double A[n][n]) nogil: +cdef bint _nearly_diagonal(double [n][n]A) noexcept nogil: return ( (SQR(A[0][0]) + SQR(A[1][1]) + SQR(A[2][2])) > 1e8*(SQR(A[0][1]) + SQR(A[0][2]) + SQR(A[1][2])) ) -cdef void get_eigenvalvec(double A[n][n], double *R, double *e): +cdef void get_eigenvalvec(double [n][n]A, double *R, double *e): '''Get the eigenvalues and eigenvectors of symmetric 3x3 matrix. A is the input 3x3 matrix. @@ -194,7 +195,7 @@ def py_get_eigenvalvec(double[:,:] A): ############################################################################## -cdef void transform(double A[3][3], double P[3][3], double res[3][3]) nogil: +cdef void transform(double [3][3]A, double [3][3]P, double [3][3]res) noexcept nogil: '''Compute the transformation P.T*A*P and add it into res. ''' cdef int i, j, k, l @@ -204,8 +205,8 @@ cdef void transform(double A[3][3], double P[3][3], double res[3][3]) nogil: for l in range(3): res[i][j] += P[k][i]*A[k][l]*P[l][j] # P.T*A*P -cdef void transform_diag(double *A, double P[3][3], - double res[3][3]) nogil: +cdef void transform_diag(double *A, double [3][3]P, + double [3][3]res) noexcept nogil: '''Compute the transformation P.T*A*P and add it into res. A is diagonal and contains the diagonal entries alone. @@ -216,8 +217,8 @@ cdef void transform_diag(double *A, double P[3][3], for k in range(3): res[i][j] += P[k][i]*A[k]*P[k][j] # P.T*A*P -cdef void transform_diag_inv(double *A, double P[3][3], - double res[3][3]) nogil: +cdef void transform_diag_inv(double *A, double [3][3]P, + double [3][3]res) noexcept nogil: '''Compute the transformation P*A*P.T and set it into res. A is diagonal and contains just the diagonal entries. ''' @@ -257,7 +258,7 @@ def py_transform_diag_inv(double[:] A, double[:,:] P): return res -cdef double * tred2(double V[n][n], double *d, double *e) nogil: +cdef double * tred2(double [n][n]V, double *d, double *e) noexcept nogil: '''Symmetric Householder reduction to tridiagonal form This is derived from the Algol procedures tred2 by @@ -376,7 +377,7 @@ cdef double * tred2(double V[n][n], double *d, double *e) nogil: return d -cdef void tql2(double V[n][n], double *d, double *e) nogil: +cdef void tql2(double [n][n]V, double *d, double *e) noexcept nogil: '''Symmetric tridiagonal QL algo for eigendecomposition This is derived from the Algol procedures tql2, by @@ -492,18 +493,18 @@ cdef void tql2(double V[n][n], double *d, double *e) nogil: V[j][k] = p -cdef void zero_matrix_case(double V[n][n], double *d) nogil: +cdef void zero_matrix_case(double [n][n]V, double *d) noexcept nogil: cdef int i, j for i in range(3): d[i] = 0.0 for j in range(3): V[i][j] = (i==j) -cdef void eigen_decomposition(double A[n][n], double V[n][n], double *d) nogil: +cdef void eigen_decomposition(double [n][n]A, double [n][n]V, double *d) noexcept nogil: '''Get eigenvalues and eigenvectors of matrix A. V is output eigenvectors and d are the eigenvalues. ''' - cdef double e[n] + cdef double [n]e cdef int i, j # Scale the matrix, as if the matrix is tiny, floating point errors # creep up leading to zero division errors in tql2. This is diff --git a/pysph/base/linked_list_nnps.pxd b/pysph/base/linked_list_nnps.pxd index b6211a8e..a4015010 100644 --- a/pysph/base/linked_list_nnps.pxd +++ b/pysph/base/linked_list_nnps.pxd @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION from libcpp.map cimport map from libcpp.vector cimport vector @@ -24,5 +25,5 @@ cdef class LinkedListNNPS(NNPS): cpdef long _get_number_of_cells(self) except -1 cdef long _get_flattened_cell_index(self, cPoint pnt, double cell_size) cdef long _get_valid_cell_index(self, int cid_x, int cid_y, int cid_z, - int* ncells_per_dim, int dim, int n_cells) nogil - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + int* ncells_per_dim, int dim, int n_cells) noexcept nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil diff --git a/pysph/base/linked_list_nnps.pyx b/pysph/base/linked_list_nnps.pyx index 7ef842e5..2c3ff11f 100644 --- a/pysph/base/linked_list_nnps.pyx +++ b/pysph/base/linked_list_nnps.pyx @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + # Library imports. import numpy as np cimport numpy as np @@ -87,7 +89,7 @@ cdef class LinkedListNNPS(NNPS): #### Public protocol ################################################ - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -326,7 +328,7 @@ cdef class LinkedListNNPS(NNPS): @cython.boundscheck(False) @cython.wraparound(False) cdef long _get_valid_cell_index(self, int cid_x, int cid_y, int cid_z, - int* ncells_per_dim, int dim, int n_cells) nogil: + int* ncells_per_dim, int dim, int n_cells) noexcept nogil: return get_valid_cell_index( cid_x, cid_y, cid_z, ncells_per_dim, dim, n_cells ) diff --git a/pysph/base/nnps.py b/pysph/base/nnps.py index aea2687f..8e0d2efe 100644 --- a/pysph/base/nnps.py +++ b/pysph/base/nnps.py @@ -1,6 +1,5 @@ from pysph.base.nnps_base import get_number_of_threads, py_flatten, \ py_unflatten, py_get_valid_cell_index - from pysph.base.nnps_base import NNPSParticleArrayWrapper, CPUDomainManager, \ DomainManager, Cell, NeighborCache, NNPSBase, NNPS from pysph.base.linked_list_nnps import LinkedListNNPS diff --git a/pysph/base/nnps_base.pxd b/pysph/base/nnps_base.pxd index 6371dd03..cbb8c8c7 100644 --- a/pysph/base/nnps_base.pxd +++ b/pysph/base/nnps_base.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + # numpy cimport numpy as np cimport cython @@ -30,11 +32,11 @@ cdef extern from 'limits.h': ctypedef unsigned int ZOLTAN_ID_TYPE ctypedef unsigned int* ZOLTAN_ID_PTR -cdef inline double norm2(double x, double y, double z) nogil: +cdef inline double norm2(double x, double y, double z) noexcept nogil: return x*x + y*y + z*z @cython.cdivision(True) -cdef inline int real_to_int(double real_val, double step) nogil: +cdef inline int real_to_int(double real_val, double step) noexcept nogil: """ Return the bin index to which the given position belongs. Parameters @@ -54,7 +56,7 @@ cdef inline int real_to_int(double real_val, double step) nogil: return ret_val cdef inline void find_cell_id_raw(double x, double y, double z, double - cell_size, int *ix, int *iy, int *iz) nogil: + cell_size, int *ix, int *iy, int *iz) noexcept nogil: """ Find the cell index for the corresponding point Parameters @@ -80,7 +82,7 @@ cdef inline void find_cell_id_raw(double x, double y, double z, double @cython.boundscheck(False) @cython.wraparound(False) cdef inline long flatten_raw(int x, int y, int z, int* ncells_per_dim, - int dim) nogil: + int dim) noexcept nogil: """Return a flattened index for a cell The flattening is determined using the row-order indexing commonly @@ -96,7 +98,7 @@ cdef inline long flatten_raw(int x, int y, int z, int* ncells_per_dim, @cython.boundscheck(False) @cython.wraparound(False) -cdef inline long flatten(cIntPoint cid, IntArray ncells_per_dim, int dim) nogil: +cdef inline long flatten(cIntPoint cid, IntArray ncells_per_dim, int dim) noexcept nogil: """Return a flattened index for a cell The flattening is determined using the row-order indexing commonly @@ -109,7 +111,7 @@ cdef inline long flatten(cIntPoint cid, IntArray ncells_per_dim, int dim) nogil: @cython.boundscheck(False) @cython.wraparound(False) cdef inline long get_valid_cell_index(int cid_x, int cid_y, int cid_z, - int* ncells_per_dim, int dim, int n_cells) nogil: + int* ncells_per_dim, int dim, int n_cells) noexcept nogil: """Return the flattened index for a valid cell""" cdef long ncx = ncells_per_dim[0] cdef long ncy = ncells_per_dim[1] @@ -136,8 +138,6 @@ cdef cIntPoint find_cell_id(cPoint pnt, double cell_size) cpdef UIntArray arange_uint(int start, int stop=*) -cpdef int get_number_of_threads() - # Basic particle array wrapper used for NNPS cdef class NNPSParticleArrayWrapper: cdef public DoubleArray x,y,z,h @@ -268,13 +268,13 @@ cdef class NeighborCache: cdef public list _neighbor_arrays cdef int _last_avg_nbr_size - cdef void get_neighbors_raw(self, size_t d_idx, UIntArray nbrs) nogil + cdef void get_neighbors_raw(self, size_t d_idx, UIntArray nbrs) noexcept nogil cpdef get_neighbors(self, int src_index, size_t d_idx, UIntArray nbrs) cpdef find_all_neighbors(self) cpdef update(self) cdef void _update_last_avg_nbr_size(self) - cdef void _find_neighbors(self, long d_idx) nogil + cdef void _find_neighbors(self, long d_idx) noexcept nogil cdef class NNPSBase: ########################################################################## @@ -305,7 +305,7 @@ cdef class NNPSBase: cpdef get_nearest_particles_no_cache(self, int src_index, int dst_index, size_t d_idx, UIntArray nbrs, bint prealloc) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cpdef get_nearest_particles(self, int src_index, int dst_index, size_t d_idx, UIntArray nbrs) @@ -336,15 +336,15 @@ cdef class NNPS(NNPSBase): cpdef _bin(self, int pa_index, UIntArray indices) cdef void _sort_neighbors(self, unsigned int* nbrs, size_t length, - unsigned int *gids) nogil + unsigned int *gids) noexcept nogil # compute the min and max for the particle coordinates cdef _compute_bounds(self) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cdef void get_nearest_neighbors(self, size_t d_idx, - UIntArray nbrs) nogil + UIntArray nbrs) noexcept nogil # Neighbor query function. Returns the list of neighbors for a # requested particle. The returned list is assumed to be of type diff --git a/pysph/base/nnps_base.pyx b/pysph/base/nnps_base.pyx index 0e147e90..ea31a2ae 100644 --- a/pysph/base/nnps_base.pyx +++ b/pysph/base/nnps_base.pyx @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + # Library imports. import numpy as np cimport numpy as np @@ -30,23 +32,6 @@ from compyle.array import get_backend, Array from compyle.parallel import Elementwise from compyle.types import annotate - -IF OPENMP: - cimport openmp - cpdef int get_number_of_threads(): - cdef int i, n - with nogil, parallel(): - for i in prange(1): - n = openmp.omp_get_num_threads() - return n - cpdef set_number_of_threads(int n): - openmp.omp_set_num_threads(n) -ELSE: - cpdef int get_number_of_threads(): - return 1 - cpdef set_number_of_threads(int n): - print("OpenMP not available, cannot set number of threads.") - # Particle Tag information from cyarray.carray cimport BaseArray, aligned_malloc, aligned_free from .utils import ParticleTAGS @@ -57,8 +42,14 @@ cdef int Ghost = ParticleTAGS.Ghost ctypedef pair[unsigned int, unsigned int] id_gid_pair_t +try: + from .omp_threads import get_number_of_threads + from .omp_threads import set_number_of_threads +except ImportError: + from .no_omp_threads import get_number_of_threads + from .no_omp_threads import set_number_of_threads -cdef inline bint _compare_gids(id_gid_pair_t x, id_gid_pair_t y) nogil: +cdef inline bint _compare_gids(id_gid_pair_t x, id_gid_pair_t y) noexcept nogil: return y.second > x.second def py_flatten(IntPoint cid, IntArray ncells_per_dim, int dim): @@ -533,7 +524,7 @@ cdef class CPUDomainManager(DomainManagerBase): # mirror domain values cdef double xmin = self.xmin, xmax = self.xmax - cdef double ymin = self.ymin, ymax = self.ymax, + cdef double ymin = self.ymin, ymax = self.ymax cdef double zmin = self.zmin, zmax = self.zmax # mirror boundary condition flags @@ -779,7 +770,7 @@ cdef class CPUDomainManager(DomainManagerBase): # periodic domain values cdef double xmin = self.xmin, xmax = self.xmax - cdef double ymin = self.ymin, ymax = self.ymax, + cdef double ymin = self.ymin, ymax = self.ymax cdef double zmin = self.zmin, zmax = self.zmax cdef double xtranslate = self.xtranslate @@ -1193,7 +1184,7 @@ cdef class NeighborCache: #### Public protocol ################################################ - cdef void get_neighbors_raw(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void get_neighbors_raw(self, size_t d_idx, UIntArray nbrs) noexcept nogil: if self._cached.data[d_idx] == 0: self._find_neighbors(d_idx) cdef size_t start, end, tid @@ -1253,7 +1244,7 @@ cdef class NeighborCache: if total > 0 and np > 0: self._last_avg_nbr_size = int(total/np) + 1 - cdef void _find_neighbors(self, long d_idx) nogil: + cdef void _find_neighbors(self, long d_idx) noexcept nogil: cdef int thread_id = threadid() self._pid_to_tid.data[d_idx] = thread_id self._start_stop.data[d_idx*2] = \ @@ -1402,7 +1393,7 @@ cdef class NNPSBase: self.find_nearest_neighbors(d_idx, nbrs) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: # Implement this in the subclass to actually do something useful. pass @@ -1518,7 +1509,7 @@ cdef class NNPS(NNPSBase): for cache in self.cache: cache.update() - cdef void get_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void get_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: if self.use_cache: self.current_cache.get_neighbors_raw(d_idx, nbrs) else: @@ -1584,7 +1575,7 @@ cdef class NNPS(NNPSBase): self.xmax.set_data(np.asarray([xmax, ymax, zmax])) cdef void _sort_neighbors(self, unsigned int* nbrs, size_t length, - unsigned int *gids) nogil: + unsigned int *gids) noexcept nogil: if length == 0: return cdef id_gid_pair_t _entry diff --git a/pysph/base/no_omp_threads.pxd b/pysph/base/no_omp_threads.pxd new file mode 100644 index 00000000..d9544186 --- /dev/null +++ b/pysph/base/no_omp_threads.pxd @@ -0,0 +1,6 @@ +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + +cpdef int get_number_of_threads() +cpdef set_number_of_threads(int) \ No newline at end of file diff --git a/pysph/base/no_omp_threads.pyx b/pysph/base/no_omp_threads.pyx new file mode 100644 index 00000000..b2bef1d6 --- /dev/null +++ b/pysph/base/no_omp_threads.pyx @@ -0,0 +1,10 @@ +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + +cpdef int get_number_of_threads(): + return 1 + +cpdef set_number_of_threads(int n): + print("OpenMP not available, cannot set number of threads.") + diff --git a/pysph/base/octree.pxd b/pysph/base/octree.pxd index 1fb6b8c7..0d5592d6 100644 --- a/pysph/base/octree.pxd +++ b/pysph/base/octree.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from .nnps_base cimport * from libcpp.vector cimport vector cimport cython @@ -77,33 +79,33 @@ cdef class Octree: cdef public bint test_parallel cdef double machine_eps - cdef double xmin[3] - cdef double xmax[3] + cdef double [3]xmin + cdef double [3]xmax ########################################################################## # Member functions ########################################################################## - cdef inline double _get_eps(self, double length, double* xmin) nogil + cdef inline double _get_eps(self, double length, double* xmin) noexcept nogil cdef inline void _calculate_domain(self, NNPSParticleArrayWrapper pa) cdef inline cOctreeNode* _new_node(self, double* xmin, double length, double hmax = *, int level = *, cOctreeNode* parent = *, - int num_particles = *, bint is_leaf = *) nogil + int num_particles = *, bint is_leaf = *) noexcept nogil cdef inline void _delete_tree(self, cOctreeNode* node) cdef int _c_build_tree(self, NNPSParticleArrayWrapper pa, vector[u_int]* indices, double* xmin, double length, - cOctreeNode* node, int level) nogil + cOctreeNode* node, int level) noexcept nogil cdef int _c_build_tree_level1(self, NNPSParticleArrayWrapper pa, - double* xmin, double length, cOctreeNode* node, int num_threads) nogil + double* xmin, double length, cOctreeNode* node, int num_threads) noexcept nogil cdef int _c_build_tree_bfs(self, NNPSParticleArrayWrapper pa, u_int* p_indices, vector[cOctreeNode *]* level_nodes, - int level, int num_threads) nogil + int level, int num_threads) noexcept nogil cdef void _plot_tree(self, OctreeNode node, ax) @@ -139,7 +141,7 @@ cdef class CompressedOctree(Octree): cdef int _c_build_tree(self, NNPSParticleArrayWrapper pa, vector[u_int]* indices, double* xmin, double length, - cOctreeNode* node, int level) nogil + cOctreeNode* node, int level) noexcept nogil cdef int c_build_tree(self, NNPSParticleArrayWrapper pa_wrapper, bint test_parallel = *) diff --git a/pysph/base/octree.pyx b/pysph/base/octree.pyx index 5960a49f..e70fc480 100644 --- a/pysph/base/octree.pyx +++ b/pysph/base/octree.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION from .nnps_base cimport * @@ -25,10 +27,17 @@ cdef extern from *: #define START_OMP_SINGLE_PRAGMA() _Pragma("omp single") { #define START_OMP_BARRIER_PRAGMA() _Pragma("omp barrier") { """ - void START_OMP_PARALLEL_PRAGMA() nogil - void END_OMP_PRAGMA() nogil - void START_OMP_SINGLE_PRAGMA() nogil - void START_OMP_BARRIER_PRAGMA() nogil + void START_OMP_PARALLEL_PRAGMA() noexcept nogil + void END_OMP_PRAGMA() noexcept nogil + void START_OMP_SINGLE_PRAGMA() noexcept nogil + void START_OMP_BARRIER_PRAGMA() noexcept nogil + +try: + from .omp_threads import get_number_of_threads + from .omp_threads import set_number_of_threads +except ImportError: + from .no_omp_threads import get_number_of_threads + from .no_omp_threads import set_number_of_threads ######################################################################## @@ -55,7 +64,7 @@ cdef class OctreeNode: equal_length = (self.length == other.length) cdef int i - for i from 0<=i<3: + for i in range(3): if self.xmin[i] != other.xmin[i]: equal_xmin = False @@ -133,7 +142,7 @@ cdef class OctreeNode: cdef int i cdef list py_children = [None for i in range(8)] cdef OctreeNode py_node - for i from 0<=i<8: + for i in range(8): if self._node.children[i] != NULL: py_node = OctreeNode() py_node.wrap_node(self._node.children[i]) @@ -157,29 +166,29 @@ cdef class OctreeNode: cdef double x, y, z cdef list ax_points = [0,0] - for i from 0<=i<2: - for j from 0<=j<2: + for i in range(2): + for j in range(2): x = self.xmin[0] + i*self.length y = self.xmin[1] + j*self.length - for k from 0<=k<2: + for k in range(2): ax_points[k] = self.xmin[2] + k*self.length ax.plot([x,x], [y,y], zs=ax_points[:], color=color) - for i from 0<=i<2: - for k from 0<=k<2: + for i in range(2): + for k in range(2): x = self.xmin[0] + i*self.length z = self.xmin[2] + k*self.length - for j from 0<=j<2: + for j in range(2): ax_points[j] = self.xmin[1] + j*self.length ax.plot([x,x], ax_points[:], zs=[z,z], color=color) - for j from 0<=j<2: - for k from 0<=k<2: + for j in range(2): + for k in range(2): y = self.xmin[1] + j*self.length z = self.xmin[2] + k*self.length - for i from 0<=i<2: + for i in range(2): ax_points[i] = self.xmin[0] + i*self.length ax.plot(ax_points[:], [y,y], zs=[z,z], color=color) @@ -205,7 +214,7 @@ cdef class Octree: #### Private protocol ################################################ @cython.cdivision(True) - cdef inline double _get_eps(self, double length, double* xmin) nogil: + cdef inline double _get_eps(self, double length, double* xmin) noexcept nogil: return (self.machine_eps/length)*fmax(length, fmax(fmax(fabs(xmin[0]), fabs(xmin[1])), fabs(xmin[2]))) @@ -240,7 +249,7 @@ cdef class Octree: cdef inline cOctreeNode* _new_node(self, double* xmin, double length, double hmax = 0, int level = 0, cOctreeNode* parent = NULL, - int num_particles = 0, bint is_leaf = False) nogil: + int num_particles = 0, bint is_leaf = False) noexcept nogil: """Create a new cOctreeNode""" cdef cOctreeNode* node = malloc(sizeof(cOctreeNode)) @@ -259,7 +268,7 @@ cdef class Octree: cdef int i - for i from 0<=i<8: + for i in range(8): node.children[i] = NULL return node @@ -269,12 +278,12 @@ cdef class Octree: cdef int i cdef cOctreeNode* temp[8] - for i from 0<=i<8: + for i in range(8): temp[i] = node.children[i] free(node) - for i from 0<=i<8: + for i in range(8): if temp[i] == NULL: continue self._delete_tree(temp[i]) @@ -282,7 +291,7 @@ cdef class Octree: @cython.cdivision(True) cdef int _c_build_tree(self, NNPSParticleArrayWrapper pa, vector[u_int]* indices, double* xmin, double length, - cOctreeNode* node, int level) nogil: + cOctreeNode* node, int level) noexcept nogil: cdef double* src_x_ptr = pa.x.data cdef double* src_y_ptr = pa.y.data cdef double* src_z_ptr = pa.z.data @@ -296,7 +305,7 @@ cdef class Octree: cdef int i, j, k cdef u_int p, q - for i from 0<=i<8: + for i in range(8): hmax_children[i] = 0 cdef int oct_id @@ -315,10 +324,10 @@ cdef class Octree: return 1 cdef vector[u_int]* new_indices[8] - for i from 0<=i<8: + for i in range(8): new_indices[i] = new vector[u_int]() - for p from 0<=p EPS_MAX): - for i from 0<=i 0): - for i from 0<=i<8: + for i in range(8): new_indices[i] = vector[u_int]() children = 0 - for n from 0<=npy_leaf_cells[i]).wrap_node(deref(self.leaf_cells)[i]) return py_leaf_cells @@ -838,7 +847,7 @@ cdef class CompressedOctree(Octree): @cython.cdivision(True) cdef int _c_build_tree(self, NNPSParticleArrayWrapper pa, vector[u_int]* indices, double* xmin, double length, - cOctreeNode* node, int level) nogil: + cOctreeNode* node, int level) noexcept nogil: cdef double* src_x_ptr = pa.x.data cdef double* src_y_ptr = pa.y.data @@ -856,9 +865,9 @@ cdef class CompressedOctree(Octree): cdef int i, j, k cdef u_int p, q - for i from 0<=i<8: + for i in range(8): hmax_children[i] = 0 - for j from 0<=j<3: + for j in range(3): xmin_new[i][j] = self.dbl_max xmax_new[i][j] = -self.dbl_max @@ -874,13 +883,13 @@ cdef class CompressedOctree(Octree): return 1 cdef vector[u_int]* new_indices[8] - for i from 0<=i<8: + for i in range(8): new_indices[i] = new vector[u_int]() cdef double* xmin_current cdef double* xmax_current - for p from 0<=p malloc(3 * sizeof(double)) xmax_new[i] = malloc(3 * sizeof(double)) tid = threadid() while(count[num_threads]>0): - for i from 0<=i<8: + for i in range(8): new_indices[i] = vector[u_int]() children = 0 - for n from 0<=n self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -104,7 +106,7 @@ cdef class OctreeNNPS(NNPS): @cython.cdivision(True) cdef void _get_neighbors(self, double q_x, double q_y, double q_z, double q_h, double* src_x_ptr, double* src_y_ptr, double* src_z_ptr, double* src_h_ptr, - UIntArray nbrs, cOctreeNode* node) nogil: + UIntArray nbrs, cOctreeNode* node) noexcept nogil: """Find neighbors recursively""" cdef double x_centre = node.xmin[0] + node.length/2 cdef double y_centre = node.xmin[1] + node.length/2 @@ -124,7 +126,7 @@ cdef class OctreeNNPS(NNPS): return if node.is_leaf: - for i from 0<=iself.tree[pa_index]).pids cdef int i - for i from 0<=icurrent_pids[i]) cpdef _refresh(self): cdef int i - for i from 0<=iself.tree[i]).c_build_tree(self.pa_wrappers[i], self.tree[i].test_parallel) self.current_tree = (self.tree[self.src_index]).root self.current_pids = (self.tree[self.src_index]).pids @@ -221,7 +223,7 @@ cdef class CompressedOctreeNNPS(OctreeNNPS): cpdef _refresh(self): cdef int i - for i from 0<=iself.tree[i]).c_build_tree(self.pa_wrappers[i], self.tree[i].test_parallel) self.current_tree = (self.tree[self.src_index]).root diff --git a/pysph/base/omp_threads.pxd b/pysph/base/omp_threads.pxd new file mode 100644 index 00000000..d9544186 --- /dev/null +++ b/pysph/base/omp_threads.pxd @@ -0,0 +1,6 @@ +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + +cpdef int get_number_of_threads() +cpdef set_number_of_threads(int) \ No newline at end of file diff --git a/pysph/base/omp_threads.pyx b/pysph/base/omp_threads.pyx new file mode 100644 index 00000000..83233e12 --- /dev/null +++ b/pysph/base/omp_threads.pyx @@ -0,0 +1,17 @@ +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + +from cython.parallel import parallel, prange +cimport openmp + + +cpdef int get_number_of_threads(): + cdef int i, n + with nogil, parallel(): + for i in prange(1): + n = openmp.omp_get_num_threads() + return n + +cpdef set_number_of_threads(int n): + openmp.omp_set_num_threads(n) \ No newline at end of file diff --git a/pysph/base/particle_array.pxd b/pysph/base/particle_array.pxd index 98c7bacc..16854b1d 100644 --- a/pysph/base/particle_array.pxd +++ b/pysph/base/particle_array.pxd @@ -1,4 +1,7 @@ -# cython: language_level=3, language=c++, embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + cimport numpy as np from cyarray.carray cimport BaseArray, UIntArray, IntArray, LongArray diff --git a/pysph/base/particle_array.pyx b/pysph/base/particle_array.pyx index 43df0efc..b19a9611 100644 --- a/pysph/base/particle_array.pyx +++ b/pysph/base/particle_array.pyx @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + """ A `ParticleArray` represents a collection of particles. diff --git a/pysph/base/point.pxd b/pysph/base/point.pxd index 0c25fe20..4fddd20a 100644 --- a/pysph/base/point.pxd +++ b/pysph/base/point.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + cimport numpy cdef extern from "math.h": diff --git a/pysph/base/point.pyx b/pysph/base/point.pyx index 8d8431c2..f953ff4f 100644 --- a/pysph/base/point.pyx +++ b/pysph/base/point.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION """A handy set of classes/functions for 3D points. """ @@ -27,23 +29,27 @@ cdef class Point: # Declared in the .pxd file. #cdef public double x, y, z - property x: - def __get__(Point self): - return self.data.x - def __set__(Point self, double x): - self.data.x = x + @property + def x(Point self): + return self.data.x + @x.setter + def x(Point self, double x): + self.data.x = x + + @property + def y(Point self): + return self.data.y + @y.setter + def y(Point self, double y): + self.data.y = y - property y: - def __get__(Point self): - return self.data.y - def __set__(Point self, double y): - self.data.y = y - property z: - def __get__(Point self): - return self.data.z - def __set__(Point self, double z): - self.data.z = z + @property + def z(Point self): + return self.data.z + @z.setter + def z(Point self, double z): + self.data.z = z ###################################################################### # `object` interface. @@ -191,17 +197,15 @@ cdef class Point: cdef class IntPoint: - property x: - def __get__(self): - return self.data.x - - property y: - def __get__(self): - return self.data.y - - property z: - def __get__(self): - return self.data.z + @property + def x(self): + return self.data.x + @property + def y(self): + return self.data.y + @property + def z(self): + return self.data.z def __init__(self, int x=0, int y=0, int z=0): self.data.x = x @@ -234,8 +238,8 @@ cdef class IntPoint: return IntPoint_new(self.data.x, self.data.y, self.data.z) cpdef numpy.ndarray asarray(self): - cdef numpy.ndarray[ndim=1,dtype=numpy.int_t] arr = numpy.empty(3, - dtype=numpy.int) + cdef numpy.ndarray[ndim=1,dtype=int] arr = numpy.empty(3, + dtype=int) arr[0] = self.data.x arr[1] = self.data.y arr[2] = self.data.z diff --git a/pysph/base/spatial_hash_nnps.pxd b/pysph/base/spatial_hash_nnps.pxd index c37d95e2..bd3819f2 100644 --- a/pysph/base/spatial_hash_nnps.pxd +++ b/pysph/base/spatial_hash_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.vector cimport vector from .nnps_base cimport * @@ -9,12 +11,12 @@ cdef extern from "spatial_hash.h": cdef cppclass HashEntry: double h_max - vector[unsigned int] *get_indices() nogil + vector[unsigned int] *get_indices() noexcept nogil cdef cppclass HashTable: - HashTable(long long int) nogil except + - void add(int, int, int, int, double) nogil - HashEntry* get(int, int, int) nogil + HashTable(long long int) except + nogil + void add(int, int, int, int, double) noexcept nogil + HashEntry* get(int, int, int) noexcept nogil # NNPS using Spatial Hashing algorithm cdef class SpatialHashNNPS(NNPS): @@ -35,13 +37,13 @@ cdef class SpatialHashNNPS(NNPS): cpdef set_context(self, int src_index, int dst_index) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cdef inline void _add_to_hashtable(self, int hash_id, unsigned int pid, double h, - int i, int j, int k) nogil + int i, int j, int k) noexcept nogil cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z) nogil + int* x, int* y, int* z) noexcept nogil cpdef _refresh(self) @@ -70,17 +72,17 @@ cdef class ExtendedSpatialHashNNPS(NNPS): cpdef set_context(self, int src_index, int dst_index) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil - cdef inline int _h_mask_approx(self, int* x, int* y, int* z) nogil + cdef inline int _h_mask_approx(self, int* x, int* y, int* z) noexcept nogil - cdef inline int _h_mask_exact(self, int* x, int* y, int* z) nogil + cdef inline int _h_mask_exact(self, int* x, int* y, int* z) noexcept nogil cdef int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z, double h) nogil + int* x, int* y, int* z, double h) noexcept nogil cdef inline void _add_to_hashtable(self, int hash_id, unsigned int pid, double h, - int i, int j, int k) nogil + int i, int j, int k) noexcept nogil cpdef _refresh(self) diff --git a/pysph/base/spatial_hash_nnps.pyx b/pysph/base/spatial_hash_nnps.pyx index 9878dda3..1d99b98a 100644 --- a/pysph/base/spatial_hash_nnps.pyx +++ b/pysph/base/spatial_hash_nnps.pyx @@ -1,5 +1,6 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free @@ -47,14 +48,14 @@ cdef class SpatialHashNNPS(NNPS): self.hashtable = malloc(narrays*sizeof(HashTable*)) cdef int i - for i from 0<=i self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -120,9 +121,9 @@ cdef class SpatialHashNNPS(NNPS): ) cdef int candidate_size = 0 - cdef int x_boxes[27] - cdef int y_boxes[27] - cdef int z_boxes[27] + cdef int [27]x_boxes + cdef int [27]y_boxes + cdef int [27]z_boxes cdef int num_boxes = self._neighbor_boxes(c_x, c_y, c_z, x_boxes, y_boxes, z_boxes) @@ -130,13 +131,13 @@ cdef class SpatialHashNNPS(NNPS): cdef double hi2 = self.radius_scale2*h*h cdef double hj2 = 0 - for i from 0<=i=0 and j+q>=0 and k+r>=0: x[length] = i+p y[length] = j+q @@ -175,7 +176,7 @@ cdef class SpatialHashNNPS(NNPS): cpdef _refresh(self): cdef int i - for i from 0<=i malloc(narrays*sizeof(HashTable*)) cdef int i - for i from 0<=i self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -339,13 +340,13 @@ cdef class ExtendedSpatialHashNNPS(NNPS): cdef double hi2 = self.radius_scale2*h*h cdef double hj2 = 0 - for i from 0<=i malloc(narrays*sizeof(double*)) cdef int i, j - for i from 0<=i malloc(self.num_levels*sizeof(HashTable*)) self.cell_sizes[i] = malloc(self.num_levels*sizeof(double)) current_hash = self.hashtable[i] - for j from 0<=j self.pa_wrappers[src_index] @cython.cdivision(True) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -158,7 +160,7 @@ cdef class StratifiedHashNNPS(NNPS): cdef double hmax_level - for i from 0<=i floor((self.radius_scale*h - self.hmin)/self.interval_size) - cdef inline double _get_h_max(self, double* current_cells, int hash_id) nogil: + cdef inline double _get_h_max(self, double* current_cells, int hash_id) noexcept nogil: return self.radius_scale*current_cells[hash_id] @cython.cdivision(True) cdef inline int _h_mask_exact(self, int* x, int* y, int* z, - int H) nogil: + int H) noexcept nogil: cdef int length = 0 cdef int s, t, u - for s from -H<=s<=H: - for t from -H<=t<=H: - for u from -H<=u<=H: + for s in range(-H, H+1): + for t in range(-H, H+1): + for u in range(-H, H+1): x[length] = s y[length] = t z[length] = u @@ -237,7 +239,7 @@ cdef class StratifiedHashNNPS(NNPS): return length cdef inline int _neighbor_boxes(self, int i, int j, int k, - int* x, int* y, int* z, int H) nogil: + int* x, int* y, int* z, int H) noexcept nogil: cdef int length = 0 cdef int p @@ -249,7 +251,7 @@ cdef class StratifiedHashNNPS(NNPS): mask_len = self._h_mask_exact(x_mask, y_mask, z_mask, H) - for p from 0<=p= 0 and j + y_mask[p] >= 0 and k + z_mask[p] >= 0): @@ -265,10 +267,10 @@ cdef class StratifiedHashNNPS(NNPS): return length cdef inline void _set_h_max(self, double* current_cells, double* src_h_ptr, - int num_particles) nogil: + int num_particles) noexcept nogil: cdef double h cdef int i, idx - for i from 0<=iself.pa_wrappers[i] num_particles = pa_wrapper.get_number_of_particles() diff --git a/pysph/base/stratified_sfc_nnps.pxd b/pysph/base/stratified_sfc_nnps.pxd index 9c3c6d57..d5bd5e91 100644 --- a/pysph/base/stratified_sfc_nnps.pxd +++ b/pysph/base/stratified_sfc_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.vector cimport vector from libcpp.map cimport map from libcpp.pair cimport pair @@ -21,13 +23,13 @@ cdef extern from 'math.h': cdef extern from "z_order.h": ctypedef unsigned int uint32_t ctypedef unsigned long long uint64_t - inline uint64_t get_key(uint64_t i, uint64_t j, uint64_t k) nogil + uint64_t get_key(uint64_t i, uint64_t j, uint64_t k) nogil cdef cppclass CompareSortWrapper: - CompareSortWrapper() nogil except + + CompareSortWrapper() except + CompareSortWrapper(uint32_t* current_pids, uint64_t* current_keys, - int length) nogil except + - inline void compare_sort() nogil + int length) except + nogil + inline void compare_sort() noexcept nogil cdef class StratifiedSFCNNPS(NNPS): ############################################################################ @@ -86,7 +88,7 @@ cdef class StratifiedSFCNNPS(NNPS): cdef inline int _get_H(self, double h_q, double h_j) - cdef inline int get_idx(self, uint64_t key, uint64_t max_key, int* key_to_idx) nogil + cdef inline int get_idx(self, uint64_t key, uint64_t max_key, int* key_to_idx) noexcept nogil cdef void _fill_nbr_boxes(self) @@ -98,12 +100,12 @@ cdef class StratifiedSFCNNPS(NNPS): cdef int _neighbor_boxes_asym(self, int i, int j, int k, int H, int* current_key_to_idx_level, uint64_t max_key, double current_cell_size, double* current_hmax_level, - vector[int]* nbr_boxes) nogil + vector[int]* nbr_boxes) noexcept nogil cdef int _neighbor_boxes_sym(self, int i, int j, int k, int H, int* current_key_to_idx_level, uint64_t max_key, double current_cell_size, double* current_hmax_level, - vector[int]* nbr_boxes) nogil + vector[int]* nbr_boxes) noexcept nogil cpdef double get_binning_size(self, int interval) @@ -111,13 +113,13 @@ cdef class StratifiedSFCNNPS(NNPS): cpdef get_spatially_ordered_indices(self, int pa_index, LongArray indices) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cdef void fill_array(self, NNPSParticleArrayWrapper pa_wrapper, int pa_index, uint32_t* current_pids, uint64_t* current_keys, double* current_cells, int* current_num_cells) - cdef inline int _get_level(self, double h) nogil + cdef inline int _get_level(self, double h) noexcept nogil cpdef _refresh(self) diff --git a/pysph/base/stratified_sfc_nnps.pyx b/pysph/base/stratified_sfc_nnps.pyx index 63b44f0d..ae1e78b0 100644 --- a/pysph/base/stratified_sfc_nnps.pyx +++ b/pysph/base/stratified_sfc_nnps.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free @@ -82,14 +84,14 @@ cdef class StratifiedSFCNNPS(NNPS): self.total_mask_len = malloc(narrays*sizeof(int)) cdef int i, j, num_particles - for i from 0<=i malloc(self.num_levels*sizeof(int*)) self.key_to_nbr_idx[i] = malloc(self.num_levels*sizeof(int*)) self.key_to_nbr_length[i] = malloc(self.num_levels*sizeof(int*)) - for j from 0<=j= 0 and num_boxes > 0): return - for i from start_idx<=i \ self.pa_wrappers[pa_index]).get_number_of_particles() keys = np.empty(num_particles) - for i from 0<=i min(self.num_levels, ceil(log2((self.cell_size + EPS)/ self.radius_scale / h))) @@ -329,7 +331,7 @@ cdef class StratifiedSFCNNPS(NNPS): cdef inline int _get_H(self, double h_q, double h_j): return ceil(h_q / h_j) - cdef inline int get_idx(self, uint64_t key, uint64_t max_key, int* key_to_idx) nogil: + cdef inline int get_idx(self, uint64_t key, uint64_t max_key, int* key_to_idx) noexcept nogil: return -1 if key >= max_key else key_to_idx[key] cdef int _neighbor_boxes_func(self, int i, int j, int k, int H, @@ -346,7 +348,7 @@ cdef class StratifiedSFCNNPS(NNPS): cdef int _neighbor_boxes_asym(self, int i, int j, int k, int H, int* current_key_to_idx_level, uint64_t max_key, double current_cell_size, double* current_hmax_level, - vector[int]* nbr_boxes) nogil: + vector[int]* nbr_boxes) noexcept nogil: cdef int length = 0 cdef uint64_t key @@ -356,9 +358,9 @@ cdef class StratifiedSFCNNPS(NNPS): cdef int s, t, u - for s from -H<=s<=H: - for t from -H<=t<=H: - for u from -H<=u<=H: + for s in range(-H, H+1): + for t in range(-H, H+1): + for u in range(-H, H+1): x_temp = i + u y_temp = j + t @@ -380,7 +382,7 @@ cdef class StratifiedSFCNNPS(NNPS): cdef int _neighbor_boxes_sym(self, int i, int j, int k, int H, int* current_key_to_idx_level, uint64_t max_key, double current_cell_size, double* current_hmax_level, - vector[int]* nbr_boxes) nogil: + vector[int]* nbr_boxes) noexcept nogil: cdef int length = 0 cdef uint64_t key @@ -394,9 +396,9 @@ cdef class StratifiedSFCNNPS(NNPS): cdef uint64_t qkey = get_key(i, j, k) - for s from -H<=s<=H: - for t from -H<=t<=H: - for u from -H<=u<=H: + for s in range(-H, H+1): + for t in range(-H, H+1): + for u in range(-H, H+1): x_temp = i + u y_temp = j + t @@ -446,7 +448,7 @@ cdef class StratifiedSFCNNPS(NNPS): strip_mask = (1 << self.max_num_bits) - 1 - for i from 0<=i> self.max_num_bits @@ -505,7 +507,7 @@ cdef class StratifiedSFCNNPS(NNPS): current_key_to_nbr_idx_level[key_bottom] = n - for k from 0<=k \ self.pa_wrappers[i]).get_number_of_particles() if self.pids[i] != NULL: @@ -602,7 +604,7 @@ cdef class StratifiedSFCNNPS(NNPS): self.pids[i] = malloc(num_particles*sizeof(uint32_t)) self.keys[i] = malloc(num_particles*sizeof(uint64_t)) current_cells = self.cell_sizes[i] - for j from 0<=j malloc(self.max_possible_key * sizeof(int)) current_key_to_nbr_length[j] = malloc(self.max_possible_key * sizeof(int)) current_key_to_nbr_idx_level = current_key_to_nbr_idx[j] current_key_to_nbr_length_level = current_key_to_nbr_length[j] - for key_iter from 0<=key_iter malloc(max_key * sizeof(int)) current_hmax[i] = malloc(max_key * sizeof(double)) key_idx_level = current_key_to_idx[i] hmax_level = current_hmax[i] current_num_cells[i] = 0 - for j from 0<=j> self.max_num_bits diff --git a/pysph/base/tests/test_device_helper.py b/pysph/base/tests/test_device_helper.py index d0e230e6..b2ee24f9 100644 --- a/pysph/base/tests/test_device_helper.py +++ b/pysph/base/tests/test_device_helper.py @@ -27,13 +27,13 @@ def check_import(backend): class TestDeviceHelper(object): - def setup(self): + def setup_method(self): self.pa = get_particle_array(name='f', x=[0.0, 1.0], m=1.0, rho=2.0) @check_all_backends def test_simple(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -51,7 +51,7 @@ def test_simple(self, backend): @check_all_backends def test_push_correctly_sets_values_with_args(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -74,7 +74,7 @@ def test_push_correctly_sets_values_with_args(self, backend): @check_all_backends def test_push_correctly_sets_values_with_no_args(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -97,7 +97,7 @@ def test_push_correctly_sets_values_with_no_args(self, backend): @check_all_backends def test_pull_correctly_sets_values_with_args(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -120,7 +120,7 @@ def test_pull_correctly_sets_values_with_args(self, backend): @check_all_backends def test_pull_correctly_sets_values_with_no_args(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -143,7 +143,7 @@ def test_pull_correctly_sets_values_with_no_args(self, backend): @check_all_backends def test_max_provides_maximum(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given/When pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -154,7 +154,7 @@ def test_max_provides_maximum(self, backend): @check_all_backends def test_that_adding_removing_prop_to_array_updates_gpu(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -177,7 +177,7 @@ def test_that_adding_removing_prop_to_array_updates_gpu(self, backend): @check_all_backends def test_resize_works(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -211,7 +211,7 @@ def test_resize_works(self, backend): @check_all_backends def test_get_number_of_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -231,7 +231,7 @@ def test_get_number_of_particles(self, backend): @check_all_backends def test_align(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa pa.add_property('force', stride=3) @@ -259,7 +259,7 @@ def test_align(self, backend): @check_all_backends def test_align_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -279,7 +279,7 @@ def test_align_particles(self, backend): @check_all_backends def test_remove_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -300,7 +300,7 @@ def test_remove_particles(self, backend): @check_all_backends def test_remove_tagged_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -319,7 +319,7 @@ def test_remove_tagged_particles(self, backend): @check_all_backends def test_add_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -336,7 +336,7 @@ def test_add_particles(self, backend): @check_all_backends def test_extend(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) @@ -352,7 +352,7 @@ def test_extend(self, backend): @check_all_backends def test_append_parray(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa1 = self.pa pa2 = get_particle_array(name='s', x=[0.0, 1.0], m=1.0, rho=2.0) @@ -368,7 +368,7 @@ def test_append_parray(self, backend): @check_all_backends def test_empty_clone(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = get_particle_array(name='f', x=[0.0, 1.0, 2.0, 3.0], m=1.0, rho=2.0) @@ -385,7 +385,7 @@ def test_empty_clone(self, backend): @check_all_backends def test_extract_particles(self, backend): check_import(backend) - self.setup() + self.setup_method() # Given pa = get_particle_array(name='f', x=[0.0, 1.0, 2.0, 3.0], m=1.0, rho=2.0) @@ -405,7 +405,7 @@ def test_extract_particles(self, backend): def test_update_minmax_cl(self): backend = 'opencl' check_import(backend) - self.setup() + self.setup_method() # Given x = [0.0, -1.0, 2.0, 3.0] diff --git a/pysph/base/tests/test_reduce_array.py b/pysph/base/tests/test_reduce_array.py index 134a0917..32b3159f 100644 --- a/pysph/base/tests/test_reduce_array.py +++ b/pysph/base/tests/test_reduce_array.py @@ -37,7 +37,7 @@ def test_dummy_reduce_array_does_nothing(self): x = np.array([1.0, 2.0]) expect = x result = dummy_reduce_array(x, 'min') - self.assertTrue(np.alltrue(result == expect)) + self.assertTrue(np.all(result == expect)) if __name__ == '__main__': diff --git a/pysph/base/z_order_gpu_nnps.pxd b/pysph/base/z_order_gpu_nnps.pxd index 50a59981..7b00b218 100644 --- a/pysph/base/z_order_gpu_nnps.pxd +++ b/pysph/base/z_order_gpu_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.map cimport map from libcpp.pair cimport pair diff --git a/pysph/base/z_order_gpu_nnps.pyx b/pysph/base/z_order_gpu_nnps.pyx index 5a2ec5c8..5076729b 100644 --- a/pysph/base/z_order_gpu_nnps.pyx +++ b/pysph/base/z_order_gpu_nnps.pyx @@ -1,4 +1,6 @@ -#cython: embedsignature=True +# cython: language_level=3, embedsignature=True +# distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free @@ -66,7 +68,7 @@ cdef class ZOrderGPUNNPS(GPUNNPS): self.cids = [] self.cid_to_idx = [] - for i from 0<=iself.pa_wrappers[i] num_particles = pa_wrapper.get_number_of_particles() @@ -180,7 +182,7 @@ cdef class ZOrderGPUNNPS(GPUNNPS): self.max_cid = [] self.sorted = False - for i from 0<=iself.pa_wrappers[i] num_particles = pa_wrapper.get_number_of_particles() diff --git a/pysph/base/z_order_nnps.pxd b/pysph/base/z_order_nnps.pxd index 95ff9282..2871e315 100644 --- a/pysph/base/z_order_nnps.pxd +++ b/pysph/base/z_order_nnps.pxd @@ -1,5 +1,7 @@ # cython: language_level=3, embedsignature=True # distutils: language=c++ +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from libcpp.map cimport map from libcpp.pair cimport pair @@ -11,12 +13,12 @@ cdef extern from "math.h": cdef extern from "z_order.h": ctypedef unsigned long long uint64_t ctypedef unsigned int uint32_t - inline uint64_t get_key(uint64_t i, uint64_t j, uint64_t k) nogil + uint64_t get_key(uint64_t i, uint64_t j, uint64_t k) nogil cdef cppclass CompareSortWrapper: - CompareSortWrapper() nogil except + + CompareSortWrapper() except + nogil CompareSortWrapper(uint32_t* current_pids, uint64_t* current_keys, - int length) nogil except + + int length) except + nogil inline void compare_sort() nogil ctypedef map[uint64_t, pair[uint32_t, uint32_t]] key_to_idx_t @@ -63,11 +65,11 @@ cdef class ZOrderNNPS(NNPS): cdef inline int _neighbor_boxes(self, int i, int j, int k, int* current_key_to_idx, int num_particles, - int* found_indices) nogil + int* found_indices) noexcept nogil cpdef set_context(self, int src_index, int dst_index) - cdef inline int get_idx(self, uint64_t key, int* key_to_idx) nogil + cdef inline int get_idx(self, uint64_t key, int* key_to_idx) noexcept nogil cpdef np.ndarray get_nbr_boxes(self, pa_index, cid) @@ -77,7 +79,7 @@ cdef class ZOrderNNPS(NNPS): cpdef np.ndarray get_keys(self, pa_index) - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil cpdef get_nearest_particles_no_cache(self, int src_index, int dst_index, size_t d_idx, UIntArray nbrs, bint prealloc) @@ -105,7 +107,7 @@ cdef class ExtendedZOrderNNPS(ZOrderNNPS): # Member functions ########################################################################## - cdef inline int _h_mask_exact(self, int* x, int* y, int* z) nogil + cdef inline int _h_mask_exact(self, int* x, int* y, int* z) noexcept nogil cdef int _neighbor_boxes_func(self, int i, int j, int k, int* current_key_to_idx, uint32_t* current_cids, @@ -115,12 +117,12 @@ cdef class ExtendedZOrderNNPS(ZOrderNNPS): cdef int _neighbor_boxes_asym(self, int i, int j, int k, int* current_key_to_idx, uint32_t* current_cids, double* current_hmax, int num_particles, - int* found_indices, double h) nogil + int* found_indices, double h) noexcept nogil cdef int _neighbor_boxes_sym(self, int i, int j, int k, int* current_key_to_idx, uint32_t* current_cids, double* current_hmax, int num_particles, - int* found_indices, double h) nogil + int* found_indices, double h) noexcept nogil cdef void _fill_nbr_boxes(self) diff --git a/pysph/base/z_order_nnps.pyx b/pysph/base/z_order_nnps.pyx index e7a75fef..7aa7f140 100644 --- a/pysph/base/z_order_nnps.pyx +++ b/pysph/base/z_order_nnps.pyx @@ -1,4 +1,5 @@ #cython: embedsignature=True +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION # malloc and friends from libc.stdlib cimport malloc, free @@ -21,7 +22,7 @@ cdef extern from "" namespace "std" nogil: ############################################################################# -cdef inline int cmp_func(const void* a, const void* b) nogil: +cdef inline int cmp_func(const void* a, const void* b) noexcept nogil: return (a)[0] - (b)[0] cdef class ZOrderNNPS(NNPS): @@ -66,7 +67,7 @@ cdef class ZOrderNNPS(NNPS): self.key_to_idx = malloc(narrays*sizeof(int*)) cdef int i - for i from 0<=i self.pa_wrappers[dst_index] self.src = self.pa_wrappers[src_index] - cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) nogil: + cdef void find_nearest_neighbors(self, size_t d_idx, UIntArray nbrs) noexcept nogil: """Low level, high-performance non-gil method to find neighbors. This requires that `set_context()` be called beforehand. This method does not reset the neighbors array before it appends the @@ -179,7 +180,7 @@ cdef class ZOrderNNPS(NNPS): cdef uint64_t key cdef int length - for i from 0<=icurrent_pids[j]) cdef int fill_array(self, NNPSParticleArrayWrapper pa_wrapper, int pa_index, @@ -263,7 +264,7 @@ cdef class ZOrderNNPS(NNPS): cdef int c_x, c_y, c_z cdef int i, n - for i from 0<=i \ self.pa_wrappers[pa_index]).get_number_of_particles() keys = np.empty(num_particles) - for i from 0<=i= self.max_key else key_to_idx[key] cdef inline int _neighbor_boxes(self, int i, int j, int k, int* current_key_to_idx, int num_particles, - int* found_indices) nogil: + int* found_indices) noexcept nogil: cdef int length = 0 cdef int p, q, r cdef uint64_t key cdef int found_idx - for p from -1<=p<2: - for q from -1<=q<2: - for r from -1<=r<2: + for p in range(-1, 2): + for q in range(-1, 2): + for r in range(-1, 2): if i+r>=0 and j+q>=0 and k+p>=0: key = get_key(i+r, j+q, k+p) found_idx = self.get_idx(key, current_key_to_idx) @@ -530,7 +531,7 @@ cdef class ZOrderNNPS(NNPS): cdef uint64_t max_key = 1 + get_key(c_x, c_y, c_z) self.max_key = max_key - for i from 0<=i=42.0.0 -Cython<3.0 +Cython>=0.20 cyarray compyle>=0.8 mako diff --git a/setup.py b/setup.py index ae13fc67..f24b8144 100644 --- a/setup.py +++ b/setup.py @@ -152,6 +152,7 @@ def get_openmp_flags(): import shutil import tempfile test_code = dedent(""" + # cython: language_level=3, distutils: language=c++ from cython.parallel import parallel, prange, threadid cimport openmp def n_threads(): @@ -334,13 +335,35 @@ def get_basic_extensions(): include_dirs += base_includes openmp_compile_args, openmp_link_args, openmp_env = get_openmp_flags() - ext_modules = [ + ext_modules = [] + if openmp_env: + ext_modules.append( + Extension( + name="pysph.base.omp_threads", + sources=["pysph/base/omp_threads.pyx"], + include_dirs=include_dirs, + extra_compile_args=extra_compile_args + openmp_compile_args, + extra_link_args=openmp_link_args, + language="c++", + define_macros=MACROS, + ) + ) + + ext_modules.extend([ + Extension( + name="pysph.base.no_omp_threads", + sources=["pysph/base/no_omp_threads.pyx"], + include_dirs=include_dirs, + extra_compile_args=extra_compile_args, + language="c++", + define_macros=MACROS, + ), + Extension( name="pysph.base.particle_array", sources=["pysph/base/particle_array.pyx"], include_dirs=include_dirs, extra_compile_args=extra_compile_args, - language="c++", define_macros=MACROS, ), @@ -349,7 +372,6 @@ def get_basic_extensions(): sources=["pysph/base/point.pyx"], extra_compile_args=extra_compile_args, include_dirs=include_dirs, - language="c++", define_macros=MACROS, ), @@ -364,7 +386,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -379,7 +400,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -393,7 +413,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -407,7 +426,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -421,7 +439,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -436,7 +453,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -450,7 +466,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -464,7 +479,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -478,7 +492,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -492,7 +505,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -502,7 +514,6 @@ def get_basic_extensions(): sources=["pysph/base/c_kernels.pyx"], include_dirs=include_dirs, extra_compile_args=extra_compile_args, - language="c++", define_macros=MACROS, ), @@ -512,7 +523,6 @@ def get_basic_extensions(): sources=["pysph/base/linalg3.pyx"], include_dirs=include_dirs, extra_compile_args=extra_compile_args, - language="c++", define_macros=MACROS, ), @@ -522,11 +532,9 @@ def get_basic_extensions(): sources=["pysph/tools/mesh_tools.pyx"], include_dirs=include_dirs, extra_compile_args=extra_compile_args, - language="c++", define_macros=MACROS, ), - - ] + ]) # OpenCL related modules ext_modules.extend(( @@ -541,7 +549,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), @@ -555,7 +562,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), Extension( @@ -568,7 +574,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, ), Extension( @@ -581,7 +586,6 @@ def get_basic_extensions(): extra_compile_args=extra_compile_args + openmp_compile_args, extra_link_args=openmp_link_args, cython_compile_time_env={'OPENMP': openmp_env}, - language="c++", define_macros=MACROS, )) ) @@ -635,7 +639,6 @@ def get_parallel_extensions(): extra_link_args=mpi_link_args, extra_compile_args=mpi_compile_args + extra_compile_args, cython_compile_time_env=cython_compile_time_env, - language="c++", define_macros=MACROS, ), ] @@ -681,7 +684,7 @@ def setup_package(): # The requirements. install_requires = [ - 'numpy', 'mako', 'cyarray', 'compyle>=0.8', 'Cython<3.0', + 'numpy', 'mako', 'cyarray', 'compyle>=0.8', 'Cython>=0.20', 'setuptools>=42.0.0', 'pytools', 'Beaker' ] tests_require = ['pytest>=3.0', 'h5py', 'vtk'] @@ -723,7 +726,6 @@ def setup_package(): ext_modules = cythonize( ext_modules, compile_time_env=compile_env, include_path=list(include_path), - language="c++", compiler_directives=COMPILER_DIRECTIVES, )