• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Multithreading - Queue?!

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 3 Posters 569 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    niccah
    last edited by 15 Jan 2012, 20:38

    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!

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 15 Jan 2012, 23:49

      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...

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 16 Jan 2012, 10:29

        .. and, Sketchup uses the 1.8.x branch of Ruby. Your reading about capabilities in the 1.9.x branch of Ruby.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • N Offline
          niccah
          last edited by 16 Jan 2012, 13:23

          @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!!

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 16 Jan 2012, 13:25

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

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • N Offline
              niccah
              last edited by 16 Jan 2012, 13:33

              @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
              end

              I 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...

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                1/6
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement