[petsc-users] Segmentation faults: Derived types
Julian Andrej
juan at tf.uni-kiel.de
Sun Aug 21 09:00:33 CDT 2016
You need to generate the TAGS file first using
make alletags
in ${PETSC_DIR}. Then you need to visit the tags table using emacs.
On Sun, Aug 21, 2016 at 12:09 PM, Santiago Ospina De Los Rios
<sospinar at unal.edu.co> wrote:
> wow, what a dumb mistake. thank you very much!
>
> Since you've noticed me such error, I am taking the time to learn all of
> your advice about management and debugging code. Then I'm learning emacs and
> so... the matter is that you recommend to use PETSc tags which it's supposed
> to be in ${PETSC_DIR}/TAGS, but it seems to be changed or something because
> I wasn't able to find it.
>
> So, how can I use the tags you are referring to?
>
>
>
> 2016-08-19 14:40 GMT-05:00 Barry Smith <bsmith at mcs.anl.gov>:
>>
>>
>> You code has a bug right at the top:
>>
>> CALL PetscInitialize(PETSC_COMM_WORLD,ierr)
>>
>> should be
>>
>> CALL PetscInitialize(PETSC_NULL_CHARACTER,ierr)
>>
>> you were just lucky previously that the stack frame was different enough
>> that it did not previously crash. Once I corrected the code the new version
>> ran without crashing. I found the bug very easily by simply running the new
>> version directly in the debugger
>>
>> lldb ./ANSIFLOW
>>
>> and seeing it crashed with a crazy stack in petscinitialize_
>>
>> Barry
>>
>>
>> > On Aug 5, 2016, at 11:34 PM, Santiago Ospina De Los Rios
>> > <sospinar at unal.edu.co> wrote:
>> >
>> > Dear Barry,
>> >
>> > I tried to build a simple code with the same things I mentioned to you
>> > on last e-mail but it worked, which is more strange to me. So I built two
>> > branches on my git code to show you the problem:
>> >
>> > git code: https://github.com/SoilRos/ANISOFLOWPACK
>> >
>> > Branch: PETSc_debug_boolean_0
>> > The first one is a simple code which is working for what was designed.
>> > Forget sample problems, just compile and run the ANISOFLOW executable on src
>> > folder, if there are some verbose messages then the program is working.
>> >
>> > Branch: PETSc_debug_boolean_1
>> > The second one is just a modification of the first one adding the two
>> > booleans mentioned above in 01_Types.F90 file. I tried it in mac El Capitan
>> > and Ubuntu (with Valgrind) and PETSc 3.7.3 and 3.7.2 respectively, both with
>> > the same segmentation fault.
>> >
>> > PD: Although I already fixed it compressing the three booleans into one
>> > integer, I think is better if we try to figure out why there is a
>> > segmentation fault because I had similar problems before.
>> > PD2: Please obviate the variable description because are pretty out of
>> > date. I'm trying to change it, so it can be confusing.
>> >
>> > Best wishes,
>> > Santiago Ospina
>> >
>> > 2016-08-05 15:54 GMT-05:00 Barry Smith <bsmith at mcs.anl.gov>:
>> >
>> > > On Aug 1, 2016, at 4:41 PM, Santiago Ospina De Los Rios
>> > > <sospinar at unal.edu.co> wrote:
>> > >
>> > > Hello there,
>> > >
>> > > I'm having problems defining some variables into derived types in
>> > > Fortran. Before, I had a similar problems with an allocatable array
>> > > "PetsInt" but I solved it just doing a non-collective Petsc Vec. Today I'm
>> > > having troubles with "PetscBool" or "Logical":
>> > >
>> > > In a module which define the variables, I have the following:
>> > >
>> > > MODULE ANISOFLOW_Types
>> > >
>> > > IMPLICIT NONE
>> > >
>> > > #include <petsc/finclude/petscsys.h>
>> > > #include <petsc/finclude/petscvec.h>
>> > >
>> > > ...
>> > >
>> > > TYPE ConductivityField
>> > > PetscBool ::
>> > > DefinedByCvtZones=.FALSE. ! It produces the segmentation fault.
>> > > PetscBool ::
>> > > DefinedByPptZones=.FALSE. ! It produces the segmentation fault.
>> > > PetscBool ::
>> > > DefinedByCell=.FALSE.
>> > > ! Conductivity defined by zones (Local):
>> > > Vec :: ZoneID
>> > > TYPE(Tensor),ALLOCATABLE :: Zone(:)
>> > > ! Conductivity defined on every cell (Local):
>> > > Vec :: Cell
>> > > END TYPE ConductivityField
>> > >
>> > >
>> > > TYPE SpecificStorageField
>> > > PetscBool ::
>> > > DefinedByStoZones=.FALSE. ! It produces the segmentation fault.
>> > > PetscBool ::
>> > > DefinedByPptZones=.FALSE. ! It produces the segmentation fault.
>> > > PetscBool ::
>> > > DefinedByCell=.FALSE.
>> > > ! Specific Storage defined by zones (Local):
>> > > Vec :: ZoneID
>> > > Vec :: Zone
>> > > ! Specific Storage defined on every cell (Global).:
>> > > Vec :: Cell
>> > > END TYPE SpecificStorageField
>> > >
>> > > TYPE PropertiesField
>> > > TYPE(ConductivityField) :: Cvt
>> > > TYPE(SpecificStorageField) :: Sto
>> > > ! Property defined by zones (Local):
>> > > PetscBool :: DefinedByPptZones=.FALSE.
>> > > Vec :: ZoneID
>> > > END TYPE PropertiesField
>> > >
>> > > ...
>> > >
>> > > CONTAINS
>> > >
>> > > ...
>> > >
>> > > END MODULE ANISOFLOW_Types
>> > >
>> > >
>> > > Later I use it in the main program, with something like this
>> > >
>> > > PROGRAM ANISOFLOW
>> > >
>> > > USE ANISOFLOW_Types, ONLY : ... ,PropertiesField,
>> > > ...
>> > > ...
>> > >
>> > > IMPLICIT NONE
>> > >
>> > > #include <petsc/finclude/petscsys.h>
>> > >
>> > > ...
>> > > TYPE(PropertiesField) :: PptFld
>> > > ...
>> > >
>> > > CALL PetscInitialize(PETSC_COMM_WORLD,ierr)
>> > > ...
>> > > CALL PetscFinalize(ierr)
>> > >
>> > > END PROGRAM
>> > >
>> > >
>> > > When I run the program appears a Segmentation Fault, which disappears
>> > > when I comment the booleans marked in the code. Because I need them, I used
>> > > Valgrind to figure out what is happening but it is yet a mistery to me.
>> > >
>> > > Valgrind message:
>> > > ==5160==
>> > > ==5160== Invalid read of size 1
>> >
>> > It is curious that it says "of size 1" when we declare PetscBool to
>> > be a logical*4 I don't see anything obviously wrong.
>> >
>> > Please send a simple code we can compile and run that reproduces the
>> > problem.
>> >
>> > Barry
>> > > ==5160== at 0x4FB2156: petscinitialize_ (zstart.c:433)
>> > > ==5160== by 0x4030EA: MAIN__ (ANISOFLOW.F90:29) # line of petsc
>> > > inizalitation
>> > > ==5160== by 0x404380: main (ANISOFLOW.F90:3) # line of "USE
>> > > ANISOFLOW_Types, ONLY : ... ,PropertiesField, ..."
>> > > ==5160== Address 0xc54fff is not stack'd, malloc'd or (recently)
>> > > free'd
>> > > ==5160==
>> > >
>> > > Program received signal SIGSEGV: Segmentation fault - invalid memory
>> > > reference.
>> > >
>> > > Backtrace for this error:
>> > > #0 0x699E777
>> > > #1 0x699ED7E
>> > > #2 0x6F0BCAF
>> > > #3 0x4FB2156
>> > > #4 0x4030EA in anisoflow at ANISOFLOW.F90:29
>> > >
>> > > I think it is maybe related with petsc because the error popped out
>> > > just in its initialization, so if you know what's going on, I would
>> > > appreciate to tell me.
>> > >
>> > > Santiago Ospina
>> > > --
>> > >
>> > > --
>> > > Att:
>> > >
>> > > Santiago Ospina De Los Ríos
>> > > National University of Colombia
>> >
>> >
>> >
>> >
>> > --
>> >
>> > --
>> > Att:
>> >
>> > Santiago Ospina De Los Ríos
>> > National University of Colombia
>>
>
>
>
> --
>
> --
> Att:
>
> Santiago Ospina De Los Ríos
> National University of Colombia
More information about the petsc-users
mailing list