Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nofib
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
9
Issues
9
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
nofib
Commits
6faf843b
Commit
6faf843b
authored
Jan 16, 2012
by
dterei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixup repa laplace & mmult
parent
48138082
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
271 additions
and
144 deletions
+271
-144
fibon/Repa/Laplace/Main.hs
fibon/Repa/Laplace/Main.hs
+53
-35
fibon/Repa/Laplace/Makefile
fibon/Repa/Laplace/Makefile
+64
-24
fibon/Repa/Laplace/SolverGet.hs
fibon/Repa/Laplace/SolverGet.hs
+28
-36
fibon/Repa/Laplace/SolverStencil.hs
fibon/Repa/Laplace/SolverStencil.hs
+51
-0
fibon/Repa/Laplace/laplace.expected.bmp
fibon/Repa/Laplace/laplace.expected.bmp
+0
-0
fibon/Repa/MMult/MMult.stdout
fibon/Repa/MMult/MMult.stdout
+1
-1
fibon/Repa/MMult/Main.hs
fibon/Repa/MMult/Main.hs
+12
-36
fibon/Repa/MMult/Makefile
fibon/Repa/MMult/Makefile
+62
-12
No files found.
fibon/Repa/Laplace/
src/Laplace/src/
Main.hs
→
fibon/Repa/Laplace/Main.hs
View file @
6faf843b
...
...
@@ -4,7 +4,8 @@
-- You supply a BMP files specifying the boundary conditions.
-- The output is written back to another BMP file.
--
import
Solver
import
SolverGet
as
SG
import
SolverStencil
as
SS
import
Data.Array.Repa
as
A
import
Data.Array.Repa.IO.BMP
import
Data.Array.Repa.IO.ColorRamp
...
...
@@ -12,13 +13,27 @@ import Data.Array.Repa.IO.Timing
import
System.Environment
import
Data.Word
import
Control.Monad
import
Prelude
as
P
type
Solver
=
Int
-- ^ Number of iterations to use.
->
Array
DIM2
Double
-- ^ Boundary value mask.
->
Array
DIM2
Double
-- ^ Boundary values.
->
Array
DIM2
Double
-- ^ Initial state.
->
Array
DIM2
Double
solvers
=
[
(
"get"
,
SG
.
solveLaplace
)
,
(
"stencil"
,
SS
.
solveLaplace
)
]
main
::
IO
()
main
=
do
args
<-
getArgs
case
args
of
[
steps
,
fileInput
,
fileOutput
]
->
laplace
(
read
steps
)
fileInput
fileOutput
[
strSolver
,
steps
,
fileInput
,
fileOutput
]
->
let
Just
solver
=
lookup
strSolver
solvers
in
laplace
solver
(
read
steps
)
fileInput
fileOutput
_
->
do
putStr
usage
...
...
@@ -28,12 +43,14 @@ main
-- | Command line usage information.
usage
::
String
usage
=
unlines
[
"Usage: laplace <iterations> <input.bmp> <output.bmp>"
[
"Usage: laplace <
solver> <
iterations> <input.bmp> <output.bmp>"
,
""
,
" iterations :: Int Number of iterations to use in the solver."
,
" input.bmp :: FileName Uncompressed RGB24 or RGBA32 BMP file for initial and boundary values."
,
" output.bmp :: FileName BMP file to write output to."
,
""
,
" solver = one of "
P
.++
show
(
P
.
map
fst
solvers
)
,
""
,
" Format of input file:"
,
" Boundary values are indicated in greyscale,"
,
" ie from the list [(x, x, x) | x <- [0 .. 255]]"
...
...
@@ -41,45 +58,41 @@ usage = unlines
,
" ie (0, 0, 255)"
,
" Any other pixel value is an error."
,
""
]
,
" NOTE: For GHC 7.0.3, this runs better when you turn off the parallel"
,
" garbage collector. Run with +RTS -qg"
,
""
]
-- | Solve it.
laplace
::
Int
-- ^ Number of iterations to use.
laplace
::
Solver
->
Int
-- ^ Number of iterations to use.
->
FilePath
-- ^ Input file.
->
FilePath
-- ^ Output file
->
IO
()
laplace
steps
fileInput
fileOutput
laplace
s
olve
s
teps
fileInput
fileOutput
=
do
-- Load up the file containing boundary conditions.
arrImage
<-
liftM
(
either
(
error
.
show
)
id
)
arrImage
<-
liftM
(
either
(
error
.
show
)
force
)
$
readImageFromBMP
fileInput
arrImage
`
deepSeqArray
`
return
()
let
arrBoundValue
=
force
$
slurpDoublesFromImage
slurpBoundValue
arrImage
let
arrBoundMask
=
force
$
slurpDoublesFromImage
slurpBoundMask
arrImage
-- Use the boundary condition values as the initial matrix.
let
arrInitial
=
arrBoundValue
arrBoundValue
`
deepSeqArray
`
arrBoundMask
`
deepSeqArray
`
arrInitial
`
deepSeqArray
`
return
()
arrBoundValue
`
deepSeqArray
`
return
()
arrBoundMask
`
deepSeqArray
`
return
()
let
arrInitial
=
arrBoundValue
-- Run the solver.
(
arrFinal
,
t
)
(
arrFinal
,
_
)
<-
time
$
let
arrFinal
=
solveLaplace
steps
arrBoundMask
arrBoundValue
arrInitial
in
arrFinal
`
deepSeqArray
`
return
arrFinal
$
let
arrFinal
=
solve
steps
arrBoundMask
arrBoundValue
arrInitial
in
arrFinal
`
deepSeqArray
`
return
arrFinal
-- Print how long it took
-- putStr (prettyTime t)
putStrLn
"Done"
putStrLn
"Done"
-- Make the result image
let
arrImageOut
...
...
@@ -98,8 +111,10 @@ slurpDoublesFromImage
->
Array
DIM2
Double
{-# INLINE slurpDoublesFromImage #-}
slurpDoublesFromImage
mkDouble
arrBound
=
traverse
arrBound
slurpDoublesFromImage
mkDouble
arrBound
@
(
Array
_
[
Region
_
(
GenManifest
_
)])
=
arrBound
`
deepSeqArray
`
force
$
unsafeTraverse
arrBound
(
\
(
Z
:.
height
:.
width
:.
_
)
->
Z
:.
height
:.
width
)
...
...
@@ -116,20 +131,23 @@ makeImageFromDoubles
->
Array
DIM3
Word8
{-# INLINE makeImageFromDoubles #-}
makeImageFromDoubles
fnColor
arrDoubles
=
traverse
arrDoubles
makeImageFromDoubles
fnColor
arrDoubles
@
(
Array
_
[
Region
_
(
GenManifest
_
)])
=
arrDoubles
`
deepSeqArray
`
force
$
unsafeTraverse
arrDoubles
(
\
(
Z
:.
height
:.
width
)
->
Z
:.
height
:.
width
:.
4
)
(
\
get
(
Z
:.
y
:.
x
:.
c
)
->
let
(
r
,
g
,
b
)
=
fnColor
(
get
(
Z
:.
y
:.
x
))
in
case
c
of
0
->
truncate
(
r
*
255
)
1
->
truncate
(
g
*
255
)
2
->
truncate
(
b
*
255
)
0
->
fromIntegral
$
(
truncate
(
r
*
255
)
::
Int
)
1
->
fromIntegral
$
(
truncate
(
g
*
255
)
::
Int
)
2
->
fromIntegral
$
(
truncate
(
b
*
255
)
::
Int
)
3
->
0
)
-- | Extract the boundary value from a RGB triple.
slurpBoundValue
::
Word8
->
Word8
->
Word8
->
Double
{-# INLINE slurpBoundValue #-}
...
...
@@ -140,10 +158,10 @@ slurpBoundValue r g b
-- A boundary value.
|
(
r
==
g
)
&&
(
r
==
b
)
=
fromIntegral
r
/
255
=
fromIntegral
(
fromIntegral
r
::
Int
)
/
255
|
otherwise
=
error
$
"Unhandled pixel value in input "
++
show
(
r
,
g
,
b
)
=
error
$
"Unhandled pixel value in input "
P
.
++
show
(
r
,
g
,
b
)
-- | Extract boundary mask from a RGB triple.
...
...
@@ -159,6 +177,6 @@ slurpBoundMask r g b
=
0
|
otherwise
=
error
$
"Unhandled pixel value in input "
++
show
(
r
,
g
,
b
)
=
error
$
"Unhandled pixel value in input "
P
.
++
show
(
r
,
g
,
b
)
fibon/Repa/Laplace/Makefile
View file @
6faf843b
TOP
=
../../..
include
$(TOP)/mk/boilerplate.mk
SRCS
=
../_RepaLib/quickcheck/Test/QuickCheck/Exception.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Text.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/State.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Gen.hs
\
SRCS
=
../_RepaLib/bmp/Codec/BMP/Base.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfo.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfoV3.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfoV4.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfoV5.hs
\
../_RepaLib/bmp/Codec/BMP/CIEXYZ.hs
\
../_RepaLib/bmp/Codec/BMP/Compression.hs
\
../_RepaLib/bmp/Codec/BMP/Error.hs
\
../_RepaLib/bmp/Codec/BMP/FileHeader.hs
\
../_RepaLib/bmp/Codec/BMP.hs
\
../_RepaLib/bmp/Codec/BMP/Pack.hs
\
../_RepaLib/bmp/Codec/BMP/Unpack.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/All.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Arbitrary.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Exception.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Function.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Gen.hs
\
../_RepaLib/quickcheck/Test/QuickCheck.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Modifiers.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Monadic.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Poly.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Property.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/State.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Test.hs
\
../_RepaLib/quickcheck/Test/QuickCheck.hs
\
../_RepaLib/repa/Data/Array/Repa/QuickCheck.hs
\
../_RepaLib/repa/Data/Array/Repa/Shape.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Text.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Complex.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Convolve.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/DFT/Center.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/DFT.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/DFT/Roots.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/FFT.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Iterate.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Matrix.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Randomish.hs
\
../_RepaLib/repa-bytestring/Data/Array/Repa/ByteString.hs
\
../_RepaLib/repa/Data/Array/Repa/Arbitrary.hs
\
../_RepaLib/repa/Data/Array/Repa.hs
\
../_RepaLib/repa/Data/Array/Repa/Index.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Base.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Elt.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/EvalBlockwise.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/EvalChunked.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/EvalCursored.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/EvalReduction.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Forcing.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Gang.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Select.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/IndexSpace.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Interleave.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Mapping.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Modify.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Reduction.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Select.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Traverse.hs
\
../_RepaLib/repa/Data/Array/Repa/Properties.hs
\
../_RepaLib/repa/Data/Array/Repa/Shape.hs
\
../_RepaLib/repa/Data/Array/Repa/Slice.hs
\
../_RepaLib/bmp/Codec/BMP/CIEXYZ.hs
\
../_RepaLib/bmp/Codec/BMP/Error.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfoV3.hs
\
../_RepaLib/bmp/Codec/BMP/FileHeader.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfoV4.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfoV5.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfo.hs
\
../_RepaLib/bmp/Codec/BMP/Base.hs
\
../_RepaLib/bmp/Codec/BMP/Unpack.hs
\
../_RepaLib/bmp/Codec/BMP/Pack.hs
\
../_RepaLib/bmp/Codec/BMP.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Timing.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/ColorRamp.hs
\
../_RepaLib/repa/Data/Array/Repa.hs
\
../_RepaLib/repa-bytestring/Data/Array/Repa/ByteString.hs
\
../_RepaLib/repa/Data/Array/Repa/Specialised/Dim2.hs
\
../_RepaLib/repa/Data/Array/Repa/Stencil/Base.hs
\
../_RepaLib/repa/Data/Array/Repa/Stencil.hs
\
../_RepaLib/repa/Data/Array/Repa/Stencil/Template.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Binary.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/BMP.hs
\
src/Laplace/src/Solver.hs
\
src/Laplace/src/Main.hs
../_RepaLib/repa-io/Data/Array/Repa/IO/ColorRamp.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Internals/Text.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Matrix.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Timing.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Vector.hs
\
SolverGet.hs
\
SolverStencil.hs
\
Main.hs
PROG_ARGS
+=
1000 pls-400x400.bmp laplace.bmp
HC_OPTS
+=
-threaded
-i
.
-i
../_RepaLib/repa
-i
../_RepaLib/repa-algorithms
-i
../_RepaLib/repa-io
-i
../_RepaLib/bmp
-i
../_RepaLib/repa-bytestring
-i
../_RepaLib/quickcheck
-isrc
/Laplace/src
-package
base
-package
binary
-package
bytestring
-package
dph-base
-package
dph-prim-par
-package
dph-prim-seq
-package
extensible-exceptions
-package
ghc
-package
mtl
-package
old-time
-package
random
CLEAN_FILES
+=
laplace.bmp
...
...
fibon/Repa/Laplace/
src/Laplace/src/Solver
.hs
→
fibon/Repa/Laplace/
SolverGet
.hs
View file @
6faf843b
{-# LANGUAGE BangPatterns
, PackageImports
#-}
module
Solver
{-# LANGUAGE BangPatterns #-}
module
Solver
Get
(
solveLaplace
)
where
import
Data.Array.Repa
as
A
import
qualified
Data.Array.Repa.Shape
as
S
import
"dph-prim-par"
Data.Array.Parallel.Unlifted
(
Elt
)
import
qualified
"dph-prim-par"
Data.Array.Parallel.Unlifted
as
U
-- | Solver for the Laplace equation.
solveLaplace
...
...
@@ -17,14 +14,13 @@ solveLaplace
->
Array
DIM2
Double
{-# NOINLINE solveLaplace #-}
solveLaplace
steps
arrBoundMask
@
Manifest
{}
arrBoundValue
@
Manifest
{}
arrInit
@
Manifest
{}
solveLaplace
steps
arrBoundMask
arrBoundValue
arrInit
=
go
steps
arrInit
where
go
i
arr
@
Manifest
{}
where
go
!
i
!
arr
|
i
==
0
=
arr
|
otherwise
=
go
(
i
-
1
)
$
force
$
applyBoundary
arrBoundMask
arrBoundValue
$
relaxLaplace
arr
|
otherwise
=
let
arr'
=
relaxLaplace
arrBoundMask
arrBoundValue
arr
in
arr'
`
deepSeqArray
`
go
(
i
-
1
)
arr'
-- | Perform matrix relaxation for the Laplace equation,
...
...
@@ -33,19 +29,34 @@ solveLaplace steps arrBoundMask@Manifest{} arrBoundValue@Manifest{} arrInit@Mani
-- Computation fn is
-- u'(i,j) = (u(i-1,j) + u(i+1,j) + u(i,j-1) + u(i,j+1)) / 4
--
-- Apply the boundary conditions to this matrix.
-- The mask matrix has 0 in places where boundary conditions hold
-- and 1 otherwise.
--
-- The value matrix has the boundary condition value in places where it holds,
-- and 0 otherwise.
--
relaxLaplace
::
Array
DIM2
Double
->
Array
DIM2
Double
::
Array
DIM2
Double
-- ^ Boundary condition mask
->
Array
DIM2
Double
-- ^ Boundary condition values
->
Array
DIM2
Double
-- ^ Initial matrix
->
Array
DIM2
Double
{-# INLINE relaxLaplace #-}
relaxLaplace
!
arr
@
Manifest
{}
=
traverse
arr
id
elemFn
relaxLaplace
arrBoundMask
@
(
Array
_
[
Region
RangeAll
(
GenManifest
_
)])
arrBoundValue
@
(
Array
_
[
Region
RangeAll
(
GenManifest
_
)])
arr
@
(
Array
_
[
Region
RangeAll
(
GenManifest
_
)])
=
[
arrBoundMask
,
arrBoundValue
,
arr
]
`
deepSeqArrays
`
force
$
A
.
zipWith
(
+
)
arrBoundValue
$
A
.
zipWith
(
*
)
arrBoundMask
$
unsafeTraverse
arr
id
elemFn
where
_
:.
height
:.
width
=
extent
arr
{-# INLINE elemFn #-}
elemFn
get
d
@
(
sh
:.
i
:.
j
)
elemFn
!
get
!
d
@
(
sh
:.
i
:.
j
)
=
if
isBorder
i
j
then
get
d
else
(
get
(
sh
:.
(
i
-
1
)
:.
j
)
...
...
@@ -56,27 +67,8 @@ relaxLaplace !arr@Manifest{}
-- Check if this element is on the border of the matrix.
-- If so we can't apply the stencil because we don't have all the neighbours.
{-# INLINE isBorder #-}
isBorder
i
j
isBorder
!
i
!
j
=
(
i
==
0
)
||
(
i
>=
width
-
1
)
||
(
j
==
0
)
||
(
j
>=
height
-
1
)
-- | Apply the boundary conditions to this matrix.
-- The mask matrix has 0 in places where boundary conditions hold
-- and 1 otherwise.
--
-- The value matrix has the boundary condition value in places where it holds,
-- and 0 otherwise.
--
applyBoundary
::
Array
DIM2
Double
-- ^ Boundary condition mask.
->
Array
DIM2
Double
-- ^ Boundary condition values.
->
Array
DIM2
Double
-- ^ Initial matrix.
->
Array
DIM2
Double
-- ^ Matrix with boundary conditions applied.
{-# INLINE applyBoundary #-}
applyBoundary
arrBoundMask
arrBoundValue
arr
=
A
.
zipWith
(
+
)
arrBoundValue
$
A
.
zipWith
(
*
)
arrBoundMask
arr
fibon/Repa/Laplace/SolverStencil.hs
0 → 100644
View file @
6faf843b
{-# LANGUAGE BangPatterns, TemplateHaskell, QuasiQuotes #-}
module
SolverStencil
(
solveLaplace
)
where
import
Data.Array.Repa
as
A
import
Data.Array.Repa.Stencil
as
A
import
Data.Array.Repa.Algorithms.Iterate
as
A
import
qualified
Data.Array.Repa.Shape
as
S
import
Language.Haskell.TH
import
Language.Haskell.TH.Quote
-- | Solver for the Laplace equation.
solveLaplace
::
Int
-- ^ Number of iterations to use.
->
Array
DIM2
Double
-- ^ Boundary value mask.
->
Array
DIM2
Double
-- ^ Boundary values.
->
Array
DIM2
Double
-- ^ Initial state.
->
Array
DIM2
Double
{-# NOINLINE solveLaplace #-}
solveLaplace
!
steps
!
arrBoundMask
!
arrBoundValue
!
arrInit
=
go
steps
arrInit
where
go
0
!
arr
=
arr
go
n
!
arr
=
go
(
n
-
1
)
(
relaxLaplace
arrBoundMask
arrBoundValue
arr
)
{-# INLINE relaxLaplace #-}
relaxLaplace
::
Array
DIM2
Double
-- ^ Boundary value mask.
->
Array
DIM2
Double
-- ^ Boundary values.
->
Array
DIM2
Double
-- ^ Initial state.
->
Array
DIM2
Double
relaxLaplace
arrBoundMask
@
(
Array
_
[
Region
RangeAll
(
GenManifest
_
)])
arrBoundValue
@
(
Array
_
[
Region
RangeAll
(
GenManifest
_
)])
arr
@
(
Array
_
[
Region
RangeAll
(
GenManifest
_
)])
=
[
arrBoundMask
,
arrBoundValue
,
arr
]
`
deepSeqArrays
`
let
ex
=
extent
arr
arrBoundMask'
=
reshape
ex
arrBoundMask
arrBoundValue'
=
reshape
ex
arrBoundValue
arr'
=
reshape
ex
arr
in
force
$
A
.
zipWith
(
+
)
arrBoundValue'
$
A
.
zipWith
(
*
)
arrBoundMask'
$
A
.
map
(
/
4
)
$
mapStencil2
BoundClamp
[
stencil2
|
0 1 0
1 0 1
0 1 0
|]
arr'
\ No newline at end of file
fibon/Repa/Laplace/laplace.expected.bmp
deleted
100644 → 0
View file @
48138082
469 KB
fibon/Repa/MMult/MMult.stdout
View file @
6faf843b
checkSum = 3.8416e9
Done
fibon/Repa/MMult/
src/MMult/src/
Main.hs
→
fibon/Repa/MMult/Main.hs
View file @
6faf843b
...
...
@@ -4,11 +4,12 @@ import Data.Array.Repa as A
import
Data.Array.Repa.IO.Matrix
import
Data.Array.Repa.IO.Timing
import
Data.Array.Repa.Algorithms.Matrix
import
Data.Array.Repa.Algorithms.Randomish
import
Data.Maybe
import
System.Environment
import
Control.Monad
import
System.Random
import
qualified
"dph-prim-par"
Data.Array.Parallel.Unlifted
as
U
import
Prelude
as
P
-- Arg Parsing ------------------------------------------------------------------------------------
data
Arg
...
...
@@ -39,7 +40,7 @@ parseArgs (flag:xx)
=
ArgMatrixRandom
(
read
x
)
(
read
y
)
:
parseArgs
rest
|
otherwise
=
error
$
"bad arg "
++
flag
++
"
\n
"
=
error
$
"bad arg "
P
.++
flag
P
.
++
"
\n
"
printHelp
=
putStr
...
...
@@ -65,33 +66,9 @@ getMatrix arg
->
readMatrixFromTextFile
fileName
ArgMatrixRandom
height
width
->
genRandomMatrix
(
Z
:.
height
:.
width
)
-- Random -----------------------------------------------------------------------------------------
-- | Generate a random(ish) matrix.
genRandomMatrix
::
DIM2
->
IO
(
Array
DIM2
Double
)
genRandomMatrix
sh
=
do
uarr
<-
genRandomUArray
(
A
.
size
sh
)
return
$
fromUArray
sh
uarr
-- | Generate a random(ish) UArray of doubles.
-- The std random function is too slow to generate really big vectors
-- with. Instead, we generate a short random vector and repeat that.
genRandomUArray
::
Int
->
IO
(
U
.
Array
Double
)
genRandomUArray
n
=
do
let
seed
=
42742
let
k
=
100
let
rg
=
mkStdGen
seed
let
ivec
=
U
.
randomRs
k
(
-
100
,
100
)
rg
::
U
.
Array
Int
let
randvec
=
U
.
map
(
\
i
->
fromIntegral
i
)
ivec
let
vec
=
U
.
map
(
\
i
->
(
randvec
U
.!:
(
i
`
mod
`
k
)))
(
U
.
enumFromTo
0
(
n
-
1
))
return
vec
->
return
$
randomishDoubleArray
(
Z
:.
height
:.
width
)
(
-
100
)
100
12345
-- Main -------------------------------------------------------------------------------------------
main
::
IO
()
main
...
...
@@ -107,21 +84,20 @@ main' args
mat1
<-
getMatrix
argMat1
mat2
<-
getMatrix
argMat2
mat1
`
deepSeqArray
`
mat2
`
deepSeqArray
`
return
()
mat1
`
deepSeqArray
`
mat2
`
deepSeqArray
`
return
()
-- Run the solver.
(
matResult
,
t
)
(
matResult
,
_
)
<-
time
$
let
matResult
=
multiplyMM
mat1
mat2
$
let
matResult
=
multiplyMM
mat1
mat2
in
matResult
`
deepSeqArray
`
return
matResult
-- Print how long it took.
--putStr (prettyTime t)
--
putStr (prettyTime t)
-- Print a checksum of all the elements
putStrLn
$
"checkSum = "
++
show
(
A
.
sumAll
matResult
)
-- putStrLn $ "checkSum = " P.++ show (A.sumAll matResult)
putStrLn
$
matResult
`
seq
`
"Done"
-- Write the output to file if requested.
case
mArgOut
of
...
...
fibon/Repa/MMult/Makefile
View file @
6faf843b
TOP
=
../../..
include
$(TOP)/mk/boilerplate.mk
SRCS
=
../_RepaLib/repa-io/Data/Array/Repa/IO/Internals/Text.hs
\
SRCS
=
../_RepaLib/bmp/Codec/BMP/Base.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfo.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfoV3.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfoV4.hs
\
../_RepaLib/bmp/Codec/BMP/BitmapInfoV5.hs
\
../_RepaLib/bmp/Codec/BMP/CIEXYZ.hs
\
../_RepaLib/bmp/Codec/BMP/Compression.hs
\
../_RepaLib/bmp/Codec/BMP/Error.hs
\
../_RepaLib/bmp/Codec/BMP/FileHeader.hs
\
../_RepaLib/bmp/Codec/BMP.hs
\
../_RepaLib/bmp/Codec/BMP/Pack.hs
\
../_RepaLib/bmp/Codec/BMP/Unpack.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/All.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Arbitrary.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Exception.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Text.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/State.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Function.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Gen.hs
\
../_RepaLib/quickcheck/Test/QuickCheck
/Arbitrary
.hs
\
../_RepaLib/quickcheck/Test/QuickCheck.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Modifiers.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Monadic.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Poly.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Property.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/State.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Test.hs
\
../_RepaLib/quickcheck/Test/QuickCheck.hs
\
../_RepaLib/repa/Data/Array/Repa/QuickCheck.hs
\
../_RepaLib/repa/Data/Array/Repa/Shape.hs
\
../_RepaLib/quickcheck/Test/QuickCheck/Text.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Complex.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Convolve.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/DFT/Center.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/DFT.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/DFT/Roots.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/FFT.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Iterate.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Matrix.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Randomish.hs
\
../_RepaLib/repa-bytestring/Data/Array/Repa/ByteString.hs
\
../_RepaLib/repa/Data/Array/Repa/Arbitrary.hs
\
../_RepaLib/repa/Data/Array/Repa.hs
\
../_RepaLib/repa/Data/Array/Repa/Index.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Base.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Elt.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/EvalBlockwise.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/EvalChunked.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/EvalCursored.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/EvalReduction.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Forcing.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Gang.hs
\
../_RepaLib/repa/Data/Array/Repa/Internals/Select.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/IndexSpace.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Interleave.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Mapping.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Modify.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Reduction.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Select.hs
\
../_RepaLib/repa/Data/Array/Repa/Operators/Traverse.hs
\
../_RepaLib/repa/Data/Array/Repa/Properties.hs
\
../_RepaLib/repa/Data/Array/Repa/Shape.hs
\
../_RepaLib/repa/Data/Array/Repa/Slice.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Timing.hs
\
../_RepaLib/repa/Data/Array/Repa.hs
\
../_RepaLib/repa/Data/Array/Repa/Specialised/Dim2.hs
\
../_RepaLib/repa/Data/Array/Repa/Stencil/Base.hs
\
../_RepaLib/repa/Data/Array/Repa/Stencil.hs
\
../_RepaLib/repa/Data/Array/Repa/Stencil/Template.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Binary.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/BMP.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/ColorRamp.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Internals/Text.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Matrix.hs
\
../_RepaLib/repa-algorithms/Data/Array/Repa/Algorithms/Matrix.hs
\
src/MMult/src/Main.hs
PROG_ARGS
+=
-random
1000 1000
-random
1000 1000
../_RepaLib/repa-io/Data/Array/Repa/IO/Timing.hs
\
../_RepaLib/repa-io/Data/Array/Repa/IO/Vector.hs
\
Main.hs
PROG_ARGS
+=
-random
600 600
-random
600 600
HC_OPTS
+=
-threaded
-i
.
-i
../_RepaLib/repa
-i
../_RepaLib/repa-algorithms
-i
../_RepaLib/repa-io
-i
../_RepaLib/bmp
-i
../_RepaLib/repa-bytestring
-i
../_RepaLib/quickcheck
-package
base
-package
binary
-package
bytestring
-package
dph-base
-package
dph-prim-par
-package
dph-prim-seq
-package
extensible-exceptions
-package
ghc
-package
mtl
-package
old-time
-package
random
include
$(TOP)/mk/target.mk
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment