algorithmic modeling for Rhino
I am trying to multithread a very simple mathematical calculation in C#. I use Parallel.ForEach which I guess is why the number of output results is different from the input. I would appreciate some help on the matter.
http://snag.gy/b6tXX.jpg
Thanks!
Tags:
List.Add probably isn't a thread-safe method. List in general isn't. You should consider using a concurrent collection of some sort.
I am sorry for asking you to spell it out for me but is your suggestion to try to split the list into 8 separate lists perform a loop with one thread on each list and at the end join the lists together?
Well if someone is interested in my benchmarks here is the file with 5 different ways of multithreading with C#, a python option and two ways of doing the same operation with native components. Oddly for me it seems that python multithreading works quicker than everything tested here!
A note on profiling. You should be careful with relying too much on the GH profiler when timing code within a script. Especially if you have an output parameter with many items as this may be a larger bottleneck than the actual code! One way of getting around this is to wrap the data in a Python list and read it downstream as an item (see attached for an example).
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by