Grasshopper

algorithmic modeling for Rhino

Hi!
I was recently working on a pretty big definition when the outofmemory magic screen appeared with its wonderful bloody panels and red crosses (cf attached image). The problem is definitely my definition, not a GH bug, but this gave me a little idea: as I saw in the last version of GH, the clusters are back. There is no link with the memory, but this is the idea: I know that GH is not a multi-threaded app, but could it be possible to assign the execution of these different clusters to, let's say one processor-core each? (in a distributed-rendering like interface: cluster A rendered by core 1, B by core 2, etc.) And as GHowl allows to send datas through networks, it could also be possible to link multi-sessions of GH on different PCs as well, no? ...

Views: 427

Attachments:

Replies to This Discussion

Hi Thibal,

a node-based algorithm like you design in Grasshopper is supremely well suited for naive threaded execution. Imagine the following network for example:


We can start the solution on two threads where Thread I solves object A1 and Thread II solves object A2. As soon as A1 is completed, Thread I can move on to object B1 and as soon as A2 completes, Thread II can move on to object B3 (whichever comes first). When both A1 and A2 are complete, we can spawn a new thread (III) to take care of object B2.

If B2 completes before B3, then Thread III will terminate. If B3 completes before B2, then Thread II terminates. Whichever thread is last will pick up execution of object C3. And so on and so forth.

This sort of threading is actually not guaranteed to help much though, as it is likely that the bottleneck components in the network will still need to be handled by a single thread.


A more efficient solution would be to divvy up the execution per component to multiple threads. If you're trying to compute the Curve Closest Point for 10,000 points and your machine contains 4 cores, then we can assign 2,500 points to the first core, 2,500 points to the second core etc.

This approach will actually work when there's only a few bottleneck components and it also means the order in which components are solved is no longer important.


An even more fine-grained approach to threading would be to make the Curve Closest Point function in the Rhino SDK threaded. There's a lot of looping going on in any given Curve CP computation so the curve could be broken up into loose spans where each span is solved by a different core. Then the partial results get consolidated once all threads finish.

The benefit here is that it would be multi-core for everyone, not just Grasshopper components.


The bad news: Some functions in Rhino are not thread-safe. Meaning that data structures such as NurbsCurves cannot be modified from multiple threads at once as it will compromise their validity. You might well end up with invalid curves and quite possible weird crashes. In very bad cases it might even be that a specific function in our SDK can only be running once, so even if you were to duplicate the curve it would still not work.

Until our SDK is thread-safe there can be no global threading in Grasshopper. I don't know where we're headed with this, but I do know that we've started using some threaded algorithms in the display as of Rhino5, so it seems we're at least getting our feet wet.

--
David Rutten
david@mcneel.com
Seattle, WA
Thank you very much for this quick and very complete answer :)

The definition I was talking about which made my quad core 8gb DDR3 crash was effectively a computation of a very large amount of points (about 80 000), with closest point, area and a point distance components set in "cross reference", so it was very very loud... (10^7 or 8 tree elements, and it takes 15minutes).

As you say in your second paragraph, it could be possible to divide this amount of points into multi-threaded lists, without touching the sdk, one component at the time. Is it something everybody can script in a VB component? Because if it is, I start scripting immediately...
Yes, threading is available as a standard .NET feature so whenever you write a VB or C# component, you can spawn threads all you like. Just know that threading is not easy, there's a lot you need to know in order to make your code stable.

--
David Rutten
david@mcneel.com
Seattle, WA
Ok, I will take a look on it! Thanks for your reply :)
TS.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service