Community
cancel
Showing results for 
Search instead for 
Did you mean: 
nikkey_c
Beginner
70 Views

Problem when merging tbb wit QT

I am using qt for gui purpose and tbb for parallel processing.
but i couldnt use both at same time.
my task is play video (background subtraction - image processing) using tbb and qt.
so after press play button using qt gui, tbb wil get start its process. at that time i couldnt able to press any otehr buttons in my gui. it getsstruck. but after tbb loops finishes i can able to access the gui.
I am using tbb22 version.
0 Kudos
6 Replies
nagy
New Contributor I
70 Views

I dont think its a problem of conflict between qt and tbb but just a bug in your code.
You would probably receive more help if you posted the relevant code.
robert-reed
Valued Contributor II
70 Views

Quoting nagy
I dont think its a problem of conflict between qt and tbb but just a bug in your code.
You would probably receive more help if you posted the relevant code.


Also, what version of Qt are you using?

nikkey_c
Beginner
70 Views

qt-win-opensource-4.6.2-vs2008
Andrey_Marochko
New Contributor III
70 Views

I'd rather call it design flaw than a conventional bug :). The loss of responsiveness is likely caused by invoking parallel algorithm directly from the GUI thread. Naturally this stalls GUI dispatch loop until the parallel computation is completed.

Instead of running TBB algorithm in the button event handler, use tbb::task::enqueue() method to schedule a task that will then run the parallel computation in its execute() method. When the parallel processing is finished, post a custom window message to the GUI thread to notify it that the calculation is done. In the handler of this message GUI will appropriately update its windows.

See the chapter 8 of the new TBB design patterns document for more detailed discussion of this and related scenarios.
nikkey_c
Beginner
70 Views

sorry for late reply,
Andrey can you share any simple code to do that implementation usingtbb::task::enqueue()? i couldnt understand the in that pdf, so plz write small code for above implementation.
I am using tbb22 version, therefore it doesnt have enqueue method...
Andrey_Marochko
New Contributor III
70 Views

Well, I've never used QT in practice, so my illustration of asynchronous signal sending may be not quite correct (or there are simpler ways). If it does not work, please refer to QT forums, and don't for get to report back here :) .

Here the outline:
[bash]class MyWidget : public QWidget {
    // ...
    public:
    void onOffloadedWorkCompletion() { /* update view */ }
};

class OffloadingTask : public tbb::task {
    MyWidget* my_widget;
public:
    tbb::task* execute () {
        // ... Do any preparative activities
        // Run parallel processing
        tbb::parallel_for( /*argument*/ );
        // Send asynchronous signal to the GUI thread
        QMetaObject::invokeMethod( my_widget, "onOffloadedWorkCompletion", Qt::QueuedConnection);
    }
    OffloadingTask ( MyWidget* w ) : my_widget(w) {}
};

void MyWidget::onPushButton() {
    tbb::task::enqueue( *new (tbb::task::allocate_root()) OffloadingTask(this) );
}
[/bash]

Reply