use strict; use warnings; use autodie; use MCE::Loop; use Data::Dumper; my $data_file = 'DATA_F.dat'; my (%global_hash1, %global_hash2); my ($global_counter1, $global_counter2) = (0, 0); MCE::Loop::init { use_slurpio => 1, max_workers => 8, init_relay => 0, gather => sub { my ($counter, $hash_ref) = @_; $global_counter2 += $counter; while (my ($k,$v) = each %{$hash_ref}) { $global_hash2{$k} = $v; } }, }; print "# printing counter1\n"; { open (my $fh, '<', $data_file); while (<$fh>) { my ($k,$v) = split; $global_hash1{$k} = $v; print ++$global_counter1, $/; } } print "# done printing counter1\n"; print "# printing counter2\n"; mce_loop_f { my ($mce, $chunk_file, $chunk_id) = @_; my ($wid, $counter, %hash) = (MCE->wid, 0); my $output = "# worker $wid\n"; my $numlines = ${ $chunk_file } =~ tr/\n//; my $relaycount = MCE->relay_recv; MCE::relay { $_ += $numlines }; open my $fh, "<", $chunk_file or die "$!"; while (<$fh>) { my ($k, $v) = split; $hash{$k} = $v; $output .= (++$counter + $relaycount).$/; } close $fh; MCE->gather($counter, \%hash); MCE->print($output); } $data_file; MCE::Loop->finish(); print "# done printing counter2\n"; print "counter1 final: ", $global_counter1, $/; print "counter2 final: ", $global_counter2, $/; print " relay final: ", MCE->relay_final, $/; print "hash1: ", Dumper(\%global_hash1); print "hash2: ", Dumper(\%global_hash2); #### # printing counter1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # done printing counter1 # printing counter2 # worker 2 1 2 # worker 8 5 6 # worker 5 3 4 # worker 7 7 8 # worker 8 17 18 # worker 7 19 20 # worker 4 11 12 # worker 8 21 22 # worker 1 9 10 # worker 6 13 14 # worker 2 25 26 # worker 7 23 24 # worker 3 15 16 # done printing counter2 counter1 final: 26 counter2 final: 26 relay final: 26 hash1: $VAR1 = { '8' => 'h', '3' => 'c', '10' => 'j', '24' => 'x', '13' => 'm', '22' => 'v', '18' => 'r', '7' => 'g', '19' => 's', '21' => 'u', '12' => 'l', '14' => 'n', '23' => 'w', '20' => 't', '11' => 'k', '15' => 'o', '1' => 'a', '6' => 'f', '26' => 'z', '4' => 'd', '9' => 'i', '2' => 'b', '17' => 'q', '5' => 'e', '25' => 'y', '16' => 'p' }; hash2: $VAR1 = { '18' => 'r', '19' => 's', '7' => 'g', '21' => 'u', '8' => 'h', '10' => 'j', '3' => 'c', '13' => 'm', '24' => 'x', '22' => 'v', '11' => 'k', '12' => 'l', '14' => 'n', '23' => 'w', '20' => 't', '4' => 'd', '26' => 'z', '15' => 'o', '1' => 'a', '6' => 'f', '16' => 'p', '9' => 'i', '2' => 'b', '17' => 'q', '5' => 'e', '25' => 'y' };