[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Python<->C cross-language interoperability




I have run the example.

BTW: run with -snes_monitor the nonlinear convergence is terribly slow.

BTW: I have added a --download-numpy and --download-petsc4py to petsc-dev. Preliminary version
uses the SVN versions. Eventually I'd like it to auto-select the correct version.


   Barry

On Nov 23, 2007, at 2:38 PM, Lisandro Dalcin wrote:

On 11/23/07, Matthew Knepley <knepley@xxxxxxxxx> wrote:
Yes, we should definitely do this. I think I already have the support for
linking to the Python library somewhere.


Perhaps I will also ask in the near future for adding two 'slots' in
the base PetscObject structure for better supporting petsc4py.

Yes, this is fine too. We should try and do it before the next release
since it will be a major release.

Nice, then I'll try to add the needed changes in petsc-dev, and I'll will surely need your help for adding support in configure system.

If any of you want to take a look, I have a trivial C SNES example,

Cool, where is it?

Well, all this is in petsc4py SVN repo, the specific example for SNES is at this location:

http://petsc4py.googlecode.com/svn/trunk/petsc/lib/ext/petsc/src/snes/impls/python/

The C example is 'ex1.c' (note the line calling Py_Initialize() ), the
equivalent Python example is 'ex1.py'. Both examples calls the methods
of class 'MyNewton' (implemented in file 'mysolver.py').

The actual SNESPYTHON type is implemented in file 'python.c', but that
type is actually available through petsc4py, and automatically
registered at import time.

To run the example, you have to build petsc4py SVN using petsc-2.3.3
or petsc-dev (use shared libs), and install petsc4py somewere (and put
that location on PYTHONPATH). After that, build 'ex1.c' (the
'makefile' is using the old bmake paths, fix for the petsc-dev case)
and run it like the following;

$ make ex1
$ ./ex1 -snes_type python -trace

Your will see in your terminal (because of -trace option, look at
mysolver.py at MyNewton.setFromOptions() methods) a lot of ouput
showing the methods and aguments passed during the complete nonlinear
solve.

Ask me if you have trouble with something.

I'll wait for your comments. Please note that all this is very
preliminar and was develeped in a couple of days, there is room for a
lot of improvement.


-- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594