Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Parallel::ForkManager and multiple datasets

by Speed_Freak (Sexton)
on Jul 05, 2018 at 15:28 UTC ( [id://1217957]=note: print w/replies, xml ) Need Help??


in reply to Parallel::ForkManager and multiple datasets

I'm attempting the following, but so far am not successful:

#pseudo code use Parallel::ForkManager; my @names = (); my %list = (); my %thing = (); $threads = 20 my $pfm = new Parallel::ForkManager( $threads ); $pfm->run_on_finish( sub { my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_stru +cture_reference) = @_; %list = $data_structure_reference->{%list}; %thing = $data_structure_reference->{%thing}; @names = $data_structure_reference->{@names}; }); FOREACH: foreach my $thing(keys %{$things_hr}) { my $pid = $pfm->start and next; #do stuff push @names, $name; #do stuff $thing{$name}{a} = $value1; $thing{$name}{b} = $value2; #do stuff $list{$id}{$name}{b} = $b; $list{$id}{$name}{e} = $b1; $list{$id}{$name}{a} = 0; $list{$id}{$name}{c} = $ar->[$id][3]; $list{$id}{$name}{i} = $ar->[$id][1]; $list{$id}{$name}{j} = $ar->[$id][2]; $list{$id}{$name}{k} = sprintf("%.4f",$ar->[$id][9]); $pfm->finish( 0, [ \%list, \%thing, \@names ] ); $pfm->wait_all_children;

I'm getting errors about pseudo hashes being deprecated or not existing.

Replies are listed 'Best First'.
Re^2: Parallel::ForkManager and multiple datasets
by Speed_Freak (Sexton) on Jul 05, 2018 at 21:00 UTC

    I got this working, but only for a single data set.I forgot there was another foreach loop going on in one of the "dostuff" sections which is creating a multi dimensional array.

    The problem becomes, how do I return a multidimensional array in its entirety back to the parent?

    #pseudo code use Parallel::ForkManager; my @names = (); my %list = (); my %thing = (); $threads = 20 my $pfm = new Parallel::ForkManager( $threads ); $pfm->run_on_finish( sub { my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_stru +cture_reference) = @_; my $name = $data_structure_reference->{name}; %list = $data_structure_reference->{data1}; $thing{$name}{a} = $data_structure_reference->{thing1}; $thing{$name}{b} = $data_structure_reference->{thing2}; push @names, $data_structure_reference->{name}; }); }); FOREACH: foreach my $thing(keys %{$things_hr}) { my $pid = $pfm->start and next; #do stuff push @names, $name; #do stuff $thing1{$name}{a} = $value1; $thing{$name}{b} = $value2; #do stuff Foreach $id:{ $list{$id}{$name}{b} = $b; $list{$id}{$name}{e} = $b1; $list{$id}{$name}{a} = 0; $list{$id}{$name}{c} = $ar->[$id][3]; $list{$id}{$name}{i} = $ar->[$id][1]; $list{$id}{$name}{j} = $ar->[$id][2]; $list{$id}{$name}{k} = sprintf("%.4f",$ar->[$id][9]); } $pfm->finish( 0, { data1 => %id, name => $sample_name, thing1 => $value1, thing2 => $value2,}); $pfm->wait_all_children;

      Replace

      %list = $data_structure_reference->{data1};

      with

      %list = %{ $data_structure_reference->{data1} };

      and replace

      $pfm->finish( 0, { data1 => %id,

      with

      $pfm->finish( 0, { data1 => \%id,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1217957]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found