Next: Controlling and Analysing the
Up: Parallel Execution
Previous: Using the Parallel System
  Index
Subsections
Parallel Annotation
The basic language construct for parallelising a program is
the parallel/1 annotation, for example
:- parallel colour/1.
colour(red).
colour(green).
colour(blue).
Without the annotation, the system would backtrack sequentially through the
alternative solutions of colour(X), and X would successively take the values
red, green and blue.
When using the parallel annotation, all three solutions are (potentially)
explored in parallel by different workers, so one worker continues with X=blue,
another with X=red and a third one with X=green.
Note that for a parallel predicate
- the order of the clauses is not relevant
- there is no programmer control over which worker takes which
alternative8.1.
Note that not only is colour/1 executed in parallel, but also the
resulting alternative continuations, e.g. if a program contains
the sequence
..., colour(X), work(X), ...
then the goals work(red), work(blue) and work(green) will also be executed
in parallel, as a consequence of the nondeterminism in colour/1.
For many applications, it is enough to add parallel annotations
to a small number
of central points in a program in order to achieve parallel speedup.
A parallel primitive that is useful to build upon is fork/2.
It behaves as if defined by
:- parallel fork/2.
fork(N, N).
...
fork(N, 2).
fork(N, 1).
i.e. a call of fork(100, X) generates the numbers between 1 and 100
in parallel, where the limit does not have to be fixed at compile time.
The library par_util (see appendix A.9)
contains some predicates that are frequently
used and are built on top of the above mentioned primitives.
par_member/2, par_delete/3, par_between/3,
par_maplist/3 etc. are parallel versions of the corresponding
sequential predicates.
It also contains &/2 which implements a restricted form of
AND-parallelism.
The finite domain solver library library(fd) provides par_indomain/1,
a parallel version of indomain/1.
The finite set solver library(conjunto) provides par_refine/1,
a parallel version of refine/1.
The library elipsys provides compatibility with the ElipSys system and
uses the par_util library.
Next: Controlling and Analysing the
Up: Parallel Execution
Previous: Using the Parallel System
  Index
1999-08-06