public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/59168] New: Wrong result with non-optimized (!) compilation
@ 2013-11-18 10:13 sarantis.pantazis at gmail dot com
  2013-11-18 10:14 ` [Bug fortran/59168] " sarantis.pantazis at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: sarantis.pantazis at gmail dot com @ 2013-11-18 10:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59168

            Bug ID: 59168
           Summary: Wrong result with non-optimized (!) compilation
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sarantis.pantazis at gmail dot com

I wanted to check the difference in CPU time in the calculation of a sum when
the terms are included in the same expression and when they are added
separately. For this reason I wrote the attached code.

First I compiled with
"gfortran -o test testPartialSum.f08"
and got the following results:

   199204048.    
   67108864.0    
  0.117000006      0.244000003

Then I compiled with 
"gfortran -o test testPartialSum.f08 -O3"
and got the following results:

   200000000.    
   200000000.    
   7.80000016E-02   7.50000030E-02

It seems clear that the optimized compilation provides the correct results but
the non-optimized one does not (which seems very weird to me!!!).

>uname -a
Linux i75454 3.7.10-1.16-desktop #1 SMP PREEMPT Fri May 31 20:21:23 UTC 2013
(97c14ba) i686 i686 i386 GNU/Linux

>cat /etc/issue
Welcome to openSUSE 12.3 "Dartmouth" - Kernel \r (\l).

>gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/myUserame/gcc-latest/gcc-4.8.2/lib/gcc/i686-pc-linux-gnu/4.8.2/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/home/myUsername/gcc-latest/gcc-4.8.2
--enable-languages=c,fortran,c++
Thread model: posix
gcc version 4.8.2 (GCC)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/59168] Wrong result with non-optimized (!) compilation
  2013-11-18 10:13 [Bug fortran/59168] New: Wrong result with non-optimized (!) compilation sarantis.pantazis at gmail dot com
@ 2013-11-18 10:14 ` sarantis.pantazis at gmail dot com
  2013-11-18 13:01 ` janus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: sarantis.pantazis at gmail dot com @ 2013-11-18 10:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59168

--- Comment #1 from Sarantis Pantazis <sarantis.pantazis at gmail dot com> ---
Created attachment 31234
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31234&action=edit
Bug code


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/59168] Wrong result with non-optimized (!) compilation
  2013-11-18 10:13 [Bug fortran/59168] New: Wrong result with non-optimized (!) compilation sarantis.pantazis at gmail dot com
  2013-11-18 10:14 ` [Bug fortran/59168] " sarantis.pantazis at gmail dot com
@ 2013-11-18 13:01 ` janus at gcc dot gnu.org
  2013-11-18 13:13 ` janus at gcc dot gnu.org
  2013-11-18 18:46 ` dominiq at lps dot ens.fr
  3 siblings, 0 replies; 5+ messages in thread
From: janus at gcc dot gnu.org @ 2013-11-18 13:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59168

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |janus at gcc dot gnu.org

--- Comment #2 from janus at gcc dot gnu.org ---
Sorry, I can not reproduce this. I have tried with gfortran 4.7, 4.8 and trunk
using -O0 up to -O3. The result is always:

   67108864.0    
   67108864.0

It seems that you have built gfortran yourself, right? Have you tried running
the testsuite ('make check-gfortran')?


$ gfortran-4.8 -v
Using built-in specs.
COLLECT_GCC=gfortran-4.8
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.8.1-10ubuntu8' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre
--enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8)


$ gfortran-4.9 -v
Using built-in specs.
COLLECT_GCC=gfortran-4.9
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/jweil/gcc49/trunk/configure --program-suffix=-4.9
--enable-checking=release --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--enable-languages=c,c++,fortran --disable-bootstrap --disable-multilib
Thread model: posix
gcc version 4.9.0 20131117 (experimental) [trunk revision 204922] (GCC)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/59168] Wrong result with non-optimized (!) compilation
  2013-11-18 10:13 [Bug fortran/59168] New: Wrong result with non-optimized (!) compilation sarantis.pantazis at gmail dot com
  2013-11-18 10:14 ` [Bug fortran/59168] " sarantis.pantazis at gmail dot com
  2013-11-18 13:01 ` janus at gcc dot gnu.org
@ 2013-11-18 13:13 ` janus at gcc dot gnu.org
  2013-11-18 18:46 ` dominiq at lps dot ens.fr
  3 siblings, 0 replies; 5+ messages in thread
From: janus at gcc dot gnu.org @ 2013-11-18 13:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59168

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from janus at gcc dot gnu.org ---
(In reply to janus from comment #2)
> Sorry, I can not reproduce this. I have tried with gfortran 4.7, 4.8 and
> trunk using -O0 up to -O3. The result is always:
> 
>    67108864.0    
>    67108864.0

... which of course is not the result you expect.

However, the solution is simple: Use -fdefault-real-8 or decleare your
variables explicitly as real(8). Single precision, i.e. real(4), does not
provide sufficient precision to represent the final value.

Closing as invalid.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/59168] Wrong result with non-optimized (!) compilation
  2013-11-18 10:13 [Bug fortran/59168] New: Wrong result with non-optimized (!) compilation sarantis.pantazis at gmail dot com
                   ` (2 preceding siblings ...)
  2013-11-18 13:13 ` janus at gcc dot gnu.org
@ 2013-11-18 18:46 ` dominiq at lps dot ens.fr
  3 siblings, 0 replies; 5+ messages in thread
From: dominiq at lps dot ens.fr @ 2013-11-18 18:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59168

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |DUPLICATE

--- Comment #4 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> Sorry, I can not reproduce this. I have tried with gfortran 4.7, 4.8 
> and trunk using -O0 up to -O3. The result is always:
>
>   67108864.0    
>   67108864.0

Confirmed for 64 bit mode, but I get the results of comment #0 for 32 bit mode.
This is a duplicate of pr323, i.e., I get 67108864.0 if I compile the test with
'-m32 -ffloat-store'.

*** This bug has been marked as a duplicate of bug 323 ***


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-11-18 18:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-18 10:13 [Bug fortran/59168] New: Wrong result with non-optimized (!) compilation sarantis.pantazis at gmail dot com
2013-11-18 10:14 ` [Bug fortran/59168] " sarantis.pantazis at gmail dot com
2013-11-18 13:01 ` janus at gcc dot gnu.org
2013-11-18 13:13 ` janus at gcc dot gnu.org
2013-11-18 18:46 ` dominiq at lps dot ens.fr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).