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);