Set compiler/linker options to make cython parallelisation actually work.

This commit is contained in:
Marek Nečada 2020-07-03 15:10:15 +03:00
parent 17824b062e
commit 38a4dbfcd7
2 changed files with 18 additions and 15 deletions

View File

@ -17,8 +17,8 @@ from .cymaterials cimport EpsMuGenerator, EpsMu
from libc.stdlib cimport malloc, free, calloc from libc.stdlib cimport malloc, free, calloc
import warnings import warnings
from cython.parallel import prange, parallel from cython.parallel cimport prange, parallel
from cython import boundscheck, wraparound from cython cimport boundscheck, wraparound
# Set custom GSL error handler. N.B. this is obviously not thread-safe. # Set custom GSL error handler. N.B. this is obviously not thread-safe.
cdef char *pgsl_err_reason cdef char *pgsl_err_reason
@ -916,7 +916,7 @@ cdef class ScatteringSystem:
cdef ccart3_t res cdef ccart3_t res
cdef cart3_t pos cdef cart3_t pos
cdef Py_ssize_t i cdef Py_ssize_t i
with nogil, parallel(): with nogil, parallel(), boundscheck(False), wraparound(False):
for i in prange(evalpos_a.shape[0]): for i in prange(evalpos_a.shape[0]):
pos.x = evalpos_a[i,0] pos.x = evalpos_a[i,0]
pos.y = evalpos_a[i,1] pos.y = evalpos_a[i,1]
@ -957,7 +957,6 @@ def empty_lattice_modes_xy(EpsMu epsmu, reciprocal_basis, wavevector, double max
free(omegas_c) free(omegas_c)
return omegas return omegas
cdef class _ScatteringSystemAtOmegaK: cdef class _ScatteringSystemAtOmegaK:
''' '''
Wrapper over the C qpms_scatsys_at_omega_k_t structure Wrapper over the C qpms_scatsys_at_omega_k_t structure
@ -1121,6 +1120,7 @@ cdef class _ScatteringSystemAtOmega:
def translation_matrix_packed(self, iri, J = QPMS_HANKEL_PLUS): def translation_matrix_packed(self, iri, J = QPMS_HANKEL_PLUS):
return self.ss_pyref.translation_matrix_packed(wavenumber=self.wavenumber, iri=iri, J=J) return self.ss_pyref.translation_matrix_packed(wavenumber=self.wavenumber, iri=iri, J=J)
@boundscheck(False)
def scattered_E(self, scatcoeffvector_full, evalpos, bint alt=False, btyp=QPMS_HANKEL_PLUS): def scattered_E(self, scatcoeffvector_full, evalpos, bint alt=False, btyp=QPMS_HANKEL_PLUS):
cdef qpms_bessel_t btyp_c = BesselType(btyp) cdef qpms_bessel_t btyp_c = BesselType(btyp)
evalpos = np.array(evalpos, dtype=float, copy=False) evalpos = np.array(evalpos, dtype=float, copy=False)
@ -1133,17 +1133,18 @@ cdef class _ScatteringSystemAtOmega:
cdef ccart3_t res cdef ccart3_t res
cdef cart3_t pos cdef cart3_t pos
cdef Py_ssize_t i cdef Py_ssize_t i
for i in range(evalpos_a.shape[0]): with wraparound(False), nogil, parallel():
pos.x = evalpos_a[i,0] for i in prange(evalpos_a.shape[0]):
pos.y = evalpos_a[i,1] pos.x = evalpos_a[i,0]
pos.z = evalpos_a[i,2] pos.y = evalpos_a[i,1]
if alt: pos.z = evalpos_a[i,2]
res = qpms_scatsysw_scattered_E__alt(self.ssw, btyp_c, &scv_view[0], pos) if alt:
else: res = qpms_scatsysw_scattered_E__alt(self.ssw, btyp_c, &scv_view[0], pos)
res = qpms_scatsysw_scattered_E(self.ssw, btyp_c, &scv_view[0], pos) else:
results[i,0] = res.x res = qpms_scatsysw_scattered_E(self.ssw, btyp_c, &scv_view[0], pos)
results[i,1] = res.y results[i,0] = res.x
results[i,2] = res.z results[i,1] = res.y
results[i,2] = res.z
return results.reshape(evalpos.shape) return results.reshape(evalpos.shape)

View File

@ -134,6 +134,8 @@ qpms_c = Extension('qpms.qpms_c',
#('amos', dict(sources=amos_sources) ), #('amos', dict(sources=amos_sources) ),
], ],
include_dirs=['amos', 'qpms'], include_dirs=['amos', 'qpms'],
extra_link_args=['-fopenmp'],
extra_compile_args=['-fopenmp'],
#extra_link_args=[ 'qpms/libqpms.a','amos/libamos.a', ], #extra_link_args=[ 'qpms/libqpms.a','amos/libamos.a', ],
#runtime_library_dirs=os.environ['LD_LIBRARY_PATH'].split(':') if 'LD_LIBRARY_PATH' in os.environ else [], #runtime_library_dirs=os.environ['LD_LIBRARY_PATH'].split(':') if 'LD_LIBRARY_PATH' in os.environ else [],
#extra_objects = ['amos/libamos.a'], # FIXME apparently, I would like to eliminate the need to cmake/make first #extra_objects = ['amos/libamos.a'], # FIXME apparently, I would like to eliminate the need to cmake/make first