Migrated functions to Acc-Monad

This commit is contained in:
Nicole Dresselhaus 2013-11-26 17:55:02 +01:00
parent 826297e4c0
commit 67cd8059f0
7 changed files with 53 additions and 49 deletions

View File

@ -7,8 +7,6 @@ module Paths_hgraph (
import qualified Control.Exception as Exception import qualified Control.Exception as Exception
import Data.Version (Version(..)) import Data.Version (Version(..))
import System.Environment (getEnv) import System.Environment (getEnv)
import Prelude
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
catchIO = Exception.catch catchIO = Exception.catch
@ -17,10 +15,10 @@ version :: Version
version = Version {versionBranch = [0,0,1], versionTags = []} version = Version {versionBranch = [0,0,1], versionTags = []}
bindir, libdir, datadir, libexecdir :: FilePath bindir, libdir, datadir, libexecdir :: FilePath
bindir = "/home/sdressel/.cabal/bin" bindir = "/homes/sdressel/.cabal/bin"
libdir = "/home/sdressel/.cabal/lib/hgraph-0.0.1/ghc-7.6.3" libdir = "/homes/sdressel/.cabal/lib/hgraph-0.0.1/ghc-7.4.1"
datadir = "/home/sdressel/.cabal/share/hgraph-0.0.1" datadir = "/homes/sdressel/.cabal/share/hgraph-0.0.1"
libexecdir = "/home/sdressel/.cabal/libexec" libexecdir = "/homes/sdressel/.cabal/libexec"
getBinDir, getLibDir, getDataDir, getLibexecDir :: IO FilePath getBinDir, getLibDir, getDataDir, getLibexecDir :: IO FilePath
getBinDir = catchIO (getEnv "hgraph_bindir") (\_ -> return bindir) getBinDir = catchIO (getEnv "hgraph_bindir") (\_ -> return bindir)

View File

@ -1,11 +1,11 @@
/* DO NOT EDIT: This file is automatically generated by Cabal */ /* DO NOT EDIT: This file is automatically generated by Cabal */
/* package QuickCheck-2.6 */ /* package QuickCheck-2.4.2 */
#define VERSION_QuickCheck "2.6" #define VERSION_QuickCheck "2.4.2"
#define MIN_VERSION_QuickCheck(major1,major2,minor) (\ #define MIN_VERSION_QuickCheck(major1,major2,minor) (\
(major1) < 2 || \ (major1) < 2 || \
(major1) == 2 && (major2) < 6 || \ (major1) == 2 && (major2) < 4 || \
(major1) == 2 && (major2) == 6 && (minor) <= 0) (major1) == 2 && (major2) == 4 && (minor) <= 2)
/* package Stream-0.4.6.1 */ /* package Stream-0.4.6.1 */
#define VERSION_Stream "0.4.6.1" #define VERSION_Stream "0.4.6.1"
@ -21,33 +21,33 @@
(major1) == 0 && (major2) < 13 || \ (major1) == 0 && (major2) < 13 || \
(major1) == 0 && (major2) == 13 && (minor) <= 0) (major1) == 0 && (major2) == 13 && (minor) <= 0)
/* package base-4.6.0.1 */ /* package base-4.5.0.0 */
#define VERSION_base "4.6.0.1" #define VERSION_base "4.5.0.0"
#define MIN_VERSION_base(major1,major2,minor) (\ #define MIN_VERSION_base(major1,major2,minor) (\
(major1) < 4 || \ (major1) < 4 || \
(major1) == 4 && (major2) < 6 || \ (major1) == 4 && (major2) < 5 || \
(major1) == 4 && (major2) == 6 && (minor) <= 0) (major1) == 4 && (major2) == 5 && (minor) <= 0)
/* package bytestring-0.10.0.2 */ /* package bytestring-0.9.2.1 */
#define VERSION_bytestring "0.10.0.2" #define VERSION_bytestring "0.9.2.1"
#define MIN_VERSION_bytestring(major1,major2,minor) (\ #define MIN_VERSION_bytestring(major1,major2,minor) (\
(major1) < 0 || \ (major1) < 0 || \
(major1) == 0 && (major2) < 10 || \ (major1) == 0 && (major2) < 9 || \
(major1) == 0 && (major2) == 10 && (minor) <= 0) (major1) == 0 && (major2) == 9 && (minor) <= 2)
/* package deepseq-1.3.0.1 */ /* package deepseq-1.3.0.0 */
#define VERSION_deepseq "1.3.0.1" #define VERSION_deepseq "1.3.0.0"
#define MIN_VERSION_deepseq(major1,major2,minor) (\ #define MIN_VERSION_deepseq(major1,major2,minor) (\
(major1) < 1 || \ (major1) < 1 || \
(major1) == 1 && (major2) < 3 || \ (major1) == 1 && (major2) < 3 || \
(major1) == 1 && (major2) == 3 && (minor) <= 0) (major1) == 1 && (major2) == 3 && (minor) <= 0)
/* package ghc-7.6.3 */ /* package ghc-7.4.1 */
#define VERSION_ghc "7.6.3" #define VERSION_ghc "7.4.1"
#define MIN_VERSION_ghc(major1,major2,minor) (\ #define MIN_VERSION_ghc(major1,major2,minor) (\
(major1) < 7 || \ (major1) < 7 || \
(major1) == 7 && (major2) < 6 || \ (major1) == 7 && (major2) < 4 || \
(major1) == 7 && (major2) == 6 && (minor) <= 3) (major1) == 7 && (major2) == 4 && (minor) <= 1)
/* package monad-par-0.3.4.5 */ /* package monad-par-0.3.4.5 */
#define VERSION_monad_par "0.3.4.5" #define VERSION_monad_par "0.3.4.5"
@ -56,17 +56,17 @@
(major1) == 0 && (major2) < 3 || \ (major1) == 0 && (major2) < 3 || \
(major1) == 0 && (major2) == 3 && (minor) <= 4) (major1) == 0 && (major2) == 3 && (minor) <= 4)
/* package parallel-3.2.0.3 */ /* package parallel-3.2.0.2 */
#define VERSION_parallel "3.2.0.3" #define VERSION_parallel "3.2.0.2"
#define MIN_VERSION_parallel(major1,major2,minor) (\ #define MIN_VERSION_parallel(major1,major2,minor) (\
(major1) < 3 || \ (major1) < 3 || \
(major1) == 3 && (major2) < 2 || \ (major1) == 3 && (major2) < 2 || \
(major1) == 3 && (major2) == 2 && (minor) <= 0) (major1) == 3 && (major2) == 2 && (minor) <= 0)
/* package text-0.11.3.1 */ /* package text-0.11.1.13 */
#define VERSION_text "0.11.3.1" #define VERSION_text "0.11.1.13"
#define MIN_VERSION_text(major1,major2,minor) (\ #define MIN_VERSION_text(major1,major2,minor) (\
(major1) < 0 || \ (major1) < 0 || \
(major1) == 0 && (major2) < 11 || \ (major1) == 0 && (major2) < 11 || \
(major1) == 0 && (major2) == 11 && (minor) <= 3) (major1) == 0 && (major2) == 11 && (minor) <= 1)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -20,7 +20,7 @@ module Main (
import Control.Monad (unless) import Control.Monad (unless)
import Control.Parallel.Strategies import Control.Parallel.Strategies
import Control.DeepSeq import Control.DeepSeq
import Data.List import qualified Data.List as L
import System.Exit (exitFailure) import System.Exit (exitFailure)
import System.Environment import System.Environment
import Test.QuickCheck.All (quickCheckAll) import Test.QuickCheck.All (quickCheckAll)
@ -33,43 +33,49 @@ import Debug.Trace
import qualified Data.Text as T import qualified Data.Text as T
import Data.Text.Encoding import Data.Text.Encoding
--import Stream hiding (map) --same as Data.Stream imported above? --import Stream hiding (map) --same as Data.Stream imported above?
import qualified Data.Array.Accelerate as A import Data.Array.Accelerate hiding (not)
-- change to Data.Array.Accelerate.CUDA as I and link accelerate-cuda to use GPU instead of CPU -- change to Data.Array.Accelerate.CUDA as I and link accelerate-cuda to use GPU instead of CPU
-- depends on accelerate-cuda package in cabal, which needs the installed CUDA-stuff form -- depends on accelerate-cuda package in cabal, which needs the installed CUDA-stuff form
-- nVidia (nvcc, header-files, ...) and the propriatary driver -- nVidia (nvcc, header-files, ...) and the propriatary driver
import Data.Array.Accelerate.Interpreter as I import Data.Array.Accelerate.Interpreter as I
type Matrix e = A.Array A.DIM2 e type Matrix e = Array DIM2 e
type Attr = Matrix A.Int8 type Attr = Matrix Int8
-- Adjecency-Matrix -- Adjecency-Matrix
type Adj = Matrix A.Int8 type Adj = Matrix Int8
-- Vector of the Adjecency-Matrix -- Vector of the Adjecency-Matrix
type AdjV = A.Vector A.Int8 type AdjV = Vector Int8
newtype Constraints = Matrix A.Float newtype Constraints = Matrix Float
-- Graph consists of a Vector denoting which colums of the matrix represents wich originating -- Graph consists of a Vector denoting which colums of the matrix represents wich originating
-- column in the global adjencency-matrix, the reduces adjencency-matrix of the graph, a -- column in the global adjencency-matrix, the reduces adjencency-matrix of the graph, a
-- matrix of constraints and a scalar denoting the density -- matrix of constraints and a scalar denoting the density
type Density = A.Scalar A.Float type Density = Scalar Float
type Graph = (A.Vector A.Int8, Adj, Constraints, Density)
-- Graph
type Graph = (Vector Int8, Adj, Constraints, Density)
-- Vector of Graphs
type MultiGraph e = (Vector Int8, Array DIM3 e, Constraints, Density)
expand :: [Graph]-> Adj -> Attr ->[Graph]
expand :: Acc (MultiGraph Int8)-> Acc Adj -> Acc Attr -> Acc (MultiGraph Int8)
expand g a att = undefined expand g a att = undefined
-- constraint gets a Graph and an Attribute-Matrix and yields true, if the Graph still fulfills -- constraint gets a Graph and an Attribute-Matrix and yields true, if the Graph still fulfills
-- all constraints defined via the Attribute-Matrix. -- all constraints defined via the Attribute-Matrix.
constraint :: Graph -> Attr -> Bool constraint :: Acc Graph -> Acc Attr -> Acc (Scalar Bool)
constraint g a = undefined constraint g a = undefined
-- addPoint gets a graph and a tuple of an adjecancy-Vector with an int wich column of the -- addPoint gets a graph and a tuple of an adjecancy-Vector with an int wich column of the
-- Adjacency-Matrix the Vector should represent to generate further Graphs -- Adjacency-Matrix the Vector should represent to generate further Graphs
addPoint :: Graph -> (Adj, Int) -> [Graph] addPoint :: Acc Graph -> Acc (Adj, (Scalar Int)) -> Acc (MultiGraph Int8)
addPoint g (a, n) = undefined addPoint g a = undefined
-- addablePoints yields all valid addititonsto a Graph -- addablePoints yields all valid addititonsto a Graph
addablePoints :: Adj -> Graph-> [(Adj, Int)] addablePoints :: Acc Adj -> Acc Graph-> Acc (Vector Int8)
addablePoints a g = undefined addablePoints a g = undefined
@ -110,11 +116,11 @@ createOutput :: [[Int]] -> B.ByteString
createOutput a = encodeUtf8 (createOutput' a) createOutput a = encodeUtf8 (createOutput' a)
createOutput' :: [[Int]] -> T.Text createOutput' :: [[Int]] -> T.Text
createOutput' [a] = T.intercalate (T.singleton ',') (map (T.pack . show) a) createOutput' [a] = T.intercalate (T.singleton ',') (L.map (T.pack . show) a)
createOutput' (a:as) = T.append createOutput' (a:as) = T.append
(T.append (T.append
(T.intercalate (T.singleton ',') (T.intercalate (T.singleton ',')
(map (T.pack . show) a)) (L.map (T.pack . show) a))
(T.singleton '\n')) (T.singleton '\n'))
(createOutput' as) (createOutput' as)
@ -135,18 +141,18 @@ exeMain = do
[adj, attr] -> Prelude.mapM B.readFile [adj, attr] [adj, attr] -> Prelude.mapM B.readFile [adj, attr]
_ -> error "Wrong arguments given" _ -> error "Wrong arguments given"
-- read file and clean -- read file and clean
adjMat <- return $ filter (not . emptyLine) (T.lines (decodeUtf8 (head input))) adjMat <- return $ L.filter (not . emptyLine) (T.lines (decodeUtf8 (head input)))
attrMat <- return $ filter (not . emptyLine) (T.lines (decodeUtf8 ((head . tail) input))) attrMat <- return $ L.filter (not . emptyLine) (T.lines (decodeUtf8 ((head . L.tail) input)))
inputLines <- return $ length adjMat inputLines <- return $ length adjMat
-- TODO: concat with foldl1' kills us later -> use presized/preallocated array so we -- TODO: concat with foldl1' kills us later -> use presized/preallocated array so we
-- dont copy that much lateron. Best would be Matrix Int -- dont copy that much lateron. Best would be Matrix Int
-- unrefined_graph::[Either [Int] String] - [Int] is Adjacency-Line, String is parse-Error -- unrefined_graph::[Either [Int] String] - [Int] is Adjacency-Line, String is parse-Error
unrefined_graph <- return $ (map (traceEvent "mapping" . createGraph) adjMat) unrefined_graph <- return $ (L.map (traceEvent "mapping" . createGraph) adjMat)
+|| (parBuffer 100 rdeepseq) --run parallel, evaluate fully +|| (parBuffer 100 rdeepseq) --run parallel, evaluate fully
--egraph <- return $ graphFolder unrefined_graph --egraph <- return $ graphFolder unrefined_graph
(graph, log, lines) <- return $ ((foldl1' ((traceEvent "concatenating graph") . (++)) (lefts unrefined_graph), -- concatenated graph (graph, log, lines) <- return $ ((L.foldl1' ((traceEvent "concatenating graph") . (++)) (lefts unrefined_graph), -- concatenated graph
traceEvent "concatenating log" T.intercalate (T.singleton '\n') (rights unrefined_graph), -- concat error-log traceEvent "concatenating log" T.intercalate (T.singleton '\n') (rights unrefined_graph), -- concat error-log
traceEvent "getting length" length unrefined_graph) -- number of elements in graph traceEvent "getting length" length unrefined_graph) -- number of elements in graph
-- in parallel -- in parallel