Important: Please read the Qt Code of Conduct -

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

  • 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));


    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.

  • 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.

Log in to reply