- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah, missed that bit - I scrolled down to the source code :). That explains it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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").
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK I guess the the different between allocatable and pointer is heap or stack. You maybe have a stack overflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Allocated arrays go on the heap. You might want to read the heap arrays option also or stack size option
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page