for(unsigned int mBlock = 0; mBlock < coords.size(); mBlock++)
{
WidgetType widgetType;
height = macBlockWidth + coords[mBlock].y;
width = macBlockHeight + coords[mBlock].x;
macBlockParent = new QWidget;
cooefsLink = new QPushButton(macBlockParent);
macBlock = new QWidget(macBlockParent);
widgetType.widget = macBlock;
widgetType.type = (macBlocks[mBlock][2] != 'S')
? (macBlocks[mBlock][0]) : (macBlocks[mBlock][2]);
blockWidgetTypes.push_back(widgetType);
connect(cooefsLink, SIGNAL(released()),
this, SLOT(showCoefficients()));
buttonSignals[cooefsLink] = mBlock;
constructMotionVector(mBlock);
macBlockLayout->addWidget(macBlockParent, height - 16, width - 16);
styleMacroBlocks(mBlock);
}
我可以做一個函數出於這個for循環,我可以通過將它分成兩個不同的for循環同時在矢量上運行的平行操作。其中一個在前半部分工作,第二個在後半部分工作。因此,例如我可以線程這個for循環
線程1
for(unsigned int mBlock = 0; mBlock < coords.size()/2; mBlock++)
{
WidgetType widgetType;
height = macBlockWidth + coords[mBlock].y;
width = macBlockHeight + coords[mBlock].x;
macBlockParent = new QWidget;
cooefsLink = new QPushButton(macBlockParent);
macBlock = new QWidget(macBlockParent);
widgetType.widget = macBlock;
widgetType.type = (macBlocks[mBlock][2] != 'S')
? (macBlocks[mBlock][0]) : (macBlocks[mBlock][2]);
blockWidgetTypes.push_back(widgetType);
connect(cooefsLink, SIGNAL(released()),
this, SLOT(showCoefficients()));
buttonSignals[cooefsLink] = mBlock;
constructMotionVector(mBlock);
macBlockLayout->addWidget(macBlockParent, height - 16, width - 16);
styleMacroBlocks(mBlock);
}
線程2
for(unsigned int mBlock = coords.size()/2; mBlock < coords.size(); mBlock++)
{
WidgetType widgetType;
height = macBlockWidth + coords[mBlock].y;
width = macBlockHeight + coords[mBlock].x;
macBlockParent = new QWidget;
cooefsLink = new QPushButton(macBlockParent);
macBlock = new QWidget(macBlockParent);
widgetType.widget = macBlock;
widgetType.type = (macBlocks[mBlock][2] != 'S')
? (macBlocks[mBlock][0]) : (macBlocks[mBlock][2]);
blockWidgetTypes.push_back(widgetType);
connect(cooefsLink, SIGNAL(released()),
this, SLOT(showCoefficients()));
buttonSignals[cooefsLink] = mBlock;
constructMotionVector(mBlock);
macBlockLayout->addWidget(macBlockParent, height - 16, width - 16);
styleMacroBlocks(mBlock);
}
由於其對我的系統真正的瓶頸,我公司只使用一個CPU,並注意它的麻杏指出,中央處理器。任何幫助將非常感謝。
另外我應該提到我知道我所提出的簡單例子不是非常安全的,例如我需要兩個不同的macBlockParent指針,例如macBlockParentT1和macBlockParentT2。 – 2013-03-20 21:22:47
你有沒有分析你的代碼,看看它是吃什麼CPU?我不熟悉QT,所以我在代碼中看到的是一些小部件/控件的創建 - 這不應該是瓶頸,對吧?它究竟在哪裏? – us2012 2013-03-20 22:21:53
瓶頸在for循環中創建小部件,在較小分辨率的視頻上它的zippy,但我現在正在研究更大的res,並且需要很長時間來構建框架。 – 2013-03-20 22:26:50