Difference between revisions of "GHC/Data Parallel Haskell/GHC.PArr"

From HaskellWiki
Jump to navigation Jump to search
 
Line 1: Line 1:
 
== Convenience without the speed: syntactic sugar for a high-level array library ==
 
== Convenience without the speed: syntactic sugar for a high-level array library ==
   
  +
The following explains how to install and use parallel arrays and array comprehensions to prototype nested data-parallel algorithms in Haskell.
Any recent stable version of GHC (e.g., version 6.6) includes syntactic support for array comprehensions and a library of frequently used array operations. To use these, you need to pass GHC the command line option <tt>-fparr</tt> (to enable the extra syntax) and import the module <hask>GHC.PArr</hask> (a Prelude extension for arrays). (If you like to use parallel array comprehensions, you also need <tt>-fglasgow-exts</tt>.) For example, the following module implements a dot product using arrays:
 
  +
  +
=== Installation ===
  +
  +
Any compiler in GHC's 6.6 series includes support for parallel arrays. It is invoked by supplying the compiler option <tt>-fparr</tt> and importing the module <hask>GHC.PArr</hask>. Moreover, to use [http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#parallel-list-comprehensions parallel array comprehensions], the compiler option <tt>-fglasgow-exts</tt> is required.
  +
  +
'''Caveat:''' Due to bugs in the parallel array support in the initial release of 6.6, we recommend to use the [http://www.haskell.org/ghc/dist/current/dist/ development version of GHC] for the moment. These bugs will be fixed in the 6.6.1 release.
  +
  +
=== A small example ===
  +
  +
The following module implements the dot product of two vectors using parallel arrays:
   
 
<haskell>
 
<haskell>
Line 26: Line 36:
 
(NB: The <tt>:set</tt> is needed despite the <tt>OPTIONS</tt> pragma in <tt>DotP.hs</tt>, so that you can use array syntax on the interactive command line of GHCi.)
 
(NB: The <tt>:set</tt> is needed despite the <tt>OPTIONS</tt> pragma in <tt>DotP.hs</tt>, so that you can use array syntax on the interactive command line of GHCi.)
   
Unfortunately, the current version of Haddock does not grok the special array syntax, so there is no nice HTML version of the interface for <hask>GHC.PArr</hask>. Instead, please consult the [http://darcs.haskell.org/packages/base/GHC/PArr.hs source code of <hask>GHC.PArr</hask>].
+
Unfortunately, the current version of Haddock does not grok the special array syntax, so there is no nice HTML version of the interface of <hask>GHC.PArr</hask>. Instead, please consult the [http://darcs.haskell.org/packages/base/GHC/PArr.hs source code of <hask>GHC.PArr</hask>] for details on the supplied array operations.

Revision as of 06:56, 20 March 2007

Convenience without the speed: syntactic sugar for a high-level array library

The following explains how to install and use parallel arrays and array comprehensions to prototype nested data-parallel algorithms in Haskell.

Installation

Any compiler in GHC's 6.6 series includes support for parallel arrays. It is invoked by supplying the compiler option -fparr and importing the module GHC.PArr. Moreover, to use parallel array comprehensions, the compiler option -fglasgow-exts is required.

Caveat: Due to bugs in the parallel array support in the initial release of 6.6, we recommend to use the development version of GHC for the moment. These bugs will be fixed in the 6.6.1 release.

A small example

The following module implements the dot product of two vectors using parallel arrays:

{-# OPTIONS -fparr -fglasgow-exts #-}
module DotP (dotp)
where
import GHC.PArr

dotp :: Num a => [:a:] -> [:a:] -> a
dotp xs ys = sumP [:x * y | x <- xs | y <- ys:]

You can use this module in an interactive GHCi session as follows:

Prelude> :set -fparr -fglasgow-exts
Prelude> :load DotP
[1 of 1] Compiling DotP             ( code/haskell/DotP.hs, interpreted )
Ok, modules loaded: DotP.
*DotP> dotp [:1..3:] [:4..6:]
32
*DotP>

(NB: The :set is needed despite the OPTIONS pragma in DotP.hs, so that you can use array syntax on the interactive command line of GHCi.)

Unfortunately, the current version of Haddock does not grok the special array syntax, so there is no nice HTML version of the interface of GHC.PArr. Instead, please consult the source code of GHC.PArr for details on the supplied array operations.