Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

a look at Sub::Genius with the debugger, and use v in 2021

by Aldebaran (Curate)
on Jun 11, 2021 at 00:51 UTC ( [id://11133755]=perlquestion: print w/replies, xml ) Need Help??

Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:

I was looking at my normal youtube feed when Leon Timmermans came up with a presentation about Raku. (Certainly interesting, and I have questions for him, but not now.) I soon realized that the zoom convention was happening, and that I could get it in essentially real time on youtube. I have them on as I go about my business, and B Estrade's talk comes on. I went about cleaning the kitchen at the start, but once it started into graph theory, I got very interested, and gave it my full attention. As things started cooking, the moderator chimed in that five minutes remained, and the presenter was left to rush through slides, to my, and seemingly, his dismay. He didn't get to running code, but I was interested enough to see what I could dig up. I feel like there was a second half to the talk that I would gladly hear. I tried to fill in the gaps by working some code, and I would like to post sources, output and questions.

I'll present with a script that came from Sub-Genius, with the exception of one line changed. It is the first of his japh examples. If you download this precise script, then the breakpoints I give here will make sense. I didn't move any working code up or down. Here is 1.japh.pl:

#!/usr/bin/env perl use v5.30.0; # implies strict use warnings; use feature 'state'; use FindBin qw/$Bin/; use lib qq{$Bin/../lib}; use Sub::Genius (); # # Implements classic JAPH, perl hacker hackerman benchmark # sequentially consistent, yet oblivious, way - that's right! # This is a Sequential Consistency Oblivious Algorithm (in the # same vein as 'cache oblivious' algorithms # # paradigm below is effective 'fork'/'join' # my $pre = q{ begin ( J & A & P & H ) end }; # Load PRE describing concurrent semantics my $sq = Sub::Genius->new(preplan => $pre ); my $GLOBAL = {}; # 'compile' PRE $sq->init_plan; # run loop-ish $sq->run_once( verbose => $ARGV[0], # 'scope' is passed as reference to all calls, effectively # acts as shared memory, federated only among subroutine # participating in the serialized excecution plan scope => { japh => [ qw/just Another perl/, q{Hacker,} ], curr => 0, contrib => [], } ); # Dump $GLOBAL that's now been changed if ( $ARGV[0] ) { print qq{\n... actual contributions of each sub ...\n}; foreach my $k ( keys %$GLOBAL ) { printf( qq{ %s() => %s\n}, $k, $GLOBAL->{$k} ); } } # # ## S T A T E S U B S ## # # # noop sub begin { my $scope = shift; state $persist = {}; # gives subroutine memory, also 'private' my $private = {}; # reset after each call return; } sub J { my $scope = shift; state $persist = { akctual => $scope->{japh}->[ $scope->{curr} ], +}; # gives subroutine memory, also 'private' + # sub's killroy $GLOBAL->{J} = $persist->{akctual}; ++$scope->{curr}; my $private = {}; + # reset after each call push @{ $scope->{contrib} }, $persist->{akctual}; return; } sub A { my $scope = shift; state $persist = { akctual => $scope->{japh}->[ $scope->{curr} ], +}; # gives subroutine memory, also 'private' + # sub's killroy $GLOBAL->{A} = $persist->{akctual}; ++$scope->{curr}; my $private = {}; + # reset after each call push @{ $scope->{contrib} }, $persist->{akctual}; return; } sub H { my $scope = shift; state $persist = { akctual => $scope->{japh}->[ $scope->{curr} ], +}; # gives subroutine memory, also 'private' + # sub's killroy $GLOBAL->{H} = $persist->{akctual}; ++$scope->{curr}; my $private = {}; + # reset after each call push @{ $scope->{contrib} }, $persist->{akctual}; return; } sub P { my $scope = shift; state $persist = { akctual => $scope->{japh}->[ $scope->{curr} ], +}; # gives subroutine memory, also 'private' + # sub's killroy $GLOBAL->{P} = $persist->{akctual}; ++$scope->{curr}; my $private = {}; + # reset after each call push @{ $scope->{contrib} }, $persist->{akctual}; return; } sub end { my $scope = shift; state $persist = {}; + # gives subroutine memory, also 'private' my $private = {}; + # reset after each call printf( "%s\n", join( q{ }, @{ $scope->{contrib} } ) ); return; } exit;

The only difference is the change from

use strict;

to

use v5.30.0; # implies strict

Normally, I would get my strictness by using the version number alone, thus:

use 5.30.0;

Q1.a) Are the above statements semantically equivalent in perl5?

Q1.b) Will they be in perl 7?

There was *a lot* said about use v in Suckitude 2020, and there seems to be many and varying opinions. I don't know where the whole thing ended up. Q1.c) Let me ask this, if I am going to use a version number, is this now preferred syntax?

use v5.30.0; # implies strict

For output I have the source files from runs with the debugger. I need to play with software to understand it. The following source worked for getting a look at this script using the debugger. I built my way to this with runs and edits:

b 70 b 82 b 94 b 106 b 118 b 126 c c v p $persist->{akctual} v c p $persist->{akctual} v c p $persist->{akctual} v c p $persist->{akctual} v c p @{$scope->{contrib}} #save 4.seq.txt

This yields:

$ perl -d 1.japh.pl jehosophat 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::(1.japh.pl:20): my $pre = q{ main::(1.japh.pl:21): begin main::(1.japh.pl:22): ( main::(1.japh.pl:23): J & main::(1.japh.pl:24): A & main::(1.japh.pl:25): P & main::(1.japh.pl:26): H main::(1.japh.pl:27): ) main::(1.japh.pl:28): end DB<1> source 4.seq.txt + >> b 70 >> b 82 >> b 94 >> b 106 >> b 118 >> b 126 >> c plan: "begin A H J P end" <<< Execute: main::begin(1.japh.pl:70): return; >> c main::A(1.japh.pl:94): return; >> v 91: ++$scope->{curr}; 92: my $private = {}; + # reset after each call 93: push @{ $scope->{contrib} }, $persist->{akctual}; 94==>b return; 95 } 96 97 sub H { 98: my $scope = shift; 99: state $persist = { akctual => $scope->{japh}->[ $scope->{cu +rr} ], }; # gives subroutine memory, also 'private' 100 + # sub's killroy >> p $persist->{akctual} just >> v 98: my $scope = shift; 99: state $persist = { akctual => $scope->{japh}->[ $scope->{cu +rr} ], }; # gives subroutine memory, also 'private' 100 + # sub's killroy 101: $GLOBAL->{H} = $persist->{akctual}; 102 103: ++$scope->{curr}; 104: my $private = {}; + # reset after each call 105: push @{ $scope->{contrib} }, $persist->{akctual}; 106:b return; 107 } >> c main::H(1.japh.pl:106): return; >> p $persist->{akctual} Another >> v 103: ++$scope->{curr}; 104: my $private = {}; + # reset after each call 105: push @{ $scope->{contrib} }, $persist->{akctual}; 106==>b return; 107 } 108 109 sub P { 110: my $scope = shift; 111: state $persist = { akctual => $scope->{japh}->[ $scope->{c +urr} ], }; # gives subroutine memory, also 'private' 112 + # sub's killroy >> c main::J(1.japh.pl:82): return; >> p $persist->{akctual} perl >> v 79: ++$scope->{curr}; 80: my $private = {}; + # reset after each call 81: push @{ $scope->{contrib} }, $persist->{akctual}; 82==>b return; 83 } 84 85 sub A { 86: my $scope = shift; 87: state $persist = { akctual => $scope->{japh}->[ $scope->{cu +rr} ], }; # gives subroutine memory, also 'private' 88 + # sub's killroy >> c main::P(1.japh.pl:118): return; >> p $persist->{akctual} Hacker, >> v 115: ++$scope->{curr}; 116: my $private = {}; + # reset after each call 117: push @{ $scope->{contrib} }, $persist->{akctual}; 118==>b return; 119 } 120 121 sub end { 122: my $scope = shift; 123: state $persist = {}; + # gives subroutine memory, also 'private' 124: my $private = {}; + # reset after each call >> c just Another perl Hacker, main::end(1.japh.pl:126): return; >> p @{$scope->{contrib}} justAnotherperlHacker, >> #save 4.seq.txt DB<14> q + $

I'm still not quite sure what all I'm looking at here, but I continue with the debugger to pick at it. Here is another source file that I found illuminating:

M b 82 c y c #save 3.2.txt
$ perl -d 1.japh.pl jesophat ... DB<1> source 3.2.txt + 1.japh.pl* 2.seq.txt 3.2.txt 4.seq.txt _Sub:: +Genius/ 1.seq.txt 3.1.txt 3.seq.txt 5.seq.txt DB<1> source 3.2.txt >> M 'FLAT.pm' => '1.0.4 from /usr/local/share/perl/5.30.0/FLAT.pm' 'FLAT/DFA.pm' => '/usr/local/share/perl/5.30.0/FLAT/DFA.pm' 'FLAT/DFA/Minimal.pm' => '/usr/local/share/perl/5.30.0/FLAT/DFA/Minima +l.pm' 'FLAT/FA.pm' => '/usr/local/share/perl/5.30.0/FLAT/FA.pm' 'FLAT/NFA.pm' => '/usr/local/share/perl/5.30.0/FLAT/NFA.pm' 'FLAT/PFA.pm' => '/usr/local/share/perl/5.30.0/FLAT/PFA.pm' 'FLAT/Regex.pm' => '/usr/local/share/perl/5.30.0/FLAT/Regex.pm' 'FLAT/Regex/Op.pm' => '/usr/local/share/perl/5.30.0/FLAT/Regex/Op.pm' 'FLAT/Regex/Parser.pm' => '/usr/local/share/perl/5.30.0/FLAT/Regex/Par +ser.pm' 'FLAT/Regex/WithExtraOps.pm' => '/usr/local/share/perl/5.30.0/FLAT/Reg +ex/WithExtraOps.pm' 'FLAT/Symbol.pm' => '/usr/local/share/perl/5.30.0/FLAT/Symbol.pm' 'FLAT/Symbol/Regex.pm' => '/usr/local/share/perl/5.30.0/FLAT/Symbol/Re +gex.pm' 'FLAT/Transition.pm' => '/usr/local/share/perl/5.30.0/FLAT/Transition. +pm' 'FLAT/Transition/Simple.pm' => '/usr/local/share/perl/5.30.0/FLAT/Tran +sition/Simple.pm' >> b 82 >> c plan: "begin A P J H end" <<< Execute: main::J(1.japh.pl:82): return; >> y $GLOBAL = HASH(0x557b5132e420) 'A' => 'just' 'J' => 'perl' 'P' => 'Another' $persist = HASH(0x557b5251d3b8) 'akctual' => 'perl' $private = HASH(0x557b5251d298) empty hash $scope = HASH(0x557b524e0fd8) 'contrib' => ARRAY(0x557b5132e3d8) 0 'just' 1 'Another' 2 'perl' 'curr' => 3 'japh' => ARRAY(0x557b510bec80) 0 'just' 1 'Another' 2 'perl' 3 'Hacker,' $sq = Sub::Genius=HASH(0x557b5214ad38) 'DFA' => FLAT::DFA=HASH(0x557b524d2410) 'ALPHA' => HASH(0x557b524e1a28) 'A' => 8 'H' => 8 'J' => 8 'P' => 8 'begin' => 1 'end' => 1 'preplan' => '[begin]([J]&[A]&[P]&[H])[end]' 'preprocess' => 1 >> c just Another perl Hacker, ... actual contributions of each sub ... H() => Hacker, P() => Another A() => just J() => perl Debugged program terminated. Use q to quit or R to restart,

It helps for me to see the notation at different stages. Also, I can quickly get to the documentation in the sources, which was excellent. You don't know what FLAT is until you do:

$ perldoc /usr/local/share/perl/5.30.0/Sub/Genius.pm $ perldoc /usr/local/share/perl/5.30.0/FLAT.pm $ perldoc /usr/local/share/perl/5.30.0/FLAT/DFA.pm

Other things I tried to grapple with, but struggled with notation, like Thompson%27s_construction. I did stumble on this, and it seems to address a lot of this history: 2007 article on regex performance. Perl compares unfavorably, and it was refuted in Re: Perl regexp matching is slow??. grinder gives an example that avoids greedy matching.

Q2.a) Is it best to avoid greedy matching unless you need it?

Q2.b) Would any of the 'no' pragmata close this performance loophole?

I thought the joke that perl was "an OS in need of a better programming language" was funny. I have one final question about the thing that keeps me in perl right now, the debugger:

Q3) Is there a term for the files one saves from debugging sessions, that is the files that are accessed using the source command?

Thanks to presenters. I've seen several and might need half a year to see them all. I appreciate your service. Thanks also for comments,

Replies are listed 'Best First'.
Re: a look at Sub::Genius with the debugger, and use v in 2021
by oodler (Acolyte) on Jun 14, 2021 at 17:39 UTC
    Wow, ty Aldebaran. I'd be happy to help you with any questions. I just wrapped up another 1:30:00 video covering the latter part of that talk. I am hoping they'll add it as an addendum to the conf talk list. Otherwise, I will share it here. We can discuss here, also feel free to HMU on irc dot perl dot org. Similar username as to this one. I joined PM just to reply to this, much appreciated.

    Update: I do want to make it very clear that the "regular expressions" I am discussing in this talk have nothing to do with perl's regexp engine. Though the topic is fundamentally similar since I hear that the perl regexp engine is DFA based. The perl regexp engine is far more powerful than a mere DFA. See:
Re: a look at Sub::Genius with the debugger, and use v in 2021
by oodler (Acolyte) on Jun 21, 2021 at 07:19 UTC
    Part 2 is available directly now, though unlisted. Here it is Aldebaran - https://www.youtube.com/watch?v=XOnPF5GnhHE. It is an additional 1:30:18. I am happy to answer questions - like I said, I am available usually on irc dot perl dot org. You can also email me at my CPAN address.

      Hi Brett,

      Welcome to the monastery. I hope your friendly presence makes it feel less cloistered here. I've taken the opportunity to look and listen to your presentations, and I'm so glad that you took the time you needed to get through the initial arc of it. I've been in conversations with people who do representations that take 1, 3, 6 hours, and you seem to be of this variety, ideas coming out of your ideas like the florets of a cauliflower("...and in the infinite case....") You should know that I'm only intermediate as a practioner of perl, despite having been at it for a while now.

      I have some pretty grandiose ideas of where this software could take us, but it would have to be an "us" thing. By that I mean, you, me, and others would have to get their paws on this if it's gonna realize its goal. One might think that there's fewer perl practioners to help with anything, but what if it offered the carrot of not having bad forks nor race conditions, provided that the user doesn't embellish and add them? The last perl script I wrote with fork was equal amounts hideous and faulty.

      I've worked through several examples. The five older ones are solid, but the last 3 pi ones need some more spitshine. My theory is that you wrote over your previous work. Let's take a look at the second one first. I will list source, output from stdout, source text from debugger, then debugger output:

      #!/usr/bin/env perl use strict; use warnings; use feature 'state'; 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( sc +ope => { sum => 0.0, num_steps => 1_000_000, pi => undef } ); printf qq{pi = %f\n}, $final_scope->{pi}; sub AUTOLOAD { our $AUTOLOAD; my $sub = $AUTOLOAD; $sub =~ s/.*:://; die if $sub !~ m/^step([\d]+)/; my $step_id = $1; # deal with 'step' my $old_scope = shift; my $new_scope = _snep( $step_id, $old_scope ); return $new_scope; } sub _snep { my ( $step_id, $scope ) = @_; $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; }

      Stdout has:

      $ ./pi2.pl Died at ./pi2.pl line 36. $

      This is my debugger source text, 3.scope.txt:

      #source 2.scope.txt f Genius.pm b 282 s n n p $sub v s v s v b 35 c n p $sub p $sub !~ m/^step([\d]+)/ #save 3.scope.txt

      Debug output:

      $ perl -d pi2.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::(pi2.pl:9): my $NUM_THREADS = 5; DB<1> source 3.scope.txt >> #source 2.scope.txt >> f Genius.pm Choosing /usr/local/share/perl/5.30.0/Sub/Genius.pm matching 'Genius.p +m': >> b 282 >> s main::(pi2.pl:11): my $preplan = q{ main::(pi2.pl:12): ( main::(pi2.pl:13): step0 main::(pi2.pl:14): & main::(pi2.pl:15): step1 main::(pi2.pl:16): & main::(pi2.pl:17): step2 main::(pi2.pl:18): & main::(pi2.pl:19): step3 main::(pi2.pl:20): & main::(pi2.pl:21): step4 main::(pi2.pl:22): & main::(pi2.pl:23): step5 main::(pi2.pl:24): ) main::(pi2.pl:25): reduce >> n main::(pi2.pl:28): my $final_scope = Sub::Genius->new( preplan => $ +preplan )->run_any( scope => { sum => 0.0, num_steps => 1_000_000, pi + => undef } ); >> n Sub::Genius::run_once(/usr/local/share/perl/5.30.0/Sub/Genius.pm:282): 282: eval sprintf( qq{%s%s(\$opts{scope});}, $opts{ns}, + $sub ); >> p $sub step >> v 279 # main run loop - run once 280: local $@; 281: foreach my $sub (@seq) { 282==>b eval sprintf( qq{%s%s(\$opts{scope});}, $opts{n +s}, $sub ); 283: die $@ if $@; # be nice and die for easier debu +ggering 284 } 285 } 286: return $opts{scope}; 287 } 288 >> >> s Sub::Genius::run_once((eval 44)[/usr/local/share/perl/5.30.0/Sub/Geniu +s.pm:282]:1): 1: main::step($opts{scope}); >> v 1==> main::step($opts{scope}); 2 ; >> s main::AUTOLOAD(pi2.pl:33): our $AUTOLOAD; >> v 30: printf qq{pi = %f\n}, $final_scope->{pi}; 31 32 sub AUTOLOAD { 33==> our $AUTOLOAD; 34: my $sub = $AUTOLOAD; 35: $sub =~ s/.*:://; 36: die if $sub !~ m/^step([\d]+)/; 37: my $step_id = $1; 38 39 # deal with 'step' >> b 35 >> c main::AUTOLOAD(pi2.pl:35): $sub =~ s/.*:://; >> n main::AUTOLOAD(pi2.pl:36): die if $sub !~ m/^step([\d]+)/; >> p $sub step >> p $sub !~ m/^step([\d]+)/ 1 >> #save 3.scope.txt DB<10> s + Sub::Genius::run_once(/usr/local/share/perl/5.30.0/Sub/Genius.pm:283): 283: die $@ if $@; # be nice and die for easier debu +ggering DB<10> s + Died at pi2.pl line 36. at /usr/local/share/perl/5.30.0/Sub/Genius.pm line 283. Sub::Genius::run_once(Sub::Genius=HASH(0x564d07b619b8), "scope", H +ASH(0x564d07e0f210)) called at /usr/local/share/perl/5.30.0/Sub/Geniu +s.pm line 245 Sub::Genius::run_any(Sub::Genius=HASH(0x564d07b619b8), "scope", HA +SH(0x564d07e0f210)) called at pi2.pl line 28 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. DB<10>

      The truth is that I don't get what goes wrong here, but I think I've framed where it happens. The scoping is hard for me to get my head around, but is it not the implementation of an AST?

      I could take you through the first one in a similar way, but again, I think it got overwritten, so fix 2 then fix 1 makes sense in such a scenario to me. The third is tantalizing, but we seem to have some inflation there:

      $ ./pi3.pl pi = 3.769908 $

      Have you read Borwein and Borwein re pi calculations? (A classic.) Worth the interlibrary loan if you haven't.

      Anyways, I'm gonna get this posted hoping that the surfeit of brilliant perl programmers who suddenly have more time on the their hands than usual can pick up where I tap out.

      Also, I've seen how you attack a keyboard, and monastery markup might be tedious from scratch. This is what I use as a template for posts:

      Edit: Removed the use of an earlier version and redundant use warnings in a subroutine.

      use warnings; use 5.011;

      Have a great day. I like scripting in the AC when the alternative is an unforgiving sun....

        Aldebaran, thanks for the kind words and welcome. I'll reply to a few things to get a handle on what direction you're heading.
        The truth is that I don't get what goes wrong here, but I think I've framed where it happens. The scoping is hard for me to get my head around, but is it not the implementation of an AST?

        The AST is only relevant when it comes to the construction of the DFA that is ultimately used to produce a single valid line of execution. Sub::Genius just takes what FLAT is able to generate as a string derived from the PRE (by way of an equivalent DFA). Are you trying to figure out how to go from the PRE to the DFA? An AST is involved in the conversion from the PRE to the PFA, but after that it is not involved at all.

        Thank you for the pointer to the work of the Borweins, I am not a math guy but do enjoy reading about the subject and interesting people around it. Numerical errors notwithstanding, here are some suggestions that I think can help:
        • any word in the PRE represents a subroutine that is called when the "plan" is run; you have access to all the good stuff perl provides, such as AUTOLOAD; this was just a demo of handling subroutines that were not explicitly defined
        • the stubby utility has a new "list" subcommand that will take a PRE and list all valid orderings implied; I added this as a way to more easily see what execution orderings of the subroutines you were admitting
        • there is an error in the pi examples that are corrected in the latest release on CPAN - NUM_THREADS should be 6; but I think you figured that out
        • all parts of perl's memory model hold, see below for what I mean.
        Here's an example of running stubby to list all possible valid subroutine execution orderings:
        $ stubby list -p "begin ( sub1 & sub2 & sub3 ) end" begin sub1 sub3 sub2 end begin sub1 sub2 sub3 end begin sub2 sub1 sub3 end begin sub2 sub3 sub1 end begin sub3 sub1 sub2 end begin sub3 sub2 sub1 end
        Regarding perl's memory model, you may program all subroutines assuming that they can access:
        • globaly variables
        • state variables defined within each sub (to create coroutines)
        • an additional execution scope represented by $scope that can be initialized (or not), then treated as an accumulator that is passed into each sub call and returned via each sub call
        My contention is that using the right plan and correct use of the "memory" space, any implicitly shared memory algorithm may be implemented correctly. This remains to be seen, but that's my gut feeling. Note - everything is run sequentially in the perl runtime - thought, there is nothing stopping you from using fork; but that just gets us back to the realities of perl being fundamentally a uniprocess.
        Hope that helps! Feel free to send me links to some stuff you've played with here - obviously, PM is not ideal for really swapping code. :-)
        I could take you through the first one in a similar way,

        I have enough time on a hades hot afternoon to do a lazy write-up for the first pi script from examples for Sub::Genius, that, on my terminal, is tripped up at run_any which calls run_once . I think this frames the issue:

        $ 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 => $p +replan )->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 $sel +f->{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 debu +ggering >> 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 d +ebuggering 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", H +ASH(0x564306ab08c0)) called at /usr/local/share/perl/5.30.0/Sub/Geniu +s.pm line 245 Sub::Genius::run_any(Sub::Genius=HASH(0x5643068207b0), "scope", HA +SH(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( sc +ope => { 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; } $

        Even with the number of threads bumped to 6, it goes no farther. I must say I'm puzzled, because I do not see how this source differs from what Brett shows to compile and behave on his screen at the one hour mark of his second youtube presentation.

Re: a look at Sub::Genius with the debugger, and use v in 2021
by oodler (Acolyte) on Jun 24, 2021 at 18:27 UTC
    I unexpectedly found a really nice document on sequential consistency as it relates to a programming lanaguage, in this case that language is Chapel (a parallel language by Cray from the 2000s) - https://chapel-lang.org/docs/language/spec/memory-consistency-model.html. If I had known about this before my talk, I probably could have expressed the idea in about 10% of the time :-).

    And whereas this is written from the perspective that "Chapel provides a multiprocess" runtime environment and their concerns are "ensuring sequential consistency" in it; my whole premise was, given the idea of sequential consistency and how it applies to parallel environments, how can we express things concurrently with the intent on running them sequentially.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11133755]
Approved by GrandFather
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-29 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found