Speeding up parallel calculations of intersections (Rhinocommon)?


#1

I have a large array of curves and a small array of surfaces, and I am finding the intersection between each curve and each surface. I need to speed this operation up.

I’ve adjusted the tolerance variable to be as forgiving as I can accommodate, which helped somewhat.

I need to parallel-ize. Can the rhinocommon intersection calculations be used in a multi-threaded manner? Is this something I can accelerate by offloading to GPU via CUDA or OpenCL?

Thanks in advance,

David


(Menno Deij - van Rijswijk) #2

You can parallelize in in C# using the Task Parallel Library (TPL). I am using it to do a similar intersection problem - a couple of BREPs with a list of planes.

Basically, substitute a for loop with Parallel.For and this speeds things up. But, before doing an “expensive” CurveSurface intersection, why not do a “cheaper” bounding box intersection test. If the bounding boxes of the curve and the surface being intersected are disjoint, the intersection does not need to be computed.


#3

Thanks for the suggestions, I will try them :smile:

I’m guessing that offloading to a GPU isn’t feasible then?


(Brian Gillespie) #4

Careful here - the intersection code in Rhino is not thread safe. If you start calling the intersectors in parallel, you may get garbage results or crashes.


#5

This was over a year ago, while RhinoCommon was presumably not complete, but seemed to suggest that this should be thread-safe.

http://news2.mcneel.com/scripts/dnewsweb.exe?cmd=article&group=rhino.plug-ins&item=44348&utag=

Is this no longer true? Can someone clarify?


(Steve Baer) #6

Um… I don’t think that is true Brian.

I would use Menno’s suggestion of a parallel for loop using the task parallel library

One thing that you DO need to be careful about is working with the Rhino document as that is not thread safe. Make all of your intersection calculations in a parallel for loop and collect your results. Once the loop is complete, you are back on the main thread of execution and you can work with the document (things like add points where the intersections occur)


#7

Ok thanks.

The only thing I’m still unclear about is GPU offloading. If code is thread-safe does it qualify for this? Or are there more stringent requirements? I’m assuming no one knows, and I’m going to continue researching. But please, stop me if you know better :wink:


(Steve Baer) #8

GPU offloading doesn’t really make much sense in the context of this question. The intersection functions in core Rhino are written to run on the CPU(s). Special code would need to be written to have these functions work on the GPU(s).