Skip to content

Commit

Permalink
No more Cython DEF and IF + prepare MPI
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Feb 2, 2024
1 parent 910b562 commit a768d26
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 27 deletions.
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean cleanall cleanmako cleancython develop build_ext_inplace list-sessions tests
.PHONY: clean cleanall develop build_ext_inplace list-sessions tests

develop: sync
pdm run pip install -e . --no-deps --no-build-isolation -v
Expand All @@ -17,13 +17,7 @@ cleanso:
cleanpythran:
find src -name __pythran__ -type d -exec rm -rf "{}" +

cleancython:
find src -name "*_cy.cpp" -delete

cleanmako:
python -c "from fluidfft_builder.src_cy.make_files_with_mako import clean_files as c; c()"

cleanall: clean cleanso cleanmako cleancython cleanpythran
cleanall: clean cleanso cleanpythran

black:
pdm run black
Expand Down
12 changes: 0 additions & 12 deletions plugins/fluidfft-builder/fluidfft_builder/include_cy/base.pyx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# cython: embedsignature=True
# cython: language_level=3

DEF MPI4PY = 0

cimport cython

from cython cimport view
Expand All @@ -21,16 +19,6 @@ else:
nb_proc = comm.size
rank = comm.Get_rank()

IF MPI4PY:
from mpi4py cimport MPI

#from mpi4py.mpi_c cimport *
# for mpi4py > 2.0
from mpi4py.libmpi cimport *

# fix a bug arising when using a recent version of mpi4py
cdef extern from 'mpi-compat.h': pass

# we define python and c types for physical and Fourier spaces
DTYPEb = np.uint8
ctypedef np.uint8_t DTYPEb_t
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from mpi4py cimport MPI
from mpi4py.libmpi cimport *

# fix a bug arising when using a recent version of mpi4py
cdef extern from 'mpi-compat.h': pass
10 changes: 9 additions & 1 deletion plugins/fluidfft-builder/fluidfft_builder/make_cy_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,23 @@ def make_file(path_output, class_name, numpy_api="numpy"):
name_output = path_output.name
module_name, extension = name_output.split(".")

template_name = f"template{dimension}d.{extension}"
if name_output.startswith("mpi"):
cdef_public_mpi_comm = "cdef public MPI.Comm comm"
include_base_mpi_pyx = "include 'base_mpi.pyx'"
else:
cdef_public_mpi_comm = ""
include_base_mpi_pyx = ""

template_name = f"template{dimension}d.{extension}"
template = load_template(template_name)

content = template.substitute(
{
"module_name": module_name,
"class_name": class_name,
"numpy_api": numpy_api,
"cdef_public_mpi_comm": cdef_public_mpi_comm,
"include_base_mpi_pyx": include_base_mpi_pyx,
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# cython: language_level=3

include 'base.pyx'

${include_base_mpi_pyx}

from fft2d_${module_name} cimport (
${class_name} as mycppclass,
Expand Down Expand Up @@ -31,8 +31,7 @@ cdef class ${class_name}:
cdef tuple _shapeK_loc, _shapeX_loc, _shapeK_seq, _shapeX_seq
cdef int _is_mpi_lib

IF MPI4PY:
cdef public MPI.Comm comm
${cdef_public_mpi_comm}
cdef public int nb_proc, rank

def __cinit__(self, int n0=2, int n1=2):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# cython: language_level=3

include 'base.pyx'

${include_base_mpi_pyx}

from fft3d_${module_name} cimport (
${class_name} as mycppclass,
Expand Down Expand Up @@ -60,8 +60,8 @@ cdef class ${class_name}:
cdef int dim_first_fft
cdef int _is_mpi_lib

IF MPI4PY:
cdef public MPI.Comm comm
${cdef_public_mpi_comm}

cdef public int nb_proc, rank

def __cinit__(self, int n0=2, int n1=2, int n2=4):
Expand Down
3 changes: 3 additions & 0 deletions plugins/fluidfft-fftw/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

develop:
pip install -e . -vv --no-build-isolation --no-deps

clean:
rm -rf build

0 comments on commit a768d26

Please sign in to comment.