dph-prim-par-0.7.0.1: Data Parallel Haskell segmented arrays. (production version)

Safe HaskellNone

Data.Array.Parallel.Unlifted.Parallel.UPSegd

Contents

Description

Parallel segment descriptors.

See Data.Array.Parallel.Unlifted for how this works.

Synopsis

Types

data UPSegd Source

A parallel segment descriptor holds a global (undistributed) segment desciptor, as well as a distributed version. The distributed version describes how to split work on the segmented array over the gang.

Constructors

UPSegd 

Fields

upsegd_usegd :: !USegd

Segment descriptor that describes the whole array.

upsegd_dsegd :: Dist ((USegd, Int), Int)

Segment descriptor for each chunk, along with segment id of first slice in the chunk, and the offset of that slice in its segment. See docs of splitSegdOfElemsD for an example.

valid :: UPSegd -> BoolSource

O(1). Check the internal consistency of a parallel segment descriptor.

Constructors

mkUPSegdSource

Arguments

:: Vector Int

Length of each segment.

-> Vector Int

Starting index of each segment.

-> Int

Total number of elements in the flat array.

-> UPSegd 

O(1). Construct a new parallel segment descriptor.

fromUSegd :: USegd -> UPSegdSource

Convert a global USegd to a parallel UPSegd by distributing it across the gang.

empty :: UPSegdSource

O(1). Construct an empty segment descriptor, with no elements or segments.

singleton :: Int -> UPSegdSource

O(1). Construct a singleton segment descriptor. The single segment covers the given number of elements.

fromLengths :: Vector Int -> UPSegdSource

O(n). Convert an array of segment lengths into a parallel segment descriptor.

The array contains the length of each segment, and we compute the indices from that. Runtime is O(n) in the number of segments.

Projections

length :: UPSegd -> IntSource

O(1). Yield the overall number of segments.

takeUSegd :: UPSegd -> USegdSource

O(1). Yield the global USegd of a UPSegd.

takeDistributed :: UPSegd -> Dist ((USegd, Int), Int)Source

O(1). Yield the distributed USegd of a UPSegd.

We get a plain USegd for each chunk, the segment id of the first slice in the chunk, and the starting offset of that slice in its segment.

takeLengths :: UPSegd -> Vector IntSource

O(1). Yield the lengths of the individual segments.

takeIndices :: UPSegd -> Vector IntSource

O(1). Yield the segment indices.

takeElements :: UPSegd -> IntSource

O(1). Yield the total number of array elements.

takeElements upsegd = sum (takeLengths upsegd)

Indices

indicesP :: UPSegd -> Vector IntSource

O(n). Yield a vector containing indicies that give the position of each member of the flat array in its corresponding segment.

indicesP (fromLengths [5, 2, 3]) = [0,1,2,3,4,0,1,0,1,2]

Replicate

replicateWithP :: Unbox a => UPSegd -> Vector a -> Vector aSource

Copying segmented replication. Each element of the vector is physically copied according to the length of each segment in the segment descriptor.

replicateWith (fromLengths [3, 1, 2]) [5, 6, 7] = [5, 5, 5, 6, 7, 7]

Segmented Folds

foldWithP :: Unbox a => (a -> a -> a) -> a -> UPSegd -> Vector a -> Vector aSource

Fold segments specified by a UPSegd.

fold1WithP :: Unbox a => (a -> a -> a) -> UPSegd -> Vector a -> Vector aSource

Fold segments specified by a UPSegd, with a non-empty vector.

sumWithP :: (Num e, Unbox e) => UPSegd -> Vector e -> Vector eSource

Sum up segments specified by a UPSegd.

foldSegsWithP :: Unbox a => (a -> a -> a) -> (USegd -> Vector a -> Vector a) -> UPSegd -> Vector a -> Vector aSource

Fold the segments specified by a UPSegd.

This low level function takes a per-element worker and a per-segment worker. It folds all the segments with the per-segment worker, then uses the per-element worker to fixup the partial results when a segment is split across multiple threads.