sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Multithreading - Queue?!

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 569 Views 3 Watching
    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

      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
      • thomthomT Offline
        thomthom
        last edited by

        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
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

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

            @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
            • thomthomT Offline
              thomthom
              last edited by

              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

                @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
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement