$ cat 5.pi.txt b 10 c n s n n v b 283 c v s #save 5.pi.txt $ perl -d pi.pl Loading DB routines from perl5db.pl version 1.55 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(pi.pl:8): my $NUM_THREADS = 5; DB<1> source 5.pi.txt >> b 10 >> c main::(pi.pl:10): my $preplan = q{ main::(pi.pl:11): ( main::(pi.pl:12): step0 main::(pi.pl:13): & main::(pi.pl:14): step1 main::(pi.pl:15): & main::(pi.pl:16): step2 main::(pi.pl:17): & main::(pi.pl:18): step3 main::(pi.pl:19): & main::(pi.pl:20): step4 main::(pi.pl:21): & main::(pi.pl:22): step5 main::(pi.pl:23): ) main::(pi.pl:24): reduce >> n main::(pi.pl:27): my $final_scope = Sub::Genius->new( preplan => $preplan )->run_any( scope => { sum => 0.0, num_steps => 1_000_000, pi => undef } ); >> s Sub::Genius::new(/usr/local/share/perl/5.30.0/Sub/Genius.pm:15): 15: my $pkg = shift; >> n Sub::Genius::new(/usr/local/share/perl/5.30.0/Sub/Genius.pm:16): 16: my %self = @_; >> n Sub::Genius::new(/usr/local/share/perl/5.30.0/Sub/Genius.pm:17): 17: my $self = \%self; >> v 14 sub new { 15: my $pkg = shift; 16: my %self = @_; 17==> my $self = \%self; 18: bless $self, $pkg; 19: die qq{'preplan' parameter required!\n} if not defined $self->{preplan}; 20 21 # set to undef to disable preprocessing 22: if ( not exists $self->{preprocess} ) { 23: $self->{preprocess} = 1; >> b 283 >> c Sub::Genius::run_once(/usr/local/share/perl/5.30.0/Sub/Genius.pm:283): 283: die $@ if $@; # be nice and die for easier debuggering >> v 280: local $@; 281: foreach my $sub (@seq) { 282: eval sprintf( qq{%s%s(\$opts{scope});}, $opts{ns}, $sub ); 283==>b die $@ if $@; # be nice and die for easier debuggering 284 } 285 } 286: return $opts{scope}; 287 } 288 289 # >> s Undefined subroutine &main::step called at (eval 38)[/usr/local/share/perl/5.30.0/Sub/Genius.pm:282] line 1. at /usr/local/share/perl/5.30.0/Sub/Genius.pm line 283. Sub::Genius::run_once(Sub::Genius=HASH(0x5643068207b0), "scope", HASH(0x564306ab08c0)) called at /usr/local/share/perl/5.30.0/Sub/Genius.pm line 245 Sub::Genius::run_any(Sub::Genius=HASH(0x5643068207b0), "scope", HASH(0x564306ab08c0)) called at pi.pl line 27 Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. >> #save 5.pi.txt DB<5> q $ cat pi.pl #!/usr/bin/env perl use strict; use warnings; use Sub::Genius; my $NUM_THREADS = 5; my $preplan = q{ ( step0 & step1 & step2 & step3 & step4 & step5 ) reduce }; my $final_scope = Sub::Genius->new( preplan => $preplan )->run_any( scope => { sum => 0.0, num_steps => 1_000_000, pi => undef } ); printf qq{pi = %f\n}, $final_scope->{pi}; sub step0 { my $scope = shift; my $step_id = 0; $scope->{sum} = _do_calc( $step_id, $scope ); return $scope; } sub step1 { my $scope = shift; my $step_id = 1; $scope->{sum} = _do_calc( $step_id, $scope ); return $scope; } sub step2 { my $scope = shift; my $step_id = 2; $scope->{sum} = _do_calc( $step_id, $scope ); return $scope; } sub step3 { my $scope = shift; my $step_id = 3; $scope->{sum} = _do_calc( $step_id, $scope ); return $scope; } sub step4 { my $scope = shift; my $step_id = 4; $scope->{sum} = _do_calc( $step_id, $scope ); return $scope; } sub step5 { my $scope = shift; my $step_id = 5; $scope->{sum} = _do_calc( $step_id, $scope ); return $scope; } sub reduce { my $scope = shift; my $num_steps = $scope->{num_steps}; my $step = 1 / $num_steps; $scope->{pi} = $scope->{sum} * $step; return $scope; } sub _do_calc { my ( $id, $scope ) = @_; my $sum = $scope->{sum}; my $num_steps = $scope->{num_steps}; my $step = 1 / $num_steps; for ( my $i = $id ; $i < $num_steps ; $i += $NUM_THREADS ) { my $x = ( $i + 0.5 ) * $step; $sum += 4.0 / ( 1 + $x * $x ); } return $sum; } $