Compiler flags

Because Qt Creator is set up for GUI programming by default, we need to change some of the compile flags for our projects for the max performance. Below we have listed the most useful compile flags you will need.

Maximize performance

The compiler has the ability to optimize your code at the cost of longer compile times and more obfuscated machine code. Obfuscated machine code doesn't really matter unless you want to debug, and that is the reason you should never add optimization flags to debug builds. The below flags should only affect your release builds.

To enable this in Qt Creator, add the following to your .pro file:

release {
    DEFINES += ARMA_NO_DEBUG
    QMAKE_CXXFLAGS_RELEASE -= -O2
    QMAKE_CXXFLAGS_RELEASE += -O3
}

This removes the default -O1 and -O2 optimization flags and introduces the -O3 optimization flag. The difference is not large, but still useful.

Enable C++11 features

C++ has evolved with time and the new features of C++ as of 2011 are awesome. To enable them, add the following to your .pro file:

COMMON_CXXFLAGS = -std=c++0x
QMAKE_CXXFLAGS += $$COMMON_CXXFLAGS
QMAKE_CXXFLAGS_RELEASE += $$COMMON_CXXFLAGS
QMAKE_CXXFLAGS_DEBUG += $$COMMON_CXXFLAGS

One useful feature is the optimized for-loop with a new "for each" syntax:

for(Atom* atom : atoms) {
    atom->calculateForce();
}

This both runs faster than many (not-correctly-implemented) for-loops that you write by hand and is easier to read.

Another are lambda functions that let you write functions directly where you need them without declaring a whole new function. In addition we get initializer lists, allowing you to write

vec a = {1, 2, 8, 3, 4, 7};

to initialize your vector a.

MPI flags

To use MPI in Qt Creator, see this blog post.

 

Published Feb. 14, 2013 1:33 PM - Last modified Feb. 28, 2013 12:29 PM