Search code examples
visual-studioqtopenmp

Qt5, Visual Studio 2012 Express and OpenMp. How to?


I am trying to compile http://www.kevinbeason.com/smallpt/ raytracer using Qt5 and Visual Studio 2012 compiler.

It works Okay but when I try to use openmp by adding

QMAKE_CXXFLAGS += -fopenmp
LIBS += -fopenmp

to project.pro , Qt says that /fopenmp is not recognized and ignored.

When I compile using VS command

cl /c /O2 /EHsc /openmp main.cpp

it works and I get a program 3 times faster then the one compiled from Qt.

How to make Qt recognize openmp and how to enable the other optimizations in the command line?

Thanks in advance.


Solution

  • I finally got all the required elements to get it compiled with openmp from Qt Creator:

    1. Add #include <omp.h> to the source, which is not required if you compile with the command line mentioned above.
    2. Add QMAKE_CXXFLAGS += -openmp to the project file. It wont work with -fopenmp. No need for any openmp lib like I did ( LIBS += -openmp ) neither for QMAKE_LFLAGS += -openmp
    3. Compile as release. With debug it has no impact on performance.

    The other optimization options are already configured in mkspecs\win32-msvc2012\ qmake.conf

    Hope this helps someone else.