Skip to content

Commit 6d97931

Browse files
author
Dag Sverre Seljebotn
committed
Merge pull request #7 from dagss/pythonsht
Declaring this ready for merging into master now.
2 parents c680bbb + 2ad9757 commit 6d97931

File tree

11 files changed

+425
-28
lines changed

11 files changed

+425
-28
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: 12 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,9 +64,15 @@ perftest: compile_all
6264
genclean:
6365
rm libsharp/sharp_legendre.c || exit 0
6466

65-
pytest:
66-
rm python/libsharp/libsharp.so || exit 0
67-
cd python && LIBSHARP_INCLUDE=$(INCDIR) LIBSHARP_LIB=$(LIBDIR) python setup.py build_ext --inplace
68-
cd python && nosetests 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
71+
cython $<
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 $@
6974

75+
python: $(all_lib) hdrcopy $(CYTHON_MODULES)
7076

77+
pytest: python
78+
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)

libsharp/sharp.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,4 +992,29 @@ int sharp_nv_oracle (sharp_jobtype type, int spin, int ntrans)
992992

993993
#ifdef USE_MPI
994994
#include "sharp_mpi.c"
995+
996+
int sharp_execute_mpi_maybe (void *pcomm, sharp_jobtype type, int spin,
997+
void *alm, void *map, const sharp_geom_info *geom_info,
998+
const sharp_alm_info *alm_info, int ntrans, int flags, double *time,
999+
unsigned long long *opcnt)
1000+
{
1001+
MPI_Comm comm = *(MPI_Comm*)pcomm;
1002+
sharp_execute_mpi((MPI_Comm)comm, type, spin, alm, map, geom_info, alm_info, ntrans,
1003+
flags, time, opcnt);
1004+
return 0;
1005+
}
1006+
1007+
#else
1008+
1009+
int sharp_execute_mpi_maybe (void *pcomm, sharp_jobtype type, int spin,
1010+
void *alm, void *map, const sharp_geom_info *geom_info,
1011+
const sharp_alm_info *alm_info, int ntrans, int flags, double *time,
1012+
unsigned long long *opcnt)
1013+
{
1014+
/* Suppress unused warning: */
1015+
(void)pcomm; (void)type; (void)spin; (void)alm; (void)map; (void)geom_info;
1016+
(void)alm_info; (void)ntrans; (void)flags; (void)time; (void)opcnt;
1017+
return SHARP_ERROR_NO_MPI;
1018+
}
1019+
9951020
#endif

libsharp/sharp_lowlevel.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,30 @@ void sharp_execute (sharp_jobtype type, int spin, void *alm, void *map,
239239
void sharp_set_chunksize_min(int new_chunksize_min);
240240
void sharp_set_nchunks_max(int new_nchunks_max);
241241

242+
243+
typedef enum { SHARP_ERROR_NO_MPI = 1,
244+
/*!< libsharp not compiled with MPI support */
245+
} sharp_errors;
246+
247+
/*! Works like sharp_execute_mpi, but is always present whether or not libsharp
248+
is compiled with USE_MPI. This is primarily useful for wrapper code etc.
249+
250+
Note that \a pcomm has the type MPI_Comm*, except we declare void* to avoid
251+
pulling in MPI headers. I.e., the comm argument of sharp_execute_mpi
252+
is *(MPI_Comm*)pcomm.
253+
254+
Other parameters are the same as sharp_execute_mpi.
255+
256+
Returns 0 if successful, or SHARP_ERROR_NO_MPI if MPI is not available
257+
(in which case nothing is done).
258+
*/
259+
int sharp_execute_mpi_maybe (void *pcomm, sharp_jobtype type, int spin,
260+
void *alm, void *map, const sharp_geom_info *geom_info,
261+
const sharp_alm_info *alm_info, int ntrans, int flags, double *time,
262+
unsigned long long *opcnt);
263+
264+
265+
242266
/*! \} */
243267

244268
#ifdef __cplusplus

python/libsharp/libsharp.pxd

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
cdef extern from "sharp.h":
2+
ctypedef long ptrdiff_t
3+
4+
void sharp_legendre_transform_s(float *bl, float *recfac, ptrdiff_t lmax, float *x,
5+
float *out, ptrdiff_t nx)
6+
void sharp_legendre_transform(double *bl, double *recfac, ptrdiff_t lmax, double *x,
7+
double *out, ptrdiff_t nx)
8+
void sharp_legendre_transform_recfac(double *r, ptrdiff_t lmax)
9+
void sharp_legendre_transform_recfac_s(float *r, ptrdiff_t lmax)
10+
void sharp_legendre_roots(int n, double *x, double *w)
11+
12+
# sharp_lowlevel.h
13+
ctypedef struct sharp_alm_info:
14+
pass
15+
16+
ctypedef struct sharp_geom_info:
17+
pass
18+
19+
void sharp_make_alm_info (int lmax, int mmax, int stride,
20+
ptrdiff_t *mvstart, sharp_alm_info **alm_info)
21+
22+
void sharp_make_geom_info (int nrings, int *nph, ptrdiff_t *ofs,
23+
int *stride, double *phi0, double *theta,
24+
double *wgt, sharp_geom_info **geom_info)
25+
26+
void sharp_destroy_alm_info(sharp_alm_info *info)
27+
void sharp_destroy_geom_info(sharp_geom_info *info)
28+
29+
ptrdiff_t sharp_map_size(sharp_geom_info *info)
30+
ptrdiff_t sharp_alm_count(sharp_alm_info *self)
31+
32+
33+
ctypedef enum sharp_jobtype:
34+
SHARP_YtW
35+
SHARP_Yt
36+
SHARP_WY
37+
SHARP_Y
38+
39+
ctypedef enum:
40+
SHARP_DP
41+
SHARP_ADD
42+
43+
void sharp_execute(sharp_jobtype type_,
44+
int spin,
45+
void *alm,
46+
void *map,
47+
sharp_geom_info *geom_info,
48+
sharp_alm_info *alm_info,
49+
int ntrans,
50+
int flags,
51+
double *time,
52+
unsigned long long *opcnt) nogil
53+
54+
ctypedef enum:
55+
SHARP_ERROR_NO_MPI
56+
57+
int sharp_execute_mpi_maybe (void *pcomm, sharp_jobtype type, int spin,
58+
void *alm, void *map, sharp_geom_info *geom_info,
59+
sharp_alm_info *alm_info, int ntrans, int flags, double *time,
60+
unsigned long long *opcnt) nogil
61+
62+
63+
cdef extern from "sharp_geomhelpers.h":
64+
void sharp_make_subset_healpix_geom_info(
65+
int nside, int stride, int nrings,
66+
int *rings, double *weight, sharp_geom_info **geom_info)
67+
void sharp_make_gauss_geom_info(
68+
int nrings, int nphi, double phi0,
69+
int stride_lon, int stride_lat, sharp_geom_info **geom_info)
70+
71+
cdef extern from "sharp_almhelpers.h":
72+
void sharp_make_triangular_alm_info (int lmax, int mmax, int stride,
73+
sharp_alm_info **alm_info)
74+
void sharp_make_rectangular_alm_info (int lmax, int mmax, int stride,
75+
sharp_alm_info **alm_info)
76+
void sharp_make_mmajor_real_packed_alm_info (int lmax, int stride,
77+
int nm, const int *ms, sharp_alm_info **alm_info)
78+
79+

0 commit comments

Comments
 (0)