HDK  UT_ThreadSpecificValue help

   364   2   1
User Avatar
Member
48 posts
Joined: Dec. 2010
Offline
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.
Edited by maxpayne - June 24, 2026 10:36:48
User Avatar
Staff
813 posts
Joined: Oct. 2012
Offline
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
User Avatar
Member
48 posts
Joined: Dec. 2010
Offline
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
Edited by maxpayne - June 25, 2026 08:20:15
  • Quick Links