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. How can i force QtConcurrent::run to use more than just one Core
Qt 6.11 is out! See what's new in the release blog

How can i force QtConcurrent::run to use more than just one Core

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.2k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    David.A.P
    wrote on last edited by
    #1

    Hello Qt Dev Community,

    i'm Programming a small Software for an optical Measuresystem and i need fast calculations on Imagedata.
    I build myself allready a Helper Method that divides my Image in Areas which are then processed by different Threads using QtConuccrent::run.

    The Helper function looks like this:
    @
    void PhaseClass::ComputePhase(uchar *Image, int ImageWidth, double PhaseImage, int PhaseImageWidth, int PhaseImageHeight, bool PhaseImageRadiusMap, int MeasureWindowWidth, int ThreadNX, int ThreadNY) {
    QFutureSynchronizer<void> computations;

    for (int x = 0; x < ThreadNX; x++) {
        for (int y = 0; y < ThreadNY; y++) {
            QRect r(x * (PhaseImageWidth / ThreadNX),
                    y * (PhaseImageHeight / ThreadNY),
                    PhaseImageWidth / ThreadNX,
                    PhaseImageHeight / ThreadNY);
    
            QFuture<void> computation = QtConcurrent::run(boost::bind(ComputePhaseWorker, r, Image, ImageWidth, PhaseImage, PhaseImageWidth, PhaseImageRadiusMap, MeasureWindowWidth));
            computations.addFuture(computation);
        }
    }
    
    computations.waitForFinished();
    

    }
    @

    This approach works fine in case of the Results but i somehow have the feeling that i could be faster.
    The Calculations are running non stop so that i can have a Liveimage, and when i start the Calculations with ThreadNY and ThreadNY set to 4, Windows tells me that my Application uses just 10 Threads where it should use 16. When i set ThreadNY and ThreadNX to 8, Windows still just uses 10 threads.
    Also all the Threads seem to run on just one single Core, and with having a 6 Core CPU i just use nearly 25-30% of the CPUs Capacity.

    Is there any possibility to tell my Application to use more Cores?
    Maybe i use QtConcurrent in a wrong way or i have a logical error somewhere... :-).

    I'm working on a AMD Phenom(tm) II X6 1075T CPU and Windows7 64Bit.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KeithS
      wrote on last edited by
      #2

      First point: there's no point in running more threads than you have number of cores (unless they're hyperthreaded like some Intel cores which will run 2 threads per core). If you try, all that will happen is that the threads get timesliced, and will probably run slower. As I understand it, QtConcurrent will check the number of cores you have and limit the number of parallel threads to that.

      Second point: you may have threads being blocked by other threads as they try and access some common resource. So although 6 threads are active, maybe 4 of them are in a wait state at any given time.

      1 Reply Last reply
      0

      • Login

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