Different result when compiling with -fcheck=bounds

62 views
Skip to first unread message

Enzo Gaggioli

unread,
Nov 6, 2017, 9:12:46 PM11/6/17
to GNU Fortran
Hi there. I have written a long program in fortran 77, which uses subroutines, and common blocks. This program solves an integrodifferential equation in five dimensions, using an iterative scheme, and for the convergence criteria I am using the difference of the norm of the solution array for two consecutive iterations. When this norm is small enough, the program ends.

Now here is the problem. I was making some test with the code, and rewriting some parts of it. The thing is that when I compiled with the option -fbounds=check, the solution doesn't converge for some criteria, and the difference computed for successive iterations differs, for exactly the same program, when I compile with out the -fbounds=check option.

This is something related to the gnu compiler or there is something wrong with my code?

Kind regards,
Enzo

RD

unread,
Nov 7, 2017, 1:44:54 AM11/7/17
to gnu-f...@googlegroups.com, e.l.ga...@gmail.com
When code output changes like this it often means you have a code problem.

My interpretation is that when the code is compiled it is packed into memory with variables adjacent to each other in a certain way. When you add the compiler flag, additional code is packed in during the compilation to do the bounds checking or whatever. This re-orders the code in memory.

Now, lets say your code has an error where it writes a variable outside its memory address. What it overwrites will change under the two different compile cases. In one case it might overwrite something no longer needed, with no ill effect, and in the other case it might overwrite its own loop counter variable, ruining the output.

I think the flag you want is “-fbounds-check” not “-fbounds=check”. So not sure that your code is actually checking for out-of-bounds situations.

If your common blocks hold huge amounts of data (over 2GB), you may be exceeding the total allocated space capacity.

See for example the -mcmodel=medium or =large flag

Link: https://software.intel.com/en-us/node/691767

R
> --
> You received this message because you are subscribed to the Google Groups "GNU Fortran" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gnu-fortran...@googlegroups.com.
> To post to this group, send email to gnu-f...@googlegroups.com.
> Visit this group at https://groups.google.com/group/gnu-fortran.
> For more options, visit https://groups.google.com/d/optout.

Edmondo Giovannozzi

unread,
Nov 7, 2017, 9:03:55 AM11/7/17
to GNU Fortran
I suggest you to use alsothe options :

  -fsanitize-address -static-libasan

It will check if you write or read outside array boundaries even in situation where the Fortran compiler cannot help.
Reply all
Reply to author
Forward
0 new messages