I'm testing THREADED_METHOD1 on a mesh (grid) with 100 points and getting some weird results. The code is:
THREADED_METHOD1( SOP_connectPoints, 1,sum, float *, result );
float sumPts;
float* pSumPts;
void SOP_connectPoints::sumPartial(float* result, const UT_JobInfo &info){
int i, n;
float total=0;
for (info.divideWork(gdp->points().entries(), i, n); i<n; i++){
total += 1;
}
{
UT_AutoJobInfoLock a(info);
*result = total;
}
}
in SOP_connectPoints::cookMySop
pSumPts = &sumPts;
sum(pSumPts);
So on 2 cored machine i get
sumPts = 50
BUT when DOMULTI=0 ( THREADED_METHOD1( SOP_connectPoints, 0,sum, float *, result ) ) all works fine and
sumPts = 100
Any suggestions ?
HDK: THREADED_METHOD1
2543 4 0- morzh
- Member
- 66 posts
- Joined: 10月 2008
- Offline
- orr
- Member
- 98 posts
- Joined: 1月 2008
- Offline
you have 2 cores so i divides the work into 50 points each.
in your for loop you are counting these points so total is set to 50 each.
Now you you trying to set result like this
{
UT_AutoJobInfoLock a(info);
*result = total;
}
so basically your first thread runs counts 50 points and sets result to 50. meanwhile your second thread runs aswell counts 50 points and sets results to 50 aswell.
I think what you wanted to do is more like this:
{
UT_AutoJobInfoLock a(info);
*result += total; // Maybe just a typo?
}
That way result will be 100 in the end.
in your for loop you are counting these points so total is set to 50 each.
Now you you trying to set result like this
{
UT_AutoJobInfoLock a(info);
*result = total;
}
so basically your first thread runs counts 50 points and sets result to 50. meanwhile your second thread runs aswell counts 50 points and sets results to 50 aswell.
I think what you wanted to do is more like this:
{
UT_AutoJobInfoLock a(info);
*result += total; // Maybe just a typo?
}
That way result will be 100 in the end.
- morzh
- Member
- 66 posts
- Joined: 10月 2008
- Offline
- orr
- Member
- 98 posts
- Joined: 1月 2008
- Offline
- morzh
- Member
- 66 posts
- Joined: 10月 2008
- Offline
-
- Quick Links