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 + 1
end
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...
Advertisement