Merge pull request #9 from pchanial/pythonsht

Pythonsht, take 2
This commit is contained in:
Dag Sverre Seljebotn 2015-06-03 23:50:09 +02:00
commit f8e6119f5d
8 changed files with 46 additions and 18 deletions

1
.gitignore vendored
View file

@ -14,3 +14,4 @@
/sharp_oracle.inc
/python/libsharp/libsharp.c
/python/libsharp/libsharp_mpi.c

View file

@ -19,6 +19,8 @@ include libfftpack/planck.make
include libsharp/planck.make
include docsrc/planck.make
CYTHON_MODULES=python/libsharp/libsharp.so $(if $(MPI_CFLAGS), python/libsharp/libsharp_mpi.so)
$(all_lib): %: | $(LIBDIR)_mkdir
@echo "# creating library $*"
$(ARCREATE) $@ $^
@ -62,10 +64,15 @@ perftest: compile_all
genclean:
rm libsharp/sharp_legendre.c || exit 0
python/libsharp/libsharp.so: python/libsharp/libsharp.pyx $(LIB_libsharp)
$(CYTHON_MODULES): %.so: %.pyx
ifndef PIC_CFLAGS
$(error Python extension must be built using the --enable-pic configure option.)
endif
cython $<
$(CC) -fPIC `python-config --cflags` -I$(INCDIR) -o python/libsharp/libsharp.o -c python/libsharp/libsharp.c
$(CL) -shared python/libsharp/libsharp.o -L$(LIBDIR) -lsharp -lfftpack -lc_utils `python-config --libs` -o $@
$(CC) $(DEBUG_CFLAGS) $(OPENMP_CFLAGS) $(PIC_CFLAGS) `python-config --cflags` -I$(INCDIR) -o $(<:.pyx=.o) -c $(<:.pyx=.c)
$(CL) -shared $(<:.pyx=.o) $(OPENMP_CFLAGS) $(CYTHON_OBJ) -L$(LIBDIR) -lsharp -lfftpack -lc_utils -L`python-config --prefix`/lib `python-config --ldflags` -o $@
pytest: python/libsharp/libsharp.so
python: $(all_lib) hdrcopy $(CYTHON_MODULES)
pytest: python
cd python && nosetests --nocapture libsharp/tests/test_sht.py

View file

@ -5,5 +5,8 @@ CL=@CC@
CCFLAGS_NO_C=@CCFLAGS_NO_C@
CCFLAGS=$(CCFLAGS_NO_C) -c
CLFLAGS=-L. -L$(LIBDIR) @LDCCFLAGS@ -lm
DEBUG_CFLAGS=@DEBUG_CFLAGS@
MPI_CFLAGS=@MPI_CFLAGS@
OPENMP_CFLAGS=@OPENMP_CFLAGS@
PIC_CFLAGS=@PIC_CFLAGS@
ARCREATE=@ARCREATE@

View file

@ -1,9 +1,10 @@
BLDROOT = $(SRCROOT)/build.$(SHARP_TARGET)
PREFIX = $(SRCROOT)/$(SHARP_TARGET)
BINDIR = $(PREFIX)/bin
INCDIR = $(PREFIX)/include
LIBDIR = $(PREFIX)/lib
DOCDIR = $(SRCROOT)/doc
BLDROOT = $(SRCROOT)/build.$(SHARP_TARGET)
PREFIX = $(SRCROOT)/$(SHARP_TARGET)
BINDIR = $(PREFIX)/bin
INCDIR = $(PREFIX)/include
LIBDIR = $(PREFIX)/lib
DOCDIR = $(SRCROOT)/doc
PYTHONDIR = $(SRCROOT)/python/libsharp
# do not use any suffix rules
.SUFFIXES:
@ -26,6 +27,7 @@ $(BLDROOT)/%.o : $(SRCROOT)/%.cc | echo_config
clean:
rm -rf $(BLDROOT) $(PREFIX) $(DOCDIR) autom4te.cache/ config.log config.status
rm -rf $(PYTHONDIR)/*.c $(PYTHONDIR)/*.o $(PYTHONDIR)/*.so
distclean: clean
rm -f config/config.auto

View file

@ -82,20 +82,20 @@ case $system in
;;
esac
CCFLAGS="$CCFLAGS $OPENMP_CFLAGS"
if test $ENABLE_DEBUG = yes; then
CCFLAGS="$CCFLAGS -g"
DEBUG_CFLAGS="-g"
fi
if test $ENABLE_PIC = yes; then
CCFLAGS="$CCFLAGS -fPIC"
PIC_CFLAGS="-fPIC"
fi
if test $ENABLE_MPI = yes; then
CCFLAGS="$CCFLAGS -DUSE_MPI"
MPI_CFLAGS="-DUSE_MPI"
fi
CCFLAGS="$CCFLAGS $DEBUG_CFLAGS $OPENMP_CFLAGS $PIC_CFLAGS $MPI_CFLAGS"
CCFLAGS_NO_C="$CCFLAGS $CPPFLAGS"
LDCCFLAGS="$LDFLAGS $CCFLAGS"
@ -104,6 +104,10 @@ AC_SUBST(SILENT_RULE)
AC_SUBST(CC)
AC_SUBST(CCFLAGS_NO_C)
AC_SUBST(LDCCFLAGS)
AC_SUBST(DEBUG_CFLAGS)
AC_SUBST(MPI_CFLAGS)
AC_SUBST(OPENMP_CFLAGS)
AC_SUBST(PIC_CFLAGS)
AC_SUBST(ARCREATE)
AC_OUTPUT(config/config.auto)

View file

@ -27,7 +27,7 @@ cdef extern from "sharp.h":
void sharp_destroy_geom_info(sharp_geom_info *info)
ptrdiff_t sharp_map_size(sharp_geom_info *info)
ptrdiff_t sharp_alm_count(sharp_alm_info *self);
ptrdiff_t sharp_alm_count(sharp_alm_info *self)
ctypedef enum sharp_jobtype:

View file

@ -105,7 +105,8 @@ def sht(jobtype, geom_info ginfo, alm_info ainfo, double[:, :, ::1] input,
from mpi4py import MPI
if not isinstance(comm, MPI.Comm):
raise TypeError('comm must be an mpi4py communicator')
comm_ptr = <void*><size_t>MPI._addressof(comm)
from .libsharp_mpi import _addressof
comm_ptr = <void*><size_t>_addressof(comm)
with nogil:
r = sharp_execute_mpi_maybe (
comm_ptr, jobtype_i,

View file

@ -0,0 +1,10 @@
from mpi4py.MPI cimport Comm
cdef extern from "Python.h":
object PyLong_FromVoidPtr(void*)
# For compatibility with mpi4py <= 1.3.1
# Newer versions could use the MPI._addressof function
def _addressof(comm):
cdef void *ptr = NULL
ptr = <void*>&(<Comm>comm).ob_mpi
return PyLong_FromVoidPtr(ptr)