I wrote (for my class in Numerical Methods for Theoretical Physics) a very simple program for a Random Walk in dimension 2. Here it is:
program random_walk
This is quite a typical thing to observe. People hit this when they create artificial computations which only test performance and do not create a useful result. When the result is not printed, the compiler can recognize that it does not need the result for the program output and may completely omit the computation.
To examine it you can add the -fdump-tree-optimized
flag to get a special source form called GIMPLE and you can compare the output for those two variants of the source code. It writes the output to a file called yourfilename.f90.something.optimized
. I can indeed see a big part missing. Basically the whole r2
array and the operations with it are optimized out. You can also compare the generated assembly if you know that better.