Safe fast CFLAGS for mex functions in Matlab

I am converting a series of low-level operations from matlab native code to high-speed C / mex code. (These low-level operations can be made vectorized in .m code, but I think I get memory images with big data.) I noticed that compiling mex code with various CFLAGS can lead to moderate improvements. For example, it CFLAGS = -O3 -ffast-mathreally gives some acceleration due to a moderate numerical error.

My question is: what are the “best” CFLAGS to use without causing too many other side effects? At least CFLAGS = -O3 -fno-math-errno -fno-unsafe-math-optimizations -fno-trapping-math -fno-signaling-nanseverything seems to be in order. I'm not sure about -funroll-loops.

Also, how would you optimize the set of CFLAGS used, semi-automatically, without nuts?

+3
source share
2 answers

If you know the target processor ... or at least want to guarantee a "minimum" processor ... you definitely need to look -mcpuand -march.

The increase in productivity can be significant.

+1
source

Regardless of what ATLAS uses on your machine ( http://math-atlas.sourceforge.net/ ), it is probably a good starting point. I don’t know that ATLAS automatically optimizes certain compiler flags, but the developers probably spent a lot of time manually.

+1
source

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


All Articles