Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. OpenMP on Qt-based app
Forum Update on Monday, May 27th 2025

OpenMP on Qt-based app

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Max Rafiandy
    wrote on 31 May 2016, 23:44 last edited by Max Rafiandy 6 Jan 2016, 00:50
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Max Rafiandy
      wrote on 1 Jun 2016, 00:47 last edited by
      #2

      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.

      1 Reply Last reply
      0

      1/2

      31 May 2016, 23:44

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved