From: Fredrik Date: 2008-04-18T14:30:03+09:00 Subject: Re: Parallel for loop > > It's different with blocks: > Ah, I got it! So it should look like this then: def forkmap(n = nil) nproc = 0 result = map do |*a| r, w = IO.pipe fork do r.close w.write( Marshal.dump( yield(*a) ) ) end if n and (nproc+=1) >= n Process.wait ; nproc -= 1 end [ w.close, r ].last end Process.waitall result.map{|r| Marshal.load [ r.read, r.close ].first} end irb> Benchmark.realtime {[1,2,3].forkmap{|i| sleep 1 } } => 1.01688504219055 irb> Benchmark.realtime {[1,2,3].forkmap(1){|i| sleep 1 } } => 3.01162004470825 Thanks! That takes me to another level of Ruby knowledge :) /Fredrik