experiments with parallelism
François Perrad
francois.perrad at gadz.org
Mon May 10 09:27:40 UTC 2010
I start experiment of parallelism with Parrot.
My goal is to add a parallelized build in the distutils library.
I try to run several ParrotThread which share a same Iterator (see code
below)
without the flag .PARROT_CLONE_GLOBALS, don't work
with the flag .PARROT_CLONE_GLOBALS, work but it's not the wanted behavior
(each thread does the whole job)
{{{
.sub 'main' :main
.local pmc cmds
cmds = new 'ResizableStringArray'
push cmds, 'sleep 1'
push cmds, 'sleep 2'
push cmds, 'sleep 3'
push cmds, 'sleep 4'
push cmds, 'sleep 5'
push cmds, 'sleep 6'
run_jobs(cmds)
.end
.include 'cloneflags.pasm'
.sub 'run_jobs'
.param pmc cmds
.const int jobs = 3
.local pmc it, threads
it = iter cmds
set_global 'iter_jobs', cmds
threads = new 'FixedPMCArray'
set threads, jobs
.const 'Sub' func = '_run_jobs'
$I0 = 0
L1:
unless $I0 < jobs goto L2
$P0 = new 'ParrotThread'
threads[$I0] = $P0
inc $I0
.local int flags
flags = .PARROT_CLONE_CODE
flags = bor flags, .PARROT_CLONE_GLOBALS
$P0.'run'(flags, func, it)
say "run"
goto L1
L2:
sleep 5
$I0 = 0
L3:
unless $I0 < jobs goto L4
$P0 = threads[$I0]
$P0.'join'()
say "join"
goto L3
L4:
say "final rendez-vous"
.end
.sub '_run_jobs'
.local pmc it
it = get_global 'iter_jobs'
L1:
unless it goto L2
$S0 = shift it
say $S0
$I0 = spawnw $S0
goto L1
L2:
say "end thread"
.end
}}}
François
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.parrot.org/pipermail/parrot-dev/attachments/20100510/3592d8e5/attachment.htm>
More information about the parrot-dev
mailing list