Question

I have some image processing to do that involves a lot of CPU crunching.

At the moment I have a ruby script that does the crunching, but it does so one image at a time. I'm aware I can use threads to make things sorta-kinda parallel, but in MRI, it seems that still isn't going to actually hit more than one processor(?)

So, at the moment I'm doing the rather clumsy:

system("ruby image_runner.rb 0 1 3  & ruby image_runner.rb 3 2 3 & ruby image_runner.rb 6 3 3")

It works, it's much faster than threads...but it's none too pretty.

So, is there a more elegant way to dispatch ruby processes to recruit as much CPU crunching power as possible?

Was it helpful?

Solution

try using fork:

image_runner.rb

[[0,1,3], [3,2,3], [6,3,3]].each do |x, y, z|
  Process.fork do 
    # ... do work for x, y, z
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top