Go to the first, previous, next, last section, table of contents.


Parallelism Annotations

This chapter discusses the constructs for adding parallelism to a Haskell program. All constructs are annotations that do not change the semantics of the program (one exception to this rule is the annotation for forcing sequential evaluation since it may change the strictness properties of the program).

Normally the basic annotations that are discussed first are sufficient to write and tune a parallel program. The advanced annotations allow to name static spark sites and to provide granularity information.

NB: To use these annotations the module Parallel must be imported as shown in the introductory example (see section A Simple Example Program).

Basic Annotations

. . .

The two basic parallelism annotations in GranSim (as well as in GUM and GRIP) are par and seq. Both take two arguments and return the value of the second argument as result. However, they differ in their operational behaviour:

Annotation: par :: a -> b -> b
. par x y creates a spark for evaluating x and returns the value of y as a result.

Annotation: seq :: a -> b -> b
. seq x y reduces x to weak head normal form and then returns the value of y as a result.

The process of sparking a parallel thread creates potential parallelism (a spark). Such a spark may be turned into a thread or may be discarded by the runtime system. Several important facts should be noted about these annotations:

Advanced Annotations

. . . .

The annotations in the previous section are actually specialisations of the following set of built-in functions which can be called directly:

Annotation: parGlobal :: Int -> Int -> Int -> Int -> a -> b -> b
. parGlobal n g s p x y creates a spark for evaluating x and returns the value of y as a result. The spark gets the name n with the granularity information g, the size information s and a degree of parallelism of p. The g, s and p fields just forward information to the runtime system.

Annotation: parLocal :: Int -> Int -> Int -> Int -> a -> b -> b
. parLocal n g s p x y behaves like parGlobal except that the thread (if it is generated at all) must be executed on the current processor.

Annotation: parAt :: Int -> Int -> Int -> Int -> a -> b -> c -> c
. parAt n g s p v x y behaves like parGlobal except that the thread (if it is generated at all) must be executed on the processor that contains the expression v.

Annotation: parAtForNow :: Int -> Int -> Int -> Int -> a -> b -> c -> c
. parAtForNow n g s p v x y behaves like parAt except that the generated thread may be migrated to another processor during the execution of the program.

Experimental Annotations

. .

Some experimental annotations currently available in GranSim are:

Annotation: parAtAbs :: Int -> Int -> Int -> Int -> Int -> a -> b -> b
. parAtAbs n g s p m x y behaves like parAt except that the thread must be executed on processor number m (the processors are numbered from 0 to p-1 where p is the runtime system argument supplied via the -bp option).

Annotation: parAtRel :: Int -> Int -> Int -> Int -> Int -> a -> b -> b
. parAtRel n g s p m x y behaves like parAtAbs except that the value of m is added to the number of the current processor to determine the target processor.

Annotation: copyable :: a -> a
. copyable x marks the expression x to be copyable. This means that the expression will be transferred in its unevaluated form if it is needed on another processor. This may duplicate work.

This annotation is not yet implemented.

Annotation: noFollow :: a -> a
. noFollow x

This annotation is not yet implemented.


Go to the first, previous, next, last section, table of contents.