2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
|
# File 'lib/parallelpipes.rb', line 2376
def parallel_map(*args, &block)
ncpus = number_of_processors_for_parallel_map
if args[-1].class == Hash
options = args.pop
ncpus = options[:n_procs] if options[:n_procs]
end
ppipe = PPipe.new(ncpus, false)
ppipe.fork(ncpus-1)
i = -1
each(*args) do |*yargs|
i+=1
next unless i%ncpus == ppipe.mpn
value = block.call(*yargs)
ppipe.i_send(i, Marshal.dump(value), tp: 0)
end
(ppipe.die; exit) unless ppipe.is_root
ppipe.waitall
i = 0
map(*args) do |*yargs|
value = Marshal.load(ppipe.w_recv(i))
i+=1
value
end
end
|