Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: [OT] Merry Christmas and gift of love

by marioroy (Parson)
on Dec 27, 2021 at 08:44 UTC ( #11139932=note: print w/replies, xml ) Need Help??


in reply to Re: [OT] Merry Christmas and gift of love
in thread [OT] Merry Christmas and gift of love

Congratulations on the PDL parallelisation effort.

Thank you for sharing the article. I'm trying to run the demonstration, beginning on page 6, and encountered a C build failure. See issue on GitHub. Thanks to @mohawk2, this is working.

Update: Remove the size args to pgswin. Thanks, etj.
Update: Display the compute time.

use strict; use warnings; use PDL; use PDL::Graphics::Simple; use Time::HiRes 'time'; no PDL::NiceSlice; # prevents interference use Inline Pdlpp => <<'EOPP'; pp_def('pp_mandel', # Pars (signature) specs threadable arguments. Pars => 'c(n=2); [o]o()', # OtherPars specs scalar arguments. OtherPars => 'int max_it', Code => <<'EOC', // All this code gets wrapped automagically in a thread loop. // It starts a fresh C block, so you can declare stuff up top. // The $GENERIC() macro is the overall expression type. int i; // Iterator $GENERIC() rp0 = $c(n=>0), ip0 = $c(n=>1); // Copy the initial val +ue to rp0/ip0 $GENERIC() rp = rp0, ip = ip0; // Copy again for the i +nitial iteration $GENERIC() rp2 = rp*rp, ip2 = ip*ip; // Find RP^2 and IP^2 f +or magnitude and z^2 // The OtherPars are in the $COMP macro. for(i=$COMP(max_it); rp2+ip2 < 4 && i; i--) { ip *= 2 * rp; rp = rp2 - ip2; // Calculate M_i(z)^2 rp += rp0; ip += ip0; // Add z rp2 = rp*rp; ip2 = ip*ip; // Calculate rp^2 and ip^2 for n +ext time } $o()= i; // Assign the iterator to the output value EOC ); EOPP my $cen = pdl(-0.74897,0.05708); my $coords = $cen + (ndcoords(501,501)/250 - 1) * 0.001; my $w = pgswin(); my $start = time(); $w->image( $coords->using(0,1), $coords->pp_mandel(2500), {title=>"Man +delbrot"} ); print "Compute time: ", time() - $start, $/; print "Press the enter key to exit\n"; <STDIN>;

Replies are listed 'Best First'.
Re^3: [OT] Merry Christmas and gift of love
by etj (Chaplain) on Dec 27, 2021 at 21:18 UTC
    Another thing that changed in 2021 (as well as the parallelisation improvements) is that PDL now has native complex numbers, which means the above code could be simplified to using C99 complex numbers rather than manually doing complex-number / magnitude calculations EDIT TO REMOVE size args to pgswin that caused gnuplot to try to make a gigantic window and run out of memory:
    use strict; use warnings; use PDL; use PDL::Graphics::Simple; use Inline Pdlpp => <<'EOPP'; pp_def('pp_mandel', # Pars (signature) specs threadable arguments. Pars => 'coord(n=2); [o]o(); complex [t]c()', # OtherPars specs scalar arguments. OtherPars => 'int max_it', Code => <<'EOC', /* All this code gets wrapped automagically in a thread loop. */ /* The $GENERIC(c) macro is the type of ndarray "c". */ // using the Wikipedia formula: z_{n+1} = {z_n}^2 + c int i; // iterator. $c() = $coord(n=>0) + I*$coord(n=>1); // Copy the initial value $GENERIC(c) z = $c(); // Copy for the initial iteration // the OtherPars are in the $COMP macro. for(i=$COMP(max_it); cabs(z) < 2 && i; i--) z = z*z + $c(); $o()= i; // Assign the iterator to the output value EOC ); EOPP my $cen = pdl(-0.74897,0.05708); my $coords = $cen + (ndcoords(501,501)/250 - 1) * 0.001; my $w = pgswin(); $w->image( $coords->using(0,1), $coords->pp_mandel(2500), {title=>"Mandelbrot"} ); <STDIN>

    EDIT apparently this version takes twice as long to run as the one that doesn't use C99 complex numbers. I assume this is because mine uses cabs, while the other one uses some cleverness to reduce the amount of multiplications etc.

Re^3: [OT] Merry Christmas and gift of love
by etj (Chaplain) on Dec 27, 2021 at 09:34 UTC
    Thanks for raising the issue, and for fixing it :-D

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2022-09-26 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (118 votes). Check out past polls.

    Notices?