Segmentation fault at runtime with OpenMP

Jakub Jelinek jakub@redhat.com
Thu Feb 7 12:25:00 GMT 2008


On Thu, Feb 07, 2008 at 01:02:58PM +0100, Tobias Burnus wrote:
> Ignacio Fernández Galván wrote:
> >Is there anything wrong with this code? It compiles fine with
> >gfortran-20080206, but when I run the output I get a segmentation
> >fault.
> >  
> Using gfortran it does not crash here, but valgrind shows:
> 
> ==10362== Use of uninitialised value of size 8
> ==10362==    at 0x400926: inner.902 (aa.f90:15)
> ==10362==    by 0x4008FA: MAIN__.omp_fn.0 (aa.f90:8)
> ==10362==    by 0x400875: MAIN__ (aa.f90:8)
> ==10362==    by 0x40095B: main (fmain.c:21)
> 
> 
> The problem seems to be the variable k, which is uninitialized in the 
> subroutine "inner". Jakub, is the code valid or not?

I believe it is invalid.  The privatization affects the construct,
not the subroutines it calls, and the subroutine thus uses the shared
k (which is uninitialized).
You can ask in www.openmp.org/forum/ if you want a definitive answer.
In any case, if the standard mandated something else, I don't see how
it could be (easily) implementable.  Consider that the nested function
call can be made both outside of omp contexts and inside of them.

> PROGRAM Outer
>  IMPLICIT NONE
>  REAL, DIMENSION(100) :: A
>  INTEGER :: k
> 
> !$OMP PARALLEL DO PRIVATE(k)
>  DO k=1,SIZE(A)
>    CALL Inner()
>  END DO
> !$OMP END PARALLEL DO
> 
>  CONTAINS
>  SUBROUTINE Inner
>    IMPLICIT NONE
>    A(k)=0.0D0
>  END SUBROUTINE Inner
> 
> END PROGRAM Outer

	Jakub



More information about the Fortran mailing list