我试图找出如何加快我的代码的某个部分。我有三个浮点变量:var1、var2、var3。
在顺序模式...
double start1, end1, t1;
start1= (double)cvGetTickCount();
var1= tester->predict(videocapture, params1, image);
var2= tester->predict(videocapture, params2, image);
var3= tester->predict(videocapture, params3, image);
end1= (double)cvGetTickCount();
t1= (end1-start1)/((double)cvGetTickFrequency()*1000.);
printf( "Time1 = %g ms\n", t1 );
它似乎比并行线程稍快...
double start2, end2, t2;
start2= (double)cvGetTickCount();
mp_set_dynamic(0); // Explicitly enable/disable dynamic teams
omp_set_num_threads(3); // Use 3 threads for all consecutive parallel regions
#pragma omp parallel num_threads(3)
{
#pragma omp sections //nowait
{
#pragma omp section
{
#pragma omp critical
{
var1= tester->predict(videocapture, params1, image);
}
}
#pragma omp section
{
#pragma omp critical
{
var2= tester->predict(videocapture, params2, image);
}
}
#pragma omp section
{
#pragma omp critical
{
var3= tester->predict(videocapture, params3, image);
}
}
}
}
}
end2= (double)cvGetTickCount();
t2= (end2-start2)/((double)cvGetTickFrequency()*1000.);
printf( "Time2 = %g ms\n", t2 );
有人可以帮我加快找到这三个变量的过程并告诉我我做错了什么