schleyfox / peach Goto Github PK
View Code? Open in Web Editor NEWParallel Each for JRuby
Home Page: http://peach.rubyforge.org
License: MIT License
Parallel Each for JRuby
Home Page: http://peach.rubyforge.org
License: MIT License
hi!
thanks a lot for peach, i think it's a great way to parallelize things, but there's a bug when the number of elements to be looped is less than 2*threads:
#!/usr/bin/env ruby
require 'peach'
@max_threads=10
@elements=19
exports = Array.new
puts "start"
$i = 0;
$num = @elements;
while $i < $num do
exports.push($i)
$i +=1;
end
puts "array initialized"
def do_export(num)
print " |export #{num} "
%x(sleep 5)
end
puts "max_threads: #{@max_threads}"
exports.peach(@max_threads) do |export|
do_export(export)
end
this code will execute 19 threads instead of 10.
ruby -e 'require "peach"; (1..10).to_a.peach{|x| sleep 0.01*x; puts x; sleep 1}'
Expected result:
1 2 3 4 5 6 7 8 9 10
Actual result:
1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 1 7 8 9 10
Reproduced with:
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
jruby 1.5.2 (ruby 1.8.7 patchlevel 249) (2010-08-20 1c5e29d) (OpenJDK 64-Bit Server VM 1.6.0_0) [amd64-java]
It'd be great if I could use .peach on instances of Hash (for Hash#each, Hash#each_key, Hash#each_value and Hash#each_pair) as well as Array.
require 'peach'
[].pmap {|foo| }
gives
RuntimeError: Thread pool size less than one?
Add a unless method_defined? ...
at the end of each def
so it's sure you don't overwrite anything. Oh, and make _peach_pool
private and remove the _
prefix - too much javascript here :-)
So every class that supports #each
can use it.
The README is a little outdated now, as Ruby 2.0 has better support for threads.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.