dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #10959
Re: Problems in assemble.py
On Friday 05 December 2008 11:11:42 Martin Sandve Alnæs wrote:
> 2008/12/5 Martin Sandve Alnæs <martinal@xxxxxxxxx>:
> > 2008/12/5 Johan Hake <hake@xxxxxxxxx>:
> >> On Friday 05 December 2008 08:55:44 Martin Sandve Alnæs wrote:
> >>> 2008/12/4 Johan Hake <hake@xxxxxxxxx>:
> >>> > On Thursday 04 December 2008 20:44:20 Anders Logg wrote:
> >>> >> I have moved the jit function and the code from get_dolfin_form to
> >>> >> separate modules.
> >>> >>
> >>> >> The JIT compilation seems to work fine, but the _ufc_form member in
> >>> >> the generated dolfin::Form subclass seems to be zero. See comment at
> >>> >> the top of the the assemble function.
> >>> >>
> >>> >> Any ideas what goes wrong? If we get this working, we can remove
> >>> >> most of the code from assemble.py and reuse it also in pde.py.
> >>> >
> >>> > It is fixed now.
> >>> >
> >>> > This is the same problem we have with the compiled elements and
> >>> > dofmaps in FunctionSpace. You need to store a reference to the
> >>> > compiled form, otherwise swig will garbage collect the form when it
> >>> > goes out of scope, killing also the actuall cpp_ufc_form.
> >>>
> >>> This is the kind of issue I'm hoping SWIGs shared_ptr bindings can help
> >>> us with.
> >>
> >> True. But I had no luck with it. I do not know where the error resides.
> >> I actually made a minimal test .cpp file I wrapped with swig, using both
> >> shared_ptr and raw pointers. This behaved as expected. Swig garbage
> >> collected the objects stored with raw pointers, but did not do it for
> >> the shared_ptr stored one. So it _should_ just work.
> >>
> >> Johan
> >
> > Can you share this test code? Details are rather important for this stuff
> > :)
> >
> > Maybe swig chooses the reference versions of dolfin::foo constructors.
> >
> > --
> > Martin
>
> Since I added the helper function with the nice short name
> reference_to_no_delete_pointer, we can add logging in
> it to see whenever a reference is put in a shared_ptr.
> Might be useful to debug this kind of thing.
Ok heres three files illustrating that shared_ptr works.
make
python test.py
make noshared
python test.py
You need swig version > 1.3.34. To test what I did in dolfin, comes with a bit
more hassle. Some caveats
1) There is a bug in swigs shared ptr handling for std::tr1::shared_ptr,
which is now fixed in svn. If you want to try this for dolfin, you
either have to dolfin_replace all std::tr1::shared_ptr with boost one,
or build swig from svn.
2) Even if the actuall code to turn on the shared_ptr stuff resides in
dolfin_shared_ptr_classes.i, compile_function and in ffc, we need to
manually turn on them for each one of the cases. It should be trivial
if you look in the right places ;). These are in dolfin.i and in
compile_function. For ffc.jit set options["shared_ptr"] = True
Johan
%module shared_ptr_test
%{
#include "shared_ptr_test.cpp"
%}
%include boost_shared_ptr.i
SWIG_SHARED_PTR(A,A)
SWIG_SHARED_PTR(B,B)
%include "shared_ptr_test.cpp"
shared:
swig -python -c++ -DUSE_SHARED_PTR shared_ptr_test.i
g++ -c shared_ptr_test_wrap.cxx -I/usr/include/python2.5 -DUSE_SHARED_PTR
g++ -shared shared_ptr_test_wrap.o -o _shared_ptr_test.so
noshared:
swig -python -c++ shared_ptr_test.i
g++ -c shared_ptr_test_wrap.cxx -I/usr/include/python2.5
g++ -shared shared_ptr_test_wrap.o -o _shared_ptr_test.so
Attachment:
test.py
Description: application/python
References