Skip to content

Instantly share code, notes, and snippets.

@matpalm
Created July 12, 2009 11:44
Show Gist options
  • Save matpalm/145610 to your computer and use it in GitHub Desktop.
Save matpalm/145610 to your computer and use it in GitHub Desktop.
# process files one at time, NUM_CPUS in parallel
@postcodes = `ls resem_per_postcode`.collect{|l| l.chomp}
def fork_for_next_postcode
postcode = @postcodes.shift
fork { run "cat resem_per_postcode/#{postcode} | ./connected_components.rb > result_per_postcode/#{postcode}" }
end
NUM_CPUS.times { fork_for_next_postcode }
while not @postcodes.empty?
Process.wait
fork_for_next_postcode
end
NUM_CPUS.times { Process.wait }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment