Parallel calculations: Difference between revisions
m
→{{header|Perl 6}}: Use Hyper instead of Race to match up the values correctly. Instead of just displaying the first number that has a particular glf, display an array of all found values.
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Use Hyper instead of Race to match up the values correctly. Instead of just displaying the first number that has a particular glf, display an array of all found values.) |
|||
Line 1,399:
=={{header|Perl 6}}==
<lang perl6>▼
▲my @nums = (1_000_000 .. 100_000_000).pick: 100000;
▲my \factories = @nums.race(:batch(@nums / 32)).map: *.&prime-factors.cache;
▲my $gmf = (factories»[0] »=>« @nums).reduce(&max).value;
sub prime-factors ( Int $n where * > 0 ) {
Line 1,427 ⟶ 1,426:
$factor = find-factor( $n, $constant + 1 ) if $n == $factor;
$factor;
The second line takes the list of numbers and converts then to a <tt>
▲The second line takes the list of numbers and converts then to a <tt>RaceSeq</tt> that is stored in a raw variable. Any <tt>RaceSeq</tt> overloads <tt>map</tt> and <tt>grep</tt> to convert and pick values in worker threads. The runtime will pick the number of OS-level threads and assign worker threads to them while avoiding stalling in any part of the program. A <tt>RaceSeq</tt> is lazy, so the computation of values will happen in chunks as they are requested in the third line.
Beside <tt>
In [[Perl 6]] most errors are bottled up <tt>Exceptions</tt> inside <tt>Failure</tt> objects that remember where they are created and thrown when used. This is useful to pass errors from one thread to another without losing file and linennumber of the source file that caused the error.
|