From: Phillip Gawlowski Date: 2008-04-16T12:47:18+09:00 Subject: Re: Parallel for loop -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Fredrik wrote: | There doesn't seem to be any EASY way of doing a parallel computation | in Ruby. | I would like to do something like this : | | array.map do |i| | fork do | i + 1 | end | end | Process.waitall | | wich would give back the array with one added to each element in an | array, and it would perform this "calculation" in parallel. However, | this doesn't work since fork runs a subprocess which is another Ruby | interpreter and I can't get anything back from that black hole, except | some exit status. | | Actually, it would be really nice if there was a 'forkmap' method that | could do this: | | array.forkmap do |i| | i + 1 | end | | But there isn't, right? | | Ruby uses green threads. All your threads would run within the Ruby process, and aren't running parallel in the sense you seem to imply. If you want to use threads, maybe JRuby and Java are what you seek. JRuby uses Java threads, which are OS threads. If I'm on the wrong tangent, just ignore this reply. :) - -- Phillip Gawlowski Twitter: twitter.com/cynicalryan You thought I was taking your woman away from you. You're jealous. You tried to kill me with your bare hands. Would a Kelvan do that? Would he have to? You're reacting with the emotions of a human. You are human. ~ -- Kirk, "By Any Other Name," stardate 4657.5 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkgFdsUACgkQbtAgaoJTgL/lnwCfad0hWxWIiJPFyTSdCAkpVIT5 UaQAmwSDyRWArC1bKgnlnYkydZWWHfAN =6rBM -----END PGP SIGNATURE-----