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 value to rp0/ip0 $GENERIC() rp = rp0, ip = ip0; // Copy again for the initial iteration $GENERIC() rp2 = rp*rp, ip2 = ip*ip; // Find RP^2 and IP^2 for 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 next 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=>"Mandelbrot"} ); print "Compute time: ", time() - $start, $/; print "Press the enter key to exit\n"; ;