0
float dist (Point p1, Point p2, int dim)
{
int i;
float result=0.0;
for (i=0; i<dim; i++)
result += (p1.coord[i] - p2.coord[i]) * (p1.coord[i] - p2.coord[i]);
return (result);
}
我想這parallize使用線程,但我不斷收到errors.I正在做這樣的事情並行編程的OpenMP與C++
float dist(Point p1,Point p2,int dim){
int id;
int i,tnum,istart,iend;
id=omp_get_thread_num();
tnum=omp_get_num_threads();
istart=id*dim/tnum;
iend=(id+i)*dim/tnum;
float result=0.0;
#pragma omp parallel for reduction (+:result)
{ for (i=istart; i<iend;i++)
result += (p1.coord[i] - p2.coord[i]) * (p1.coord[i] - p2.coord[i]);
return (result);}
}
謝謝
你不應該自己計算'start','end'等,或者用omp庫來計算這樣一個簡單的程序。 – 2013-04-20 19:07:18