Menu

Optimization Flags

Eric T
2007-09-05
2012-09-26
  • Eric T

    Eric T - 2007-09-05

    Hi, I've been trying to speed up my c code (neural net, with many iterations), and I've tried to implement the Dev-C++ built-in optimization flags, listed in Tools->Compilation Options->Settings->Optimization, but they have no effect! Anyone know why this is?

    A work-around to this problem has been to go to Tools->Compilation Options->Compiler, and to manually add the optimization flags when calling compiler: -O1, or -O2, or -O3.

    However, though this speeds up my executable (by factor of 2 for O2 and O3), it creates significant differences in the numerical results. To try to track down this problem, I looked at the gcc online manual:
    http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
    in order to determine which specific flags are associated with each optimization level (1, 2, and 3), and to then eliminate the specific flag(s) causing the numerical differences.

    What I discovered is that none of the many flags listed significantly affected the speed, nor were responsible for the numerical differences!
    The manual does say "Not all optimizations are controlled directly by a flag. Only optimizations that have a flag are listed" I take this to mean that the O1, O2, and O3 flags do other things besides turn on the flags listed in this manual, but it's unknown what these things are. According to my investigations, though, these "unlisted" optimizations have the greatest effect, in both speed of executable, and in causing numerical differences.

    Does anyone know what these unlisted optimizations are, and how they can be switched on/off?

    I also noticed that the gcc online manual (link above) contains flags that are not recognized in Dev-C++, suggesting that I may not be looking at the correct manual for Dev-C++. Anyone know where a more correct manual can be found?

    Thanks for reading all this, and I appreciate your responses.
    -Eric T.

     
    • Wayne Keen

      Wayne Keen - 2007-09-05

      Keep in mind that the version of GCC used by Dev is 3.4. This is not the current version of GCC.

      It would be useful if you could post some examples of flags that are not recognized.

      Wayne

       
    • Eric T

      Eric T - 2007-09-05

      Hi Wayne,

      Thanks for responding. I forgot to mention that I'm using Dev-C++ version 4.9.9.2, installed on computer running Windows XP Home Ed., with Pentium 4 processor.

      Below, in my compilation log, you'll find the flags I tried out (taken from gcc online manual) that the Dev-C++ c-compiler did not recognize. When I remove these flags, it compiles fine, but as I said before without a significant effect on speed or in causing numerical differences, as is the case with the -O1, O2, and O3 flags. Here's part of the compilation log:

      make.exe -f "C:\Documents and Settings\Owner\My Documents\Neural Net\Makefile.win" all
      gcc.exe -c neural.c -o neural.o -I"C:/Dev-Cpp/include" -fdefer-pop -fdelayed-branch -fguess-branch-probability -fcprop-registers -fif-conversion -fif-conversion2 -fsplit-wide-types -ftree-ccp -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-ter -ftree-sra -ftree-copyrename -ftree-fre -ftree-ch -funit-at-a-time -finline-small-functions -fmerge-constants -fthread-jumps -fcrossjumping -foptimize-sibling-calls -fcse-follow-jumps -fcse-skip-blocks -fgcse -fgcse-lm -fexpensive-optimizations -frerun-cse-after-loop -fcaller-saves -fpeephole2 -fschedule-insns -fschedule-insns2 -fsched-interblock -fsched-spec -fregmove -fstrict-aliasing -fstrict-overflow -fdelete-null-pointer-checks -freorder-blocks -freorder-functions -falign-functions -falign-jumps -falign-loops -falign-labels -ftree-vrp -ftree-pre -finline-functions -funswitch-loops -fpredictive-commoning -fgcse-after-reload

      cc1.exe: error: unrecognized command line option "-fsplit-wide-types"
      cc1.exe: error: unrecognized command line option "-ftree-ccp"
      cc1.exe: error: unrecognized command line option "-ftree-dce"
      cc1.exe: error: unrecognized command line option "-ftree-dominator-opts"
      cc1.exe: error: unrecognized command line option "-ftree-dse"
      cc1.exe: error: unrecognized command line option "-ftree-ter"
      cc1.exe: error: unrecognized command line option "-ftree-sra"
      cc1.exe: error: unrecognized command line option "-ftree-copyrename"
      cc1.exe: error: unrecognized command line option "-ftree-fre"
      cc1.exe: error: unrecognized command line option "-ftree-ch"
      cc1.exe: error: unrecognized command line option "-finline-small-functions"
      cc1.exe: error: unrecognized command line option "-fstrict-overflow"
      cc1.exe: error: unrecognized command line option "-ftree-vrp"
      cc1.exe: error: unrecognized command line option "-ftree-pre"

      cc1.exe: error: unrecognized command line option "-fpredictive-commoning"

      neural.c:1: warning: this target machine does not have delayed branches

      make.exe: *** [neural.o] Error 1

      Execution terminated

       
    • Anonymous

      Anonymous - 2007-09-06

      Besides your investigation, is worthy to mention that the MinGW version, ant the gcc-g++ compiler, included in the standard Dev-C++ 4.9.9.2, are a bit old. I would suggest:

      • Uninstall the current Dev-C++ version.
      • Download and install the latest candidate MinGW
      • Download and install the Dev-C++ execitable only
      • Configure Bloodshed Dev-C++ to use the already installed MinGW

      In this forum can be found instructions to do that.

      HTH

      Old Newbie

       
    • Anonymous

      Anonymous - 2007-09-06

      The settings in Tools->Compilation Options->Settings are applied to a project when it is created; thereafter they have no effect on the project. You need to set the options in the Project->Project options dialog.

      You need to make sure you are using the right version of the GCC manual. For teh version of GCC supplied with Dev-C++ 4.9.9.2 that is: http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/.

      Even if you upgrade the compiler, many of the options may have an effect only on specific architectures and specific forms of code. Simply throwing all possible options all at once is not a good way of trying to make your code faster. You need to understand what each option achieves and determine if your code and hardware are conducive to such optimisation.

      Moreover compiler optimisations are no substitute for writing efficient code and algorithms in the first instance; which will often yield far greater benefits. If you are moving 100 bytes where you could move just 50, or none at all, the optimiser may not help - it will still have to move 100 if that is what your code requires. Of course your code may already be tight, but until you have considered that, you should steer clear of relying on the compiler to optimise your code. It works hard to implement your code as well as possible on the target instruction set, but it will do exactly what your code says, so optimisation should start there.

      Clifford

       
      • Osito

        Osito - 2007-09-06

        Doesn't dev come with gcc-3.4.2? http://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/

         
        • Anonymous

          Anonymous - 2007-09-06

          Yes, but for some reason that version is not listed at: http://gcc.gnu.org/onlinedocs/ (from where I got the link). I don't imagine that there is a difference in these manuals, the change from 3.4.2 to 3.4.6 probably had no effect on the manual other than possible corrections to the documentation because teh design of the compiler did not change, so the later document is probably preferred.

          Clifford

           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.