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