Search - User list
Full Version: HDK: THREADED_METHOD1
Root » Technical Discussion » HDK: THREADED_METHOD1
morzh
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 ?
orr
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.
morzh
no, that is not working
orr
hm, it's working for me. I just did a test with 301 points and 8 cores it gives me:

37
38
37
38
38
38
37
38
sum: 301


I also put pratheses around result like this (*result) += total; just to make sure .

that's how i call it:

sumPts = 0;
sum(&sumPts);
cout << “sum: ” << sumPts << endl;
morzh
!!!! All works fine. orr, thank you for your help !!! All the problems was cause I've made a silly mistake in my code. The next question is how to make the multithreaded loop over group of points. We have FOR_ALL_OPT_GROUP_POINTS macro, so how could we make multhithreaded version for this loop …
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB