Anonymous user
Parallel calculations: Difference between revisions
→{{header|Perl 6}}: Provide an example for parallel compution that works today.
(Add Perl) |
(→{{header|Perl 6}}: Provide an example for parallel compution that works today.) |
||
Line 1,400:
=={{header|Perl 6}}==
Assuming that <tt>factors</tt> is defined exactly as in the prime decomposition task:
<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 = ([max] @factories»[0] »=>« @nums).value;
</lang>
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>RaceSeq</tt> and its in order equivalent <tt>HyperSeq</tt>, [[Rakudo]] supports primitive threads, locks and highlevel promises. Using channels and supplies values can be move threadsafe from one thread to another. A react-block can be used as a central hub for message passing.
In the future hyper operators, junctions and feeds will be candidates for autothreading.
=={{header|PicoLisp}}==
|