Jump to content

Multithreading


Recommended Posts

Hi,

I've got the following code which mimicks a trail sop:


SOP_TrailIfExists::cookMySop(OP_Context &context)
{
fpreal t = context.getTime();
fpreal f = context.getFloatFrame();
fpreal new_t;
const GU_Detail *current_frame_gdp;
const GU_Detail *trail_frame_gdp;
GU_Detail blank_gdp;
GU_Detail trail_gdp;
OP_Context trail_context = context;

//get trail length and increment amount from UI
fpreal len = LEN(t);
fpreal inc = INC(t);

// Lock the input context
if (lockInput(0, context) >= UT_ERROR_ABORT)
return error();

//get the geometry
current_frame_gdp=inputGeo(0, context);

//start copying
gdp->copy(blank_gdp, GEO_COPY_START);
//copy current frame
gdp->copy(*current_frame_gdp, GEO_COPY_ADD);

//unlock the context
unlockInput(0);

//do the trail
for(int i = 1;i<len;i++)
{

// This is the frame number we want to evaluate
new_t = f-(i*inc);

// The context takes seconds, not frame, so we convert.
new_t = OPgetDirector()->getChannelManager()->getTime(new_t);

// Adjust our cooking context to reflect this
trail_context.setTime(new_t);

// Lock the input context
if (lockInput(0, trail_context) >= UT_ERROR_ABORT)
return error();

//get the geometry
trail_frame_gdp=inputGeo(0, trail_context);
// copy the geometry
gdp->copy(*trail_frame_gdp, GEO_COPY_ADD);

}

//end copying geometry
gdp->copy(blank_gdp, GEO_COPY_END);

//unlock the input
unlockInput(0);


return error();
}
[/CODE]

I'd like to be able to make it run on multiple threads, but I'm a bit unsure about how to go about it. I've had a look at:

http://www.sidefx.co...ingChildThreads

which seems to suggest I need to wrap it all up into a class and use the UT_ThreadedAlgorithm THREADED_METHOD options. But then I looked at the slides in: $HFS/toolkit/slides/HDK12_Intro.pdf

and they mention the UTparallelFor option. My main questions are:

1. Which one should I go for?

2. Will I need to wrap all of my code into a class or can I just put the for loop into a seperate function and thread that function?

Cheers,

Tony

Link to comment
Share on other sites

Guest mantragora

If I remember correctly PDF mentioned both methods. It wasn't specified why one is better over other so I suppose both are equally good.

PS. I have somewhere example of threaded code, not made by me, but I can't find it now. :)

Edited by mantragora
Link to comment
Share on other sites

I'm skeptical that this could actually be multithreaded. Houdini doesn't really support threaded network cooking which is essentially what this could would be doing. I suppose it's worth a shot, but I wouldn't expect any gains and there might even be some crashing.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...