Commit eafc2a15 authored by Sebastian Ohlmann's avatar Sebastian Ohlmann

add first version of python wrapper

- depends on python, cython, mpi4py and numpy
- currently only dependency check on python
- should be done optionally
- converts wrapper.pyx to wrapper.c using cython, then compiles this to
  a python extension
- installs the files such that they can be imported with `import pyelpa`
  in python
parent 9e3bfb2e
......@@ -612,6 +612,17 @@ endif
#test_c_cannon@SUFFIX@_LDADD = $(test_program_ldadd) $(FCLIBS)
#test_c_cannon@SUFFIX@_CFLAGS = $(test_program_cflags)
# python wrapper
pyelpadir = $(pythondir)/pyelpa
pyelpa_PYTHON = python/__init__.py python/distributedmatrix.py
pyelpa_LTLIBRARIES = wrapper.la
wrapper_la_SOURCES = python/wrapper.c
wrapper_la_LDFLAGS = -module -avoid-version -shared $(AM_LDFLAGS)
wrapper_la_LIBADD = libelpa@SUFFIX@.la
wrapper_la_CFLAGS = -I$(PYTHON_INCLUDE) $(AM_CFLAGS)
python/wrapper.c: python/wrapper.pyx
cython $<
# test scripts
......
......@@ -1275,6 +1275,22 @@ else
AC_MSG_RESULT([no])
fi
AM_PATH_PYTHON([3.6])
AC_ARG_VAR([PYTHON_INCLUDE], [Include flags for python, bypassing python-config])
AC_ARG_VAR([PYTHON_CONFIG], [Path to python-config])
AS_IF([test -z "$PYTHON_INCLUDE"], [
AS_IF([test -z "$PYTHON_CONFIG"], [
AC_PATH_PROGS([PYTHON_CONFIG],
[python$PYTHON_VERSION-config python-config],
[no],
[`dirname $PYTHON`])
AS_IF([test "$PYTHON_CONFIG" = no], [AC_MSG_ERROR([cannot find python-config for $PYTHON.])])
])
AC_MSG_CHECKING([python include flags])
PYTHON_INCLUDE=`$PYTHON_CONFIG --includes`
AC_MSG_RESULT([$PYTHON_INCLUDE])
])
AC_OUTPUT
......
"""pyelpa -- python wrapper for ELPA
This wrapper uses cython to wrap the C API of ELPA (Eigenvalue SoLvers for
Petaflop-Applications) so that it can be called from python.
Examples:
1. Use the Elpa object to access the eigenvectors/eigenvalues wrapper:
>>> import numpy as np
... from pyelpa import ProcessorLayout, DistributedMatrix, Elpa
... from mpi4py import MPI
... import sys
...
... # set some parameters for matrix layout
... na = 1000
... nev = 200
... nblk = 16
...
... # initialize processor layout, needed for calling ELPA
... comm = MPI.COMM_WORLD
... layout_p = ProcessorLayout(comm)
...
... # create arrays
... a = DistributedMatrix(layout_p, na, nev, nblk)
... eigenvectors = DistributedMatrix(layout_p, na, nev, nblk)
... eigenvalues = np.zeros(na, dtype=np.float64)
...
... # initialize elpa
... e = Elpa.from_distributed_matrix(a)
...
... # set input matrix (a.data) on this core (a is stored in a block-cyclic
... # distributed layout; local size: a.na_rows x a.na_cols)
... # Caution: using this, the global matrix will not be symmetric; this is just
... # and example to show how to access the data
... a.data[:, :] = np.random.rand(a.na_rows, a.na_cols).astype(np.float64)
...
... # now compute nev of na eigenvectors and eigenvalues
... e.eigenvectors(a.data, eigenvalues, eigenvectors.data)
...
... # now eigenvectors.data contains the local part of the eigenvector matrix
... # which is stored in a block-cyclic distributed layout
...
... # now eigenvalues contains all computed eigenvalues on all cores
...
... # now compute nev of na eigenvalues
... e.eigenvalues(a.data, eigenvalues)
...
... # now eigenvalues contains all computed eigenvalues on all cores
2. Use the functions provided by the DistributedMatrix object:
>>> import numpy as np
... from pyelpa import DistributedMatrix
...
... # set some parameters for matrix layout
... na = 1000
... nev = 200
... nblk = 16
...
... a = DistributedMatrix.from_comm_world(na, nev, nblk)
... # use a diagonal matrix as input
... matrix = np.diagflat(np.arange(na)**2)
... # set from global matrix
... a.set_data_from_global_matrix(matrix)
...
... data = a.compute_eigenvectors()
... eigenvalues = data['eigenvalues']
... eigenvectors = data['eigenvectors']
... # now eigenvectors.data contains the local part of the eigenvector matrix
... # which is stored in a block-cyclic distributed layout
...
... # now eigenvalues contains all computed eigenvalues on all cores
"""
from .wrapper import Elpa
from .distributedmatrix import ProcessorLayout, DistributedMatrix
__all__ = ['ProcessorLayout', 'DistributedMatrix', 'Elpa']
This diff is collapsed.
This diff is collapsed.
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