- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Dear Sir or Madame,
I came across a Valgrind error message that is related to the use of Fortran pointers. See below for a minimal testcase.
Compiler: ifort (IFORT) 19.0.5.281 20190815
IntelMPI: Version 2019 Update 6 Build 20191024 (needed for loading the Valgrind module)
Valgrind: valgrind-3.14.0
Running
valgrind ./a.out
produces the error message (among other messages)
==22137== Invalid write of size 8
==22137== at 0x404659: MAIN__ (test.f:11)
==22137== by 0x4037D1: main (in /p/home/jusers/friedrich1/jureca/git/spex/tests/valgrind/a.out)
==22137== Address 0x1ffe859090 is on thread 1's stack
==22137== in frame #0, created by MAIN__ (test.f:1)
==22137==
==22137== Invalid read of size 8
==22137== at 0x404354: MAIN__ (test.f:11)
==22137== by 0x4037D1: main (in /p/home/jusers/friedrich1/jureca/git/spex/tests/valgrind/a.out)
==22137== Address 0x1ffe859090 is on thread 1's stack
==22137== in frame #0, created by MAIN__ (test.f:1)
if the program has been compiled in the following way:
ifort -cpp -O0 -g -DALLOC=pointer -DDIM=63 test.f (and any DIM higher than 63)
but NOT if it has been compiled like this:
ifort -cpp -O0 -g -DALLOC=pointer -DDIM=62 test.f (and any DIM smaller than 62)
ifort -cpp -O0 -g -DALLOC=allocatable -DDIM=63 test.f (and any other DIM).
GFORTRAN does not produce this error.
I would like to know if I should worry about this error. Or is there a violation of the Fortran standard in the code?
Thank you.
Best wishes
Christoph
**************
TESTCASE:
program test
implicit none
real(8), ALLOC :: a(:,:,:), b(:,:,:)
write(*,*) DIM
allocate ( a(DIM,DIM,DIM) )
allocate ( b(DIM,DIM,DIM) )
a = 0
b = 0
a = a - b
deallocate(a)
deallocate(b)
end
Enlace copiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
What is the value of DIM in this test program? I do not see it set. Oh, and there are other errors, like "ALLOC" instead of "ALLOCATABLE". This program can't be correct.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
DIM and ALLOC are set by the compilation command (preprocessor), e.g.,
ifort -cpp -O0 -g -DALLOC=pointer -DDIM=63 test.f
So, in this case, DIM would be set as "63" and ALLOC would be set as "pointer".
Christoph
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Ah, missed that bit - I scrolled down to the source code :). That explains it.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
I have never used -D but reading the help. "Defines a symbol name that can be associated with an optional value. This definition is used during preprocessing in both Intel® Fortran conditional compilation directives and the fpp preprocessor. "
-D It does not define a Fortran variable so I do not think your usage is valid.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
No, what "-DDIM=63" simply does is replacing all occurrences of DIM by 63 before compilation. You can also do that by hand and compile without the preprocessor ("-cpp").
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
OK I guess the the different between allocatable and pointer is heap or stack. You maybe have a stack overflow.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Thank you.
Interesting possibility. I have just checked it: When pointers are allocated, the memory goes to the heap. (I checked the VmStk value of /proc/PID/status.)
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Allocated arrays go on the heap. You might want to read the heap arrays option also or stack size option

- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla