Opened 9 years ago

Closed 9 years ago

#3659 closed feature request (worksforme)

two-dimensional PArrays in data parallel code

Reported by: ams Owned by: rl
Priority: normal Milestone:
Component: Compiler Version: 6.10.4
Keywords: Cc: rl@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Hi -- Is it possible to create two-dimensional PArrays? It seems like an expression like

   fromList [fromList [1]]

would do it (where fromList is from Data.Array.Parallel.Prelude), but a type class constraint seems not to be matched here:

    No instance for (Elt (PArray Int))
      arising from a use of `fromList' at Main.hs:8:16-42
    Possible fix: add an instance declaration for (Elt (PArray Int))

(Details below.) Are there any other ways?

Thanks -- Adam Shaw

$ cat Main.hs
import Data.Array.Parallel.PArray as P

main :: IO ()
  = do
      let v2D = P.fromList [P.fromList [1::Int]]
      print v2D

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.13.20090929

$ ghc -fdph-seq Main.hs

    No instance for (Elt (PArray Int))
      arising from a use of `fromList' at Main.hs:6:16-47
    Possible fix: add an instance declaration for (Elt (PArray Int))
    In the expression: fromList [fromList [1 :: Int]]
    In the definition of `v2D': v2D = fromList [fromList [1 :: Int]]
    In the expression:
        do { let v2D = fromList ...;
             print v2D }

Change History (3)

comment:1 Changed 9 years ago by chak

Cc: rl@… added

The function fromList doesn't currently work on lists of parallel arrays. It arguably should, though.

From what you are writing, I am not sure whether you want to work explicitly with PArrays or whether you want to work with [:t:] types. In the former case, you can use nestUSegdPA to construct a nested array. In the latter case, you currently probably have to use a combination of singletonP and (+:+) to first create singleton nested arrays from all your subarrays and then concatenate them.

I notice that you are calling the nested array a two-dimensional array. If your aim is to have subarrays of the same size and to operate in a regular manner on the nested array (e.g., implementing dense matrix operations), you will probably find that the performance isn't great and the code is a bit awkward. The reason is that the current system is biased towards nested, irregular arrays. We are currently working on complementing the existing API with explicit support for regular, multi-dimensional arrays to address this issue.

comment:2 Changed 9 years ago by rl

Owner: set to rl

comment:3 Changed 9 years ago by rl

Resolution: worksforme
Status: newclosed

In the HEAD, fromList hast this type:

fromList :: PA a => [a] -> PArray a

That said, the type PArray is internal to DPH and in theory shouldn't be used outside of the library. You have to use it at the moment when interfacing non-vectorised with vectorised code but I'm in the process of fixing that. Once I'm done, you'll be able to use [:a:] everywhere and DPH won't expose module outside of the (temporary) Data.Array.Parallel.Prelude hierarchy.

Note: See TracTickets for help on using tickets.