开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
g++ on Raspberry Pi 3
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
OpenCV OpenMP
问题(Question):
在加速一些追踪的算法,在双核的笔电上以验证过,速度变1.8倍
但在4核心的树莓派3上却也只大约变2倍
喂入的资料(Input):
可平行化的循环(如程式码)
预期的正确结果(Expected Output):
速度变为原来的3倍多
错误结果(Wrong Output):
效能不符合预期
程式码(Code):(请善用置底文网页, 记得排版)
vector<double> vSumRadio(sampleBoxNum, 0);
#pragma omp parallel for num_threads(4)
for (int j=0; j< sampleBoxNum; j++)
{
double eSumRadioTmp = 0;
double eTmp1 = 0;
double eTmp2 = 0;
eSumRadioTmp = 0.0f;
for (int i = 0; i<featureNum; i++)
{
double ePosTmp = 0, eNegTmp = 0;
eTmp1 = (sampleValue[i][j]-Pos[i])*(sampleValue[i][j]-Pos[i]);
eTmp2 = (sampleValue[i][j]-Neg[i])*(sampleValue[i][j]-Neg[i]);
ePosTmp = exp(eTmp1/-(2.0f*sigmaPos[i]*sigmaPos[i]
+1e-30))/(sigmaPos[i] + 1e-30);
eNegTmp = exp(eTmp2/-(2.0f*sigmaNeg[i]*sigmaNeg[i]+
1e-30))/(sigmaNeg[i]+1e-30);
eSumRadioTmp += log(ePosTmp + 1e-30) - log(eNegTmp + 1e-30);
}
vSumRadio[j] = eSumRadioTmp;
}
补充说明(Supplement):
1. 原本没用 num_threads(4),用omp_get_thread_num()抓出来的执行绪只有0跟1
2. omp_get_num_procs() 抓出来的核心数确定为4核心