Faster code with another compiler

I use a standard gcccompiler in developing mathematical software in C. I don’t know much about compilers or compiler options, and I was just wondering if it’s possible to make faster executables using another compiler or to choose the best options? By default, the Makefile sets the parameters -ffast-mathand -O3, and I think that both of them have some effect on the overall computation time. My software uses memory quite widely, so I guess some of the memory management related options can do the trick?

Any ideas?

+3
source share
6 answers

Before experimenting with different compilers or random arbitrary microoptimizations, you really need to get a decent profiler and profile for your code to know exactly what performance bottlenecks are. The actual picture can be very different from what you imagine. After you have a profile, you can begin to consider what may be useful optimization. For instance. changing the compiler will not help you if you are limited by memory bandwidth.

+9
source

gcc: -Os, -O2 -O3. -O2 , . , , -Os .

-march = native ( , ) . . gcc uses with native, :
C, test.c,

$ touch test.c
$ gcc -march=native -fverbose-asm -S test.c
$ cat test.s

goto Gentoo. gcc. : i7, gcc 4.5 Atom, -march -mtune .

, (-, Gentoo, -march = native ) http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html

4.4 4.5, -flto -fwhole-program. , . , , GCC http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

+5

Linux x86, Intel PGI .

, !

+3

, , (() , .

:

, , .

+1

, , malloc, , . , jemalloc (http://www.canonware.com/jemalloc/).

+1

Keep in mind that most of the improvements that can be made as a result of changing compilers or settings will only receive proportional accelerations, where you can sometimes get improvements in O()your program as corrective algorithms . Make sure that you have exhausted this before putting a lot of effort into adjusting your settings.

+1
source

Source: https://habr.com/ru/post/1748319/


All Articles