optimization bug in gfortran 6.3?
James Spencer
james.s.spencer@gmail.com
Sun May 14 22:21:00 GMT 2017
Hi Steve,
On 14 May 2017 at 18:22, Steve Kargl <sgk@troutmask.apl.washington.edu> wrote:
> On Sun, May 14, 2017 at 05:42:47PM +0100, James Spencer wrote:
>>
>> https://github.com/hande-qmc/hande/blob/master/src/energy_evaluation.F90#L794.
>>
>
> Assuming those that might be able to help you use git is
> not necessarily valid.
Sorry, I didn't mean to assume this; the link was just for context of
where the code came from.
I have now reduced it to a standalone example (attached) which shows
essentially the same behaviour, except that the call to
update_proj_energy_mol where excitation%nexcit = 1 is correctly
executed in the original code but shows the same problem in the
reduced case. I tried to reduce the example further but gave up after
a few attempts all changed the behaviour to that I expected.
gcc 6.3.0 has different behaviour at -O3 and at -g:
$ gfortran --version
GNU Fortran (GCC) 6.3.1 20170306
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
$ make clean && make OPT=-O3 && ./test
rm -f test *.mod *.o *.optimized
gfortran -O3 -fdump-tree-optimized -Wall -Wextra -c
hamiltonian_molecular.f90
gfortran -O3 -fdump-tree-optimized -Wall -Wextra -c
energy_evaluation.f90
gfortran -O3 -fdump-tree-optimized -Wall -Wextra -c test.f90
gfortran energy_evaluation.o hamiltonian_molecular.o test.o -o test
0.0000000000000000
0.0000000000000000
$ make clean && make OPT=-g && ./test
rm -f test *.mod *.o *.optimized
gfortran -g -fdump-tree-optimized -Wall -Wextra -c
hamiltonian_molecular.f90
gfortran -g -fdump-tree-optimized -Wall -Wextra -c
energy_evaluation.f90
gfortran -g -fdump-tree-optimized -Wall -Wextra -c test.f90
gfortran energy_evaluation.o hamiltonian_molecular.o test.o -o test
60.000000000000000
-112.00000000000000
gfortran 7.1.0 behaves consistently:
$ gfortran --version
GNU Fortran (GCC) 7.1.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
$ make clean && make OPT=-O3 && ./test
rm -f test *.mod *.o *.optimized
gfortran -O3 -fdump-tree-optimized -Wall -Wextra -c
hamiltonian_molecular.f90
gfortran -O3 -fdump-tree-optimized -Wall -Wextra -c
energy_evaluation.f90
gfortran -O3 -fdump-tree-optimized -Wall -Wextra -c test.f90
gfortran energy_evaluation.o hamiltonian_molecular.o test.o -o test
60.000000000000000
-112.00000000000000
$ make clean && make OPT=-g && ./test
rm -f test *.mod *.o *.optimized
gfortran -g -fdump-tree-optimized -Wall -Wextra -c
hamiltonian_molecular.f90
gfortran -g -fdump-tree-optimized -Wall -Wextra -c
energy_evaluation.f90
gfortran -g -fdump-tree-optimized -Wall -Wextra -c test.f90
gfortran energy_evaluation.o hamiltonian_molecular.o test.o -o test
60.000000000000000
-112.00000000000000
The actual output should be 60 and -112. Given the different source
files and I'm not using link-time optimisation, I don't think gcc
6.3.0 with -O3 should be converting this code in energy_evaluation.f90
hmatel = slater_condon2_mol_excit(excitation%from_orb(1),
excitation%from_orb(2), &
excitation%to_orb(1),
excitation%to_orb(2), &
excitation%perm)
estimators%proj_energy = estimators%proj_energy + hmatel%r*pop(1)
to this in energy_evaluation.f90.211t.optimized:
_40 = &excitation_16(D)->perm;
_41 = &excitation_16(D)->to_orb[1];
_42 = &excitation_16(D)->to_orb[0];
_43 = &excitation_16(D)->from_orb[1];
_44 = &excitation_16(D)->from_orb[0];
*hmatel_14(D) = slater_condon2_mol_excit (_44, _43, _42, _41, _40);
_46 = *estimators_18(D).proj_energy;
_47 = *pop.0_5[0];
_48 = _47 * 0.0;
_49 = _46 + _48;
*estimators_18(D).proj_energy = _49;
which causes 0 to be accumulated instead of the true value.
James
> --
> Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt_bug.tar.gz
Type: application/x-gzip
Size: 1216 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20170514/66c57114/attachment.bin>
More information about the Fortran
mailing list