[Edinburgh-pm] parallel semantics in perl

Miles Gould miles at assyrian.org.uk
Tue Dec 14 02:51:03 PST 2010

On Mon, Dec 13, 2010 at 08:15:09PM +0000, Wim Vanderbauwhede wrote:
> I'm looking into a way to run Perl on a manycore or multiprocessor
> system without visible threads or forks. To do so I want to assume
> parallel evaluation, i.e. all independent statements in a block or
> function argument list are evaluated in parallel. Similarly, loops are
> sequential; but in many cases they can be unrolled and evaluated in
> parallel.

I'm not quite sure what you're asking. I see three possibilities:

1) Within each block, build up use-def chains, and try to run every set
of nonorderable statements in parallel. Side-effecting builtins like
"print" (but not, say, "open", because that's treated as a variable
definition) dominate every statement that's after them in a lexical
block, and purity of function calls is determined recursively.

This may make no sense: I'd have to think about it harder. And really,
if autoparallelisation were this easy, someone would have solved the
problem by now.

Thinking a /little/ bit harder: references and aliasing kill you here.
But reference-heavy code is much rarer in Perl than it is in (to pick an
example /purely/ at random) C++, so this might actually be somewhat
useful, given a really good test suite.

2) Treat /blocks/ as sequential, but by default run different
/invocations/ of blocks parallelly. So if I write, say,

foreach my $flintstone (qw/Fred Barney Betty Wilma Bamm-bamm Dino Pebbles/) {
	my $surname = surname($flintstone);
	say "Yabba-dabba-doo, $flintstone $surname!";

then the assignment to $surname would always happen before the
corresponding call to "say", but Fred's block would run in parallel with
Barney's block, and so on.

3) As above, but only run invocations in parallel if the user has
annotated them in some way.

> For example, whereas statements in a bare {...} block will be
> evaluated in parallel,  a do {...} could mean sequential evaluation. A
> "foreach" in full could be parallel, a "for" sequential.

In common with everyone else, I really hate this idea :-) I like Aaron's
lexically-scoped pragma idea; failing that, I'd suggest simply adding
"pfor", "pdo", "pgrep" keywords (or "sfor", "sdo" etc for option 2).


for life is not a paragraph and death i think is no parenthesis
  -- e e cummings

More information about the Edinburgh-pm mailing list