I've been doing a lot of research into Data Parallel Haskell, and found two seperate parallel array types. The [::]
type seems to show up more in the research papers and seems to be the ideal type, but PArray
seems to be stuck in everywhere. The wiki page on the subject makes it very clear that arrays of type [::]
cannot be passed to unvectorized code. Why? Why is there this intermediate PArray
type? It seems completely superfluous to me. The wiki calls it a "flat array," but the whole point of vectorization is to make parallel arrays flat.
Update: After reading more papers and documentation and source code I am even more confused. [::]
or its synonym PArr
seem to be implemented in GHC.PArr as a flat array, while PArray
, the intermediate type that is called "flat" in multiple places, is implemented in Data.Array.Parallel.PArray.Base and other modules imported from there as a data family, using the flattening transformation described in so many of the papers I read. Why are the flat arrays not flat and the nested ones flat?
Update 2: After more research, I have found that the docementation is a complete mess. The wiki page hasn't had any content updates in nearly a year, contradicts the hackage documentation (see Data.Array.Parallel.Prelude, where it explicitly says not to import the special prelude), and is just generally outdated. The GHC Trac page also is out of date, including, for example, a guide to the DPH packages that mentions packages that, at least as far as Hackage is concerned (I haven't, and don't quite no where to look in other places), don't exist, and doesn't mention packages like dph-lifted-vseg.
On a better note, I believe I now understand the answer to the first update, hinted at by this portion of the comments in GHC.PArr:
-- BIG UGLY HACK: The desugarer special cases this module. Despite the uses of '-XParallelArrays',
-- the desugarer does not load 'Data.Array.Parallel' into its global state. (Hence,
-- the present module may not use any other piece of '-XParallelArray' syntax.)
--
-- This will be cleaned up when we change the internal represention of '[::]' to not
-- rely on a wired-in type constructor.
It is my guess that, when vectorization is enabled, that module is automatically replaced with another representation that uses the flattening transformation. This might even be something like
type [::] = PArray
, solving my original problem. However, not only does the latter point not make much sense (why restrict [::]
to a flat array type when vectorization is off?), but I have found no evidence to support either theory besides the comment mentioned above. It seems like the only reliable way to learn anything is to look at the GHC source, which, given its size and complexity, is something that I am eager to do, even if I was sure I would succeed.
Refer to this:
http://hackage.haskell.org/packages/archive/dph-seq/0.5.1.1/doc/html/Data-Array-Parallel.html