Commit 18611991 authored by gsell's avatar gsell

Python support added

parent 603366bc
Pipeline #5 skipped
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
ACLOCAL_FLAGS="-I m4 $ACLOCAL_FLAGS"
ACLOCAL_FLAGS="-I m4 -I . $ACLOCAL_FLAGS"
LIBTOOLIZE_FLAGS="--force $LIBTOOLIZE_FLAGS"
AUTOMAKE_FLAGS="--add-missing --copy --foreign $AUTOMAKE_FLAGS"
......
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_pkg_swig.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_PKG_SWIG([major.minor.micro], [action-if-found], [action-if-not-found])
#
# DESCRIPTION
#
# This macro searches for a SWIG installation on your system. If found,
# then SWIG is AC_SUBST'd; if not found, then $SWIG is empty. If SWIG is
# found, then SWIG_LIB is set to the SWIG library path, and AC_SUBST'd.
#
# You can use the optional first argument to check if the version of the
# available SWIG is greater than or equal to the value of the argument. It
# should have the format: N[.N[.N]] (N is a number between 0 and 999. Only
# the first N is mandatory.) If the version argument is given (e.g.
# 1.3.17), AX_PKG_SWIG checks that the swig package is this version number
# or higher.
#
# As usual, action-if-found is executed if SWIG is found, otherwise
# action-if-not-found is executed.
#
# In configure.in, use as:
#
# AX_PKG_SWIG(1.3.17, [], [ AC_MSG_ERROR([SWIG is required to build..]) ])
# AX_SWIG_ENABLE_CXX
# AX_SWIG_MULTI_MODULE_SUPPORT
# AX_SWIG_PYTHON
#
# LICENSE
#
# Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
# Copyright (c) 2008 Alan W. Irwin
# Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
# Copyright (c) 2008 Andrew Collier
# Copyright (c) 2011 Murray Cumming <murrayc@openismus.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 11
AC_DEFUN([AX_PKG_SWIG],[
# Ubuntu has swig 2.0 as /usr/bin/swig2.0
AC_PATH_PROGS([SWIG],[swig swig2.0])
if test -z "$SWIG" ; then
m4_ifval([$3],[$3],[:])
elif test -n "$1" ; then
AC_MSG_CHECKING([SWIG version])
[swig_version=`$SWIG -version 2>&1 | grep 'SWIG Version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`]
AC_MSG_RESULT([$swig_version])
if test -n "$swig_version" ; then
# Calculate the required version number components
[required=$1]
[required_major=`echo $required | sed 's/[^0-9].*//'`]
if test -z "$required_major" ; then
[required_major=0]
fi
[required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
[required_minor=`echo $required | sed 's/[^0-9].*//'`]
if test -z "$required_minor" ; then
[required_minor=0]
fi
[required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
[required_patch=`echo $required | sed 's/[^0-9].*//'`]
if test -z "$required_patch" ; then
[required_patch=0]
fi
# Calculate the available version number components
[available=$swig_version]
[available_major=`echo $available | sed 's/[^0-9].*//'`]
if test -z "$available_major" ; then
[available_major=0]
fi
[available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
[available_minor=`echo $available | sed 's/[^0-9].*//'`]
if test -z "$available_minor" ; then
[available_minor=0]
fi
[available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
[available_patch=`echo $available | sed 's/[^0-9].*//'`]
if test -z "$available_patch" ; then
[available_patch=0]
fi
# Convert the version tuple into a single number for easier comparison.
# Using base 100 should be safe since SWIG internally uses BCD values
# to encode its version number.
required_swig_vernum=`expr $required_major \* 10000 \
\+ $required_minor \* 100 \+ $required_patch`
available_swig_vernum=`expr $available_major \* 10000 \
\+ $available_minor \* 100 \+ $available_patch`
if test $available_swig_vernum -lt $required_swig_vernum; then
AC_MSG_WARN([SWIG version >= $1 is required. You have $swig_version.])
SWIG=''
m4_ifval([$3],[$3],[])
else
AC_MSG_CHECKING([for SWIG library])
SWIG_LIB=`$SWIG -swiglib`
AC_MSG_RESULT([$SWIG_LIB])
m4_ifval([$2],[$2],[])
fi
else
AC_MSG_WARN([cannot determine SWIG version])
SWIG=''
m4_ifval([$3],[$3],[])
fi
fi
AC_SUBST([SWIG_LIB])
])
......@@ -16,6 +16,7 @@ ENABLE_DEBUG='no'
ENABLE_C='yes'
ENABLE_FORTRAN='no'
ENABLE_PARALLEL='no'
ENABLE_PYTHON='no'
###############################################################################
# --enable-xxx and --with-xxx Arguments
......@@ -39,6 +40,13 @@ AC_ARG_ENABLE(
[ENABLE_FORTRAN=$enableval])
AM_CONDITIONAL([ENABLE_FORTRAN], [test "$ENABLE_FORTRAN" = "yes"])
AC_ARG_ENABLE(
[python],
[AS_HELP_STRING([--enable-python],
[Compile the Python interface [default=no]])],
[ENABLE_PYTHON=$enableval])
AM_CONDITIONAL([ENABLE_PYTHON], [test "$ENABLE_PYTHON" = "yes"])
AC_ARG_ENABLE(
[parallel],
[AS_HELP_STRING([--enable-parallel],
......@@ -280,6 +288,50 @@ else
AC_MSG_RESULT([no])
fi
# python enabled?
if test "X$ENABLE_PYTHON" = "Xyes"; then
AM_PATH_PYTHON([2.5])
AX_PKG_SWIG([1.3], [], [ AC_MSG_ERROR([SWIG is required to build..]) ])
#SWIG_ENABLE_CXX
#SWIG_PYTHON
PYTHON_PREFIX=`python-config --prefix`
PYTHON_EXEC_PREFIX=`python-config --exec-prefix`
# make sure numpy is available..
AC_MSG_CHECKING([for numpy support])
NUMPY_INCLUDE=`${PYTHON} -c 'import numpy; print numpy.get_include()'`
if test "X$?" = "X0" ; then
AC_MSG_RESULT([$NUMPY_INCLUDE])
else
AC_MSG_RESULT([no])
exit 1
fi
AC_SUBST([NUMPY_INCLUDE])
#check for parallel support
if test "X$ENABLE_PARALLEL" = "Xyes"; then
AC_MSG_CHECKING([for mpi4py support])
MPI4PY_INCLUDE=`${PYTHON} -c 'import mpi4py; print mpi4py.get_include()'`
if test "X$?" = "X0" ; then
AC_MSG_RESULT([$MPI4PY_INCLUDE])
else
AC_MSG_RESULT([no])
exit 1
fi
AC_SUBST([MPI4PY_INCLUDE])
fi
AC_MSG_RESULT([ok])
else
AC_MSG_CHECKING([if python interface is enabled])
AC_MSG_RESULT([no])
fi
######################## large indices enabled ###########################
AC_MSG_CHECKING([if large indices are enabled])
if test "X$USE_LARGE_INDICES" = "Xyes"; then
......@@ -403,6 +455,7 @@ AC_CONFIG_FILES([
src/include/h5core/Makefile
src/C/Makefile
src/Fortran/Makefile
src/Python/Makefile
test/Makefile
doc/Makefile
tools/Makefile
......@@ -434,4 +487,13 @@ AC_MSG_RESULT([AM_LDFLAGS = $AM_LDFLAGS])
AC_MSG_RESULT([LIBS = $LIBS])
AC_MSG_RESULT([HDF5_PREFIX = $HDF5_PREFIX])
AC_MSG_RESULT([LUSTREROOT = $LUSTREROOT])
if test "x$ENABLE_PYTHON" = "xyes"; then
AC_MSG_RESULT([PYTHON = $PYTHON])
AC_MSG_RESULT([SWIG = $SWIG])
AC_MSG_RESULT([NUMPY_INCLUDE = $NUMPY_INCLUDE])
if test "x$ENABLE_PARALLEL" = "xyes"; then
AC_MSG_RESULT([MPI4PY_INCLUDE = $MPI4PY_INCLUDE])
fi
fi
AC_MSG_RESULT([ ])
%module H5hut
%{
#define SWIG_FILE_WITH_INIT
#include <stdint.h>
#include "h5core/h5_types.h"
//#include "H5.h"
#include "H5hut.h"
%}
%import <stdint.i>
%include numpy.i
%apply unsigned long int { h5_prop_t };
%apply unsigned long int { h5_file_t };
%apply (unsigned long long* IN_ARRAY1) { h5_size_t* };
%apply (unsigned int* IN_ARRAY1) { h5_uint32_t* }; //uint32_t
%apply (unsigned long long* IN_ARRAY1) { h5_uint64_t* }; //uint64_t
%apply (int* IN_ARRAY1) { h5_int32_t* }; //int32_t
%apply (long long* IN_ARRAY1) { h5_int64_t* }; //int64_t
%apply (float* IN_ARRAY1) { h5_float32_t* };
%apply (double* IN_ARRAY1) { h5_float64_t* };
%init %{
import_array();
%}
%ignore h5_report_errorhandler;
%ignore h5_abort_errorhandler;
%ignore h5priv_vprintf;
%ignore h5_verror;
%ignore H5ReportErrorhandler;
%ignore H5AbortErrorhandler;
%include "h5core/h5_types.h"
//%include "H5.h"
//%include "H5_attribs.h"
%include "H5_model.h"
%include "H5hut.h"
%include "H5Block_attribs.h"
//%include "H5Block.h"
%include "H5Block_io.h"
%include "H5Block_model.h"
//%include "H5Part.h"
%include "H5Part_io.h"
%include "H5Part_model.h"
//%include "H5Fed_adjacency.h"
//%include "H5Fed.h"
//%include "H5Fed_model.h"
//%include "H5Fed_retrieve.h"
//%include "H5Fed_store.h"
//%include "H5Fed_tags.h"
%module H5hut_mpi
%{
#define SWIG_FILE_WITH_INIT
#define PARALLEL_IO 1
#include <mpi.h>
#include <stdint.h>
#include "h5core/h5_types.h"
//#include "H5.h"
#include "H5hut.h"
%}
%import <stdint.i>
%include numpy.i
%apply unsigned long int { h5_prop_t };
%apply unsigned long int { h5_file_t };
%apply (unsigned long long* IN_ARRAY1) { h5_size_t* };
%apply (unsigned int* IN_ARRAY1) { h5_uint32_t* }; //uint32_t
%apply (unsigned long long* IN_ARRAY1) { h5_uint64_t* }; //uint64_t
%apply (int* IN_ARRAY1) { h5_int32_t* }; //int32_t
%apply (long long* IN_ARRAY1) { h5_int64_t* }; //int64_t
%apply (float* IN_ARRAY1) { h5_float32_t* };
%apply (double* IN_ARRAY1) { h5_float64_t* };
%init %{
import_array();
%}
%include mpi4py/mpi4py.i
%mpi4py_typemap(Comm, MPI_Comm);
%typemap(in) MPI_Comm* {
MPI_Comm *ptr = (MPI_Comm *)0;
int res = SWIG_AsPtr_MPI_Comm($input, &ptr);
if (!SWIG_IsOK(res) || !ptr) {
SWIG_exception_fail(SWIG_ArgError((ptr ? res : SWIG_TypeError)), "in method '" "$symname" "', argument " "$argnum"" of type '" "MPI_Comm""'");
}
$1 = ptr;
if (SWIG_IsNewObj(res)) free((char*)ptr);
}
%ignore h5_report_errorhandler;
%ignore h5_abort_errorhandler;
%ignore h5priv_vprintf;
%ignore h5_verror;
%ignore H5ReportErrorhandler;
%ignore H5AbortErrorhandler;
%include "h5core/h5_types.h"
//%include "H5.h"
//%include "H5_attribs.h"
%include "H5_model.h"
%include "H5hut.h"
%include "H5Block_attribs.h"
//%include "H5Block.h"
%include "H5Block_io.h"
%include "H5Block_model.h"
//%include "H5Part.h"
%include "H5Part_io.h"
%include "H5Part_model.h"
//%include "H5Fed_adjacency.h"
//%include "H5Fed.h"
//%include "H5Fed_model.h"
//%include "H5Fed_retrieve.h"
//%include "H5Fed_store.h"
//%include "H5Fed_tags.h"
if ENABLE_PYTHON
if ENABLE_PARALLEL
BUILT_SOURCES = H5hut_mpi_wrap.c
SWIG_SOURCES = H5hut_mpi.i $(MPI4PY_INCLUDE)/mpi4py/mpi4py.i numpy.i
pkgpython_PYTHON = H5hut_mpi.py __init__.py
pkgpyexec_LTLIBRARIES = _H5hut_mpi.la
_H5hut_mpi_la_SOURCES = H5hut_mpi_wrap.c $(SWIG_SOURCES)
_H5hut_mpi_la_CPPFLAGS = -DPARALLEL_IO $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/src/include -I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION)/ -I$(MPI4PY_INCLUDE) -I$(NUMPY_INCLUDE)
_H5hut_mpi_la_LDFLAGS = -module
_H5hut_mpi_la_LIBADD = $(top_builddir)/src/h5core/libH5hut.la
H5hut_mpi_wrap.c : $(SWIG_SOURCES)
$(SWIG) $(SWIG_PYTHON_OPT) -python -DPARALLEL_IO -I$(top_srcdir)/src/include -I$(MPI4PY_INCLUDE) -o $@ $<
else
BUILT_SOURCES = H5hut_wrap.c
SWIG_SOURCES = H5hut.i numpy.i
pkgpython_PYTHON = H5hut.py __init__.py
pkgpyexec_LTLIBRARIES = _H5hut.la
_H5hut_la_SOURCES = H5hut_wrap.c $(SWIG_SOURCES)
_H5hut_la_CPPFLAGS = $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/src/include -I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION)/ -I$(NUMPY_INCLUDE)
_H5hut_la_LDFLAGS = -module
_H5hut_la_LIBADD = $(top_builddir)/src/h5core/libH5hut.la
H5hut_wrap.c : $(SWIG_SOURCES)
$(SWIG) $(SWIG_PYTHON_OPT) -python -I$(top_srcdir)/src/include -o $@ $<
endif
#all-local:
# $(INSTALL) -d $(DESTDIR)/site-packages/h5hut
# $(INSTALL) -m644 H5hut.py $(DESTDIR)/site-packages/h5hut/
# $(INSTALL) -m644 .libs/_H5hut.so $(DESTDIR)/site-packages/h5hut/
endif
clean: clean-am
clean-local:
$(RM) -f *~ H5hut_wrap.c H5hut.py H5hut.pyc H5hut_mpi_wrap.c H5hut_mpi.py H5hut_mpi.pyc
#TODO: use the rewrite to swap depending whether mpi is there are not..
import numpy
try:
import H5hut_mpi as H5hut_rewrite
from H5hut_mpi import *
except:
import H5hut as H5hut_rewrite
from H5hut import *
__h5hut_table__ = {}
# for now assume last parameter is the data field..
funcx = """
def {0}(*args, **kwargs):
import numpy
if type(args[-1]) is numpy.ndarray:
#print "writing type", args[-1].dtype
__h5hut_table__['{0}'][args[-1].dtype](*args, **kwargs)
elif ((type(args[-1]) is list or type(args[-1]) is tuple) and len(args[-1]) > 0):
#print "writing type", type(args[-1][0]).dtype
__h5hut_table__['{0}'][numpy.dtype(type(args[-1][0]))](*args, **kwargs)
else:
print 'last argument is not a numpy data array'
"""
def __update_types__():
import numpy
import sys
import inspect
__h5hut_api__ = dir(H5hut_rewrite)
__h5hut_types__ = [ "Int32", "Int64", "Float32", "Float64" ]
__numpy_types__ = [ numpy.dtype(numpy.int32),
numpy.dtype(numpy.int64),
numpy.dtype(numpy.float32),
numpy.dtype(numpy.float64) ]
for __i__ in __h5hut_api__:
for __j__ in __h5hut_types__:
if __j__ in __i__:
key = __i__[:-len(__j__)]
numpy_key = __numpy_types__[__h5hut_types__.index(__j__)]
func = H5hut_rewrite.__dict__[__i__]
if key not in __h5hut_table__:
__h5hut_table__[key] = {}
__h5hut_table__[key][numpy_key] = func
del H5hut_rewrite.__dict__[__i__]
del sys.modules["H5hut"].__dict__[__i__]
for __new_func__ in __h5hut_table__.keys():
types = __h5hut_table__[__new_func__]
#args = inspect.getargspec(types[0])
#print __new_func__
result = funcx.format(__new_func__)
exec(result)
#H5hut_rewrite.__dict__[__new_func__] = globals()[__new_func__]
sys.modules["H5hut"].__dict__[__new_func__] = locals()[__new_func__]
__update_types__()
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment