Contribution:
dph
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]
PArray a
[Float]
PArray Float
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
cutV
[Float]
consumeSalaries
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
[:Float:]
PArray Float
{-# NOINLINE cutV #-}
cutP
cutVP
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]
PArray Float
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 function has to be applied.
main
- The output should be equal to the content of the file this!!baseline.
There are no revisions for this page.
User contributions
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.