From: Rajinder Yadav Date: 2009-10-30T01:36:23+09:00 Subject: Re: Using multicore CPUs in parallel tasks On Thu, Oct 29, 2009 at 10:56 AM, Marc Hoeppner wrote: > Hi, > > I've been reading around a bit but couldn't find a solution that worked, > so here goes: > > I am running ruby 1.8 and want to make full use of a quad core CPU > (64bit, Ubuntu) in a task that lends itself to multithreading/multicore > use. > > It's basically an array of objects that are each use in a fairly CPU > intensive job, so I figured I could have 4 of them run at the same time > , one on each CPU. You might want to checkout Pure and Tiamat and talk to James Lawrence (see links). He seems to have something you are asking for. I don't know much about these 2 project, they came by my radar a few days ago but I think it's cool what James is working on! == Links * Pure: http://purefunctional.rubyforge.org * Documentation: http://tiamat.rubyforge.org * Download: http://rubyforge.org/frs/?group_id=9145 * Rubyforge home: http://rubyforge.org/projects/tiamat * Repository: http://github.com/quix/tiamat == Author * James M. Lawrence > BUT... > > The only reasonably understandably suggestion looked something like: > > ---- > threads = 4 > my_array = [something_here] > > threads.times do >  Process.fork(a_method(my_array.shift)) > end > > my_array.each do |object| >  Process.wait(0) >  Process.fork(a_method(object)) > end > --- > > But this still only used one CPU (and looks a bit ugly..). Is that some > limitation of ruby (v 1.8 specifically) or am I doing something wrong? > > Cheers, > > Marc > -- > Posted via http://www.ruby-forum.com/. > > -- Kind Regards, Rajinder Yadav http://DevMentor.org Do Good! - Share Freely, Enrich and Empower people to Transform their lives.