Search - User list
Full Version: HDK  UT_ThreadSpecificValue help
Root » Technical Discussion » HDK  UT_ThreadSpecificValue help
maxpayne
Hi everyone. I'm trying to use UT_ThreadSpecificValue inside Threaded loop using UT_Parallel_for.

Every thread supposed to have some variable that is accumulated and after loop it's being summed up.

It all seems to work but it looks like values that are being accumulated indefinitely. What is the correct way of using it ?

I tried to set UT_ThreadSpecificValue back to 0.0 but looks like it doesn't do much.

Any help would be appreciated.

Code example:

static UT_ThreadSpecificValue<UT_Vector3D> temp

        GA_SplittableRange point_range(gdp->getPointRange());
        UTparallelFor(point_range, (const GA_SplittableRange& r)
        {

        setting variables...

            for (GA_Iterator it(r.begin()); !it.atEnd(); ++it)
            {

                GA_Offset ptoff = *it;

                UT_Vector3D myVector = temp.get();

                myVector+=1;

                temp.get()=myVector;

           }

            for (UT_Vector3D value : temp)
            {
                x_var+= temp.x();
                y_var+= temp.y();
                z_var+= temp.z();
            }

UPDATE: resetting values with temp.clear() before loop works but whenever I change any parameter on a node repeatedly , Houdini crashes.
cwhite
I'm not sure about the crash you mentioned, but you would need to reset the thread-specific values before your parallel loop since you have them in a static variable

However, I'd recommend looking at using UTparallelReduce (or UTparallelDeterministicReduce for accumulating floating-point values) which are designed for this type of pattern
maxpayne
cwhite
I'm not sure about the crash you mentioned, but you would need to reset the thread-specific values before your parallel loop since you have them in a static variable

However, I'd recommend looking at using UTparallelReduce (or UTparallelDeterministicReduce for accumulating floating-point values) which are designed for this type of pattern
I just found out that resetting values explicitly for ThreadSpecificValue using iterator like value=0.0 solves the issue with Houdini crash.
I'm not sure why .clear() causes the crash even though documentation says it will reset all thread to initial state.
Anyway. I will look into UTparallelReduce. Thank you for the advice
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