Skip to content

Commit f8e6119

Browse files
author
Dag Sverre Seljebotn
committed
Merge pull request #9 from pchanial/pythonsht
Pythonsht, take 2
2 parents 3d60c8b + 07e0226 commit f8e6119

File tree

8 files changed

+46
-18
lines changed

8 files changed

+46
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
/sharp_oracle.inc
1515

1616
/python/libsharp/libsharp.c
17+
/python/libsharp/libsharp_mpi.c

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ include libfftpack/planck.make
1919
include libsharp/planck.make
2020
include docsrc/planck.make
2121

22+
CYTHON_MODULES=python/libsharp/libsharp.so $(if $(MPI_CFLAGS), python/libsharp/libsharp_mpi.so)
23+
2224
$(all_lib): %: | $(LIBDIR)_mkdir
2325
@echo "# creating library $*"
2426
$(ARCREATE) $@ $^
@@ -62,10 +64,15 @@ perftest: compile_all
6264
genclean:
6365
rm libsharp/sharp_legendre.c || exit 0
6466

65-
python/libsharp/libsharp.so: python/libsharp/libsharp.pyx $(LIB_libsharp)
67+
$(CYTHON_MODULES): %.so: %.pyx
68+
ifndef PIC_CFLAGS
69+
$(error Python extension must be built using the --enable-pic configure option.)
70+
endif
6671
cython $<
67-
$(CC) -fPIC `python-config --cflags` -I$(INCDIR) -o python/libsharp/libsharp.o -c python/libsharp/libsharp.c
68-
$(CL) -shared python/libsharp/libsharp.o -L$(LIBDIR) -lsharp -lfftpack -lc_utils `python-config --libs` -o $@
72+
$(CC) $(DEBUG_CFLAGS) $(OPENMP_CFLAGS) $(PIC_CFLAGS) `python-config --cflags` -I$(INCDIR) -o $(<:.pyx=.o) -c $(<:.pyx=.c)
73+
$(CL) -shared $(<:.pyx=.o) $(OPENMP_CFLAGS) $(CYTHON_OBJ) -L$(LIBDIR) -lsharp -lfftpack -lc_utils -L`python-config --prefix`/lib `python-config --ldflags` -o $@
74+
75+
python: $(all_lib) hdrcopy $(CYTHON_MODULES)
6976

70-
pytest: python/libsharp/libsharp.so
77+
pytest: python
7178
cd python && nosetests --nocapture libsharp/tests/test_sht.py

config/config.auto.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ CL=@CC@
55
CCFLAGS_NO_C=@CCFLAGS_NO_C@
66
CCFLAGS=$(CCFLAGS_NO_C) -c
77
CLFLAGS=-L. -L$(LIBDIR) @LDCCFLAGS@ -lm
8-
8+
DEBUG_CFLAGS=@DEBUG_CFLAGS@
9+
MPI_CFLAGS=@MPI_CFLAGS@
10+
OPENMP_CFLAGS=@OPENMP_CFLAGS@
11+
PIC_CFLAGS=@PIC_CFLAGS@
912
ARCREATE=@ARCREATE@

config/rules.common

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
BLDROOT = $(SRCROOT)/build.$(SHARP_TARGET)
2-
PREFIX = $(SRCROOT)/$(SHARP_TARGET)
3-
BINDIR = $(PREFIX)/bin
4-
INCDIR = $(PREFIX)/include
5-
LIBDIR = $(PREFIX)/lib
6-
DOCDIR = $(SRCROOT)/doc
1+
BLDROOT = $(SRCROOT)/build.$(SHARP_TARGET)
2+
PREFIX = $(SRCROOT)/$(SHARP_TARGET)
3+
BINDIR = $(PREFIX)/bin
4+
INCDIR = $(PREFIX)/include
5+
LIBDIR = $(PREFIX)/lib
6+
DOCDIR = $(SRCROOT)/doc
7+
PYTHONDIR = $(SRCROOT)/python/libsharp
78

89
# do not use any suffix rules
910
.SUFFIXES:
@@ -26,6 +27,7 @@ $(BLDROOT)/%.o : $(SRCROOT)/%.cc | echo_config
2627

2728
clean:
2829
rm -rf $(BLDROOT) $(PREFIX) $(DOCDIR) autom4te.cache/ config.log config.status
30+
rm -rf $(PYTHONDIR)/*.c $(PYTHONDIR)/*.o $(PYTHONDIR)/*.so
2931

3032
distclean: clean
3133
rm -f config/config.auto

configure.ac

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ case $system in
8282
;;
8383
esac
8484

85-
CCFLAGS="$CCFLAGS $OPENMP_CFLAGS"
86-
8785
if test $ENABLE_DEBUG = yes; then
88-
CCFLAGS="$CCFLAGS -g"
86+
DEBUG_CFLAGS="-g"
8987
fi
9088

9189
if test $ENABLE_PIC = yes; then
92-
CCFLAGS="$CCFLAGS -fPIC"
90+
PIC_CFLAGS="-fPIC"
9391
fi
9492

9593
if test $ENABLE_MPI = yes; then
96-
CCFLAGS="$CCFLAGS -DUSE_MPI"
94+
MPI_CFLAGS="-DUSE_MPI"
9795
fi
9896

97+
CCFLAGS="$CCFLAGS $DEBUG_CFLAGS $OPENMP_CFLAGS $PIC_CFLAGS $MPI_CFLAGS"
98+
9999
CCFLAGS_NO_C="$CCFLAGS $CPPFLAGS"
100100

101101
LDCCFLAGS="$LDFLAGS $CCFLAGS"
@@ -104,6 +104,10 @@ AC_SUBST(SILENT_RULE)
104104
AC_SUBST(CC)
105105
AC_SUBST(CCFLAGS_NO_C)
106106
AC_SUBST(LDCCFLAGS)
107+
AC_SUBST(DEBUG_CFLAGS)
108+
AC_SUBST(MPI_CFLAGS)
109+
AC_SUBST(OPENMP_CFLAGS)
110+
AC_SUBST(PIC_CFLAGS)
107111
AC_SUBST(ARCREATE)
108112

109113
AC_OUTPUT(config/config.auto)

python/libsharp/libsharp.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cdef extern from "sharp.h":
2727
void sharp_destroy_geom_info(sharp_geom_info *info)
2828

2929
ptrdiff_t sharp_map_size(sharp_geom_info *info)
30-
ptrdiff_t sharp_alm_count(sharp_alm_info *self);
30+
ptrdiff_t sharp_alm_count(sharp_alm_info *self)
3131

3232

3333
ctypedef enum sharp_jobtype:

python/libsharp/libsharp.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def sht(jobtype, geom_info ginfo, alm_info ainfo, double[:, :, ::1] input,
105105
from mpi4py import MPI
106106
if not isinstance(comm, MPI.Comm):
107107
raise TypeError('comm must be an mpi4py communicator')
108-
comm_ptr = <void*><size_t>MPI._addressof(comm)
108+
from .libsharp_mpi import _addressof
109+
comm_ptr = <void*><size_t>_addressof(comm)
109110
with nogil:
110111
r = sharp_execute_mpi_maybe (
111112
comm_ptr, jobtype_i,

python/libsharp/libsharp_mpi.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from mpi4py.MPI cimport Comm
2+
cdef extern from "Python.h":
3+
object PyLong_FromVoidPtr(void*)
4+
5+
# For compatibility with mpi4py <= 1.3.1
6+
# Newer versions could use the MPI._addressof function
7+
def _addressof(comm):
8+
cdef void *ptr = NULL
9+
ptr = <void*>&(<Comm>comm).ob_mpi
10+
return PyLong_FromVoidPtr(ptr)

0 commit comments

Comments
 (0)