GranSim Home Page

This page describes GranSim, a simulator for the parallel execution of Glasgow Parallel Haskell (GPH) programs. Haskell is a non-strict, purely-functional programming language. GPH extends Haskell with annotations for sequential (seq) and parallel (par) composition.

GranSim is based on the Glasgow Haskell Compiler (GHC) and available from the anonymous FTP server (Version 0.29 of GHC). Basically, GranSim is just a special setup of GHC, similar to the parallel setup (GUM). In the GranSim setup the compiler instruments the generated code. This information is used by the runtime-system to perform an event driven simulation. The actual graph reduction code is the same as for sequential compilation with GHC. Therefore, all optimisations in GHC can be used for GranSim, too. For now, GranSim only been tested with the Haskell 1.2 front-end of GHC.


How to Get GranSim

GranSim is available by anonymous FTP from Glasgow, in the directory pub/haskell/glasgow: (

The Glasgow site is mirrored by (, in computing/programming/languages/haskell/glasgow.

A description of the contents of the Glasgow FTP server can be found in

GranSim is part of GHC, actually it is a special setup of GHC 0.29. To install it you have to download a GranSim bundle of GHC for the architecture you are using. Then download a GranSim friendly version of hsc and replace the hsc in the bundle with it:

gransim.ANNOUNCE		This file

gransim-guide{.ps,.info.tar,.html.tar}.gz	GranSim User's Guide

ghc-0.29-gransim->platform<.tar.gz  Binary distribution of GranSim.
				This bundle and a GranSim friendly hsc are all
				you need to compile (ghc -gransim) and run
				parallel Haskell programs.

	>platform< ==<	alpha-dec-osf2

ghc-0.29-gran-hsc->platform<.gz  The GranSim friendly hsc.
			 Replace the hsc in the GranSim bundle with this one
			 before you start using GranSim.

ghc-0.29-gran-hc-files.tar.gz Basic set of intermediate C (.hc) files for 
			 the compiler proper, and the prelude in GranSim setup.
			 Used for bootstrapping the system.

The Main Features of GranSim

The main features of GranSim are:

An Example Program

This section discusses a very simple parallel example program to convey the main idea of how to express parallelism in GPH.

We use the well-known nfib function as an example. Here is the sequential version:

nfib :: Int -> Int
nfib 0 = 1
nfib 1 = 1
nfib n = nf1+nf2+1
         where nf1  = nfib (n-1)
               nf2  = nfib (n-2)

The straightforward idea for parallelising nfib is to start parallel processes for computing both recursive calls. This is expressed with the par annotation, which `sparks' a parallel process for computing its first argument and whose result is its second argument. This gives the following parallel program:

parfib :: Int -> Int
parfib 0 = 1
parfib 1 = 1
parfib n = nf2 `par` (nf1 `par` (nf1+nf2+1))
           where nf1 = parfib (n-1)
                 nf2 = parfib (n-2)

The drawback of this program is the blocking of the main task on the two created child-tasks. Only when both child tasks have returned a result, the main task can continue. It is more efficient to have one of the recursive calls computed by the main task and to spark only one parallel process for the other recursive call. In order to guarantee that the main expression is evaluated in the right order (i.e. without blocking the main task on the child task) the seq annotation is used:

parfib :: Int -> Int
parfib 0 = 1
parfib 1 = 1
parfib n = nf2 `par` (nf1 `seq` (nf1+nf2+1))
           where nf1 = parfib (n-1)
                 nf2 = parfib (n-2)

The operational reading of this function is as follows: First spark a parallel process for computing the expression parfib (n-2). Then evaluate the expression parfib (n-1). Finally, evaluate the main expression. If the parallel process has not finished by this time the main task will be blocked on nf2. Otherwise it will just pick up the result.

This simple example already shows several basic aspects of parallel, lazy functional programming:

Parallelism Profiles

This section shows some activity profiles generated by GranSim's visualisation tools. See the appropriate section in the GranSim User's Guide for a more detailed discussion of the visualisation tools and for more examples.

The first example is a PostScript picture showing the overall activity during the execution of a simple parallel example program (searching for a list of words in a grid of letters). The overall activity profile separates the threads into five different classes:

The number of threads in each class is shown for each point in time.

The second example shows the per-processor activity profile for the same program. It shows one strip for each of the simulated processors. Each of these strips encodes three pieces of information:

The third example shows a per-thread activity profile for a part of the same program. In this profile active (running) periods of a thread are shown as a thick green line. Periods of fetching remote data are shown as a blue line. Periods of suspension, because another thread is running on that processor, are shown as a red line. Finally, periods in which a thread is blocked because it needs data that is being evaluated by another thread are shown as gaps in the profile.

We also have an experimental Java script to generate a dynamic visualisation of the program execution. The idea is to represent the parallel machine as a sequqence of processors and to show for each processor its state (as color) and its load (as the height of the associated bar). Here is a demo.

Documentation about GranSim and Publications

A more detailed description of GranSim with more example programs, a discussion of available options and of visualisation tools and an introduction to parallel non-strict functional programming in the large can be found in the GranSim User's Guide (PostScript, PostScript 2-up, Info).

Finally, here is a list of our publications about parallel, non-strict functional programming. This covers both GranSim and GUM.


This page is currently under construction!


Hans-Wolfgang Loidl <>
Last modified: Mon Mar 5 14:35:20 2001