Multithreading - Queue?!
-
Hey!
I started to get some experience in multithreading in ruby. It's very interesting!
Problems, which I want to solve with MT is: Cross THE line A face....
so I have lots of faces (lets say 16) and I have 4 CPUs - so I decided "by hand" that every CPU gets 4 faces to check.
But I want to write a queue for the thread - I think this should be a better performance.With the help of google I found for example this page: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/thread/rdoc/Queue.html#method-i-pop
But there is written: require 'thread' => but I haven't this file and I can find it nowhere
Do you have any experience to use queues in Ruby?
Thanks again for your help!
-
Muliti-threading in SketchUp Ruby is a no-go.
There's a few topics here on the forum about threading - and all just ends in misery... -
.. and, Sketchup uses the 1.8.x branch of Ruby. Your reading about capabilities in the 1.9.x branch of Ruby.
-
@thomthom said:
Muliti-threading in SketchUp Ruby is a no-go.
There's a few topics here on the forum about threading - and all just ends in misery...hm, okay, strange... in my case it works very fine. I just though to push the performance a little bit more.
Oh okay, I didn't know, that Sketchup uses a "old" version of Ruby ...
Thanks for your help!!
-
Do you have a snippet of multi-threaded SketchUp Ruby code? I'd be very interested!

-
@thomthom said:
Do you have a snippet of multi-threaded SketchUp Ruby code? I'd be very interested!

hehe, okay, here it is....
@unknownuser said:
facesCount = FACE.length # wieviel Flächen habe ich?
$facesPerThread = facesCount.divmod($opt.cpuCores.to_i) # Wieviel Flächen bekommt jede CPU?thread = Array.new
$j = 0
$opt.cpuCores.to_i.times do |i|$k = ($j-1) + $facesPerThread[0] # Der Rest der Flächen wird noch auf die einzelnen CPUs aufgeteilt if $facesPerThread[1] > 0 $k += 1 $facesPerThread[1] -= 1 end #UI.messagebox $k thread[i] = Thread.new do for l in $j..$k do #UI.messagebox FACE[l] out = FACE[l].isInCylinder break if out end out end # Startpunkt für den nächsten Thread $j = $k + 1end
thread.each do |tmp|
tmp.join
endI tested it with some simple models and I saved some single seconds.... not too much, but faster then without any threads....
I'm very interested to hear what do you think about it...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement