[dune-fem] Segmentation fault when creating a new space for several times
Martin Nolte
nolte at mathematik.uni-freiburg.de
Thu Jun 18 14:53:44 CEST 2015
Hi Macro,
I suspect that your problem originates from a dangling reference. From the
second iteration on, you destruct the grid part (and create a new one), before
you destruct the discrete function space (which only happens when you reassign
the unique_ptr to the discrete function space).
Cound you try the following:
for(int i=0;i!=n;++i)
{
std::cout<<"iteration : "<<i<<std::endl;
// only the following line is new!
space.reset();
gridPart=std::unique_ptr<GridPartType>(new GridPartType(*grid));
space=std::unique_ptr<DiscreteFunctionSpaceType>(new
DiscreteFunctionSpaceType(*gridPart));
}
This will destruct the space before deleting the grid part.
Best,
Martin
On 06/18/2015 02:09 PM, Agnese, Marco wrote:
> Hi everybody,
> I found a bug which I don't understand. I have created this simple test to trigger it (the grid is dune/fem/space/test/3dgrid.dgf):
>
> #include <config.h>
> #include <iostream>
> #include <memory>
>
> #include <dune/fem/space/discontinuousgalerkin.hh>
> #include <dune/fem/space/lagrange.hh>
> #include <dune/fem/space/combinedspace.hh>
> #include <dune/fem/gridpart/leafgridpart.hh>
>
> int main(int argc,char** argv)
> {
> // init mpi
> Dune::Fem::MPIManager::initialize(argc,argv);
> try
> {
> // create grid
> typedef Dune::GridSelector::GridType GridType;
> typedef Dune::Fem::LeafGridPart<GridType> GridPartType;
> Dune::GridPtr<GridType> grid("3dgrid.dgf");
>
> // define spaces
> typedef Dune::Fem::FunctionSpace<double,double,GridType::dimensionworld,GridType::dimensionworld> FuncSpace1;
> typedef Dune::Fem::FunctionSpace<double,double,GridType::dimensionworld,1> FuncSpace2;
> typedef Dune::Fem::LagrangeDiscreteFunctionSpace<FuncSpace1,GridPartType,2> DiscreteFunctionSpaceType1;
> typedef Dune::Fem::LagrangeDiscontinuousGalerkinSpace<FuncSpace2,GridPartType,0> DiscreteFunctionSpaceType2;
> typedef Dune::Fem::TupleDiscreteFunctionSpace<DiscreteFunctionSpaceType1,DiscreteFunctionSpaceType2> DiscreteFunctionSpaceType;
>
> // create function space n times
> const int n(10);
> std::unique_ptr<GridPartType> gridPart;
> std::unique_ptr<DiscreteFunctionSpaceType> space;
> for(int i=0;i!=n;++i)
> {
> std::cout<<"iteration : "<<i<<std::endl;
> gridPart=std::unique_ptr<GridPartType>(new GridPartType(*grid));
> space=std::unique_ptr<DiscreteFunctionSpaceType>(new DiscreteFunctionSpaceType(*gridPart));
> }
>
> return 0;
> }
> catch(const Dune::Exception& exception)
> {
> std::cerr<<exception<<std::endl;
> return 1;
> }
> }
>
> The output is
>
> iteration : 0
> iteration : 1
> iteration : 2
> terminate called after throwing an instance of 'Dune::InvalidStateException'
> [macomp000:06078] *** Process received signal ***
> [macomp000:06078] Signal: Aborted (6)
> [macomp000:06078] Signal code: (-6)
> [macomp000:06078] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10340)[0x7fdcb6e00340]
> [macomp000:06078] [ 1] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x39)[0x7fdcb39d4bb9]
> [macomp000:06078] [ 2] /lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7fdcb39d7fc8]
> [macomp000:06078] [ 3] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x155)[0x7fdcb72846b5]
> [macomp000:06078] [ 4] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x5e836)[0x7fdcb7282836]
> [macomp000:06078] [ 5] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x5d8f9)[0x7fdcb72818f9]
> [macomp000:06078] [ 6] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(__gxx_personality_v0+0x52a)[0x7fdcb72824aa]
> [macomp000:06078] [ 7] /lib/x86_64-linux-gnu/libgcc_s.so.1(+0xfff3)[0x7fdcb701dff3]
> [macomp000:06078] [ 8] /lib/x86_64-linux-gnu/libgcc_s.so.1(_Unwind_Resume+0x57)[0x7fdcb701e517]
> [macomp000:06078] [ 9] ./combinedspacetest[0x41d464]
> [macomp000:06078] [10] ./combinedspacetest[0x43fb19]
> [macomp000:06078] [11] ./combinedspacetest[0x408dfc]
> [macomp000:06078] [12] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fdcb39bfec5]
> [macomp000:06078] [13] ./combinedspacetest[0x409e3c]
> [macomp000:06078] *** End of error message ***
> Aborted (core dumped)
>
> So it works for 2 iterations and then fails. What is the issue?
>
> Thank you very much,
> Cheers,
> Marco.
> _______________________________________________
> dune-fem mailing list
> dune-fem at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-fem
>
--
Dr. Martin Nolte <nolte at mathematik.uni-freiburg.de>
Universität Freiburg phone: +49-761-203-5630
Abteilung für angewandte Mathematik fax: +49-761-203-5632
Hermann-Herder-Straße 10
79104 Freiburg, Germany
More information about the dune-fem
mailing list