Headline

Data parallelism in Language:Haskell with Technology:DPH

Motivation

The implementation demonstrates data parallelism in Language:Haskell with Technology:DPH. The operations for totaling and cutting salaries are implemented on top of DPH's parallel arrays. In this manner, we encounter some limitations of DPH with regard to data parallelism. In particular, data parallelism is limited to arrays over primitive types from a DPH-specific Prelude module; there is no support for user-defined types. Hence, we need to flatten the company to a list of salary values, which are of a DPH-specific type for floating point numbers, before salaries can be totaled and cut. The resulting list of cut salaries needs to be reintegrated into the company in question. These conversions obviously take more time than we gain by data parallelism. Hence, the present illustration of DPH is of limited use.

Illustration

Cutting in Parallel

As we mentioned in the motivation section, data parallelism can only be applied to arrays. We therefore flatten the company to become a list of salaries (see this!!SalaryFlattener.hs for details).

Non-parallel code

Unfortunately the normal Prelude list type

[a]
is not amenable to data parallelism, but a special array type called
PArray a
. We therefore need a special function in a non-parallel module for converting between
[Float]
and
PArray Float
before we can cut in parallel:

cut :: Company -> Company
cut c = (consumeSalaries c) (toList $ cutV $ fromList $ flattenSalaries c)

We first flatten the company, then convert the salary list to

PArray Float
and call the cut function
cutV
from a parallelism-ready module. After that we convert back to
[Float]
and call
consumeSalaries
to replace all salaries in the company tree.

Parallel code

Parallel and non-parallel code cannot be mixed in the same module. Hence, we set up separate modules. In the module for parallel for cut, we declare:

{-# LANGUAGE ParallelArrays #-}
{-# OPTIONS GHC -fvectorise #-}

This tells Technology:GHC to vectorise this module, i.e., to apply data parallelism, and that this module uses parallel arrays. We then define the interface function between vectorised and non-vectorised code

cutV
:

cutV :: PArray Float -> PArray Float
{-# NOINLINE cutV #-}
cutV v = toPArrayP (cutVP (fromPArrayP v))

This function converts from

PArray Float
to a parallel array
[:Float:]
, calls the parallel code and converts back to
PArray Float
. A parallel array can only be used in a vectorised module, so only here can we convert to it. Marking this function
{-# NOINLINE cutV #-}
makes it usable in non-vectorised modules.
cutP
calls the actual data parallel function
cutVP
, which uses a parallel map function to cut all list values:

cutVP :: [:Float:] -> [:Float:]
cutVP = mapP (/2)

Architecture

The module in this!!SalaryFlattener.hs contains functionality to flatten a company and to replace all salaries. this!!Total.hs and this!!Cut.hs host the code for converting between

[Float]
and
PArray Float
and calling data parallel functions for totaling and cutting salaries, which can be found in this!!TotalV.hs and this!!CutV.hs. The algebraic datatype for companies can be found in this!!Company.hs. this!!SampleCompany.hs holds a sample company. this!!Main.hs collects test scenarios for totaling and cutting.

Usage

Tested with GHC/GHCi version 7.2.1.

  • All sources have to be compiled using the GHC-options
    Invalid Language supplied
    .
  • this!!Main.hs has to be loaded into GHCi.
  • The
    main
function has to be applied.
  • The output should be equal to the content of the file this!!baseline.
One can also use the this!!Makefile with a target test for test automation.


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.