Reputation: 137
I'm using OpenMP for this and I'm not confident of my answer as well. Really need your help in this. I've been wondering which method (serial or parallel) is faster in run speed in this. My #pragma
commands (set into comments) are shown below.
Triangle Triangle::t_ID_lookup(Triangle a[], int ID, int n)
{
Triangle res; int i;
//#pragma omp for schedule(static) ordered
for(i=0; i<n; i++)
{
if(ID==a[i].t_ID)
{
//#pragma omp ordered
return (res=a[i]); // <-changed into "res = a[i]" instead of "return(...)"
}
}
return res;
}
Upvotes: 1
Views: 125
Reputation: 10596
n
. If n
is small, then the overhead required for the OMP threads makes the OMP version slower. This can be overcome by adding an if
clause: #pragma omp parallel if (n > YourThreshhold)
a[i].t_ID
are not unique, then you may receive different results from the same data when using OMP
.if(found) continue;
can be added at the beginning of the loop.ordered
, so if that was the crux of your question, ignore all the above and consider this answer.For an alternative way of writing your loop, see Z Boson's answer to a different question.
Upvotes: 2