OpenMP on Qt-based app
-
I code for a benchmark tool. While benchmark executed, it use all processor resources (all threads) using OpenMP library to gain the performance peak of processor. For a non-Qt app and compiled the program by gcc -fopenmp -obenchmark foo.c
it works fine, runs on CLI without any Qt library. However, if I use Qt to design its GUI, the #pragma parallel region won't creating multiple task even if omp_set_num_threads(value) were set.#include <QApplication> #include <QQmlApplicationEngine> #include <pcm/cpucounters.h> #include <omp.h> #include <stdio.h> int main(int argc, char *argv[]) { std::cout << "Max Thread " << omp_get_max_threads() << std::endl; omp_set_num_threads(omp_get_max_threads()); #pragma omp parallel { int tid = omp_get_thread_num(); printf("Hello Qt Parallel %d\n",tid); } QApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
Actually, this is not my benchmark code. It just a simple code to make sure that the parallel region runs multiple threads or not. The question is: how to use OpenMP thread on Qt-based app?
Best Regard
-
Solved. The problem was my mistake :)
The .pro file needs to set both QMAKE_CXXFLAGS += -fopenmp and QMAKE_LFLAGS += -fopenmp. I just added the QMAKE_LFLAGS += -fopenmp before.