rseq is an evaluation strategy that evaluates a value sequentially to weak head normal form. In chunked parallel work, it evaluates each chunk rather than creating another spark. section 13.4.3
Use rseq when parallel work already creates the sparks:
- Combine it with parListChunk so each spark performs a larger unit of work. section 13.4.3
- Avoid replacing it with rpar in this situation, because rpar would spark another spark and add useless work. section 13.4.3
- Tune chunk sizes and verify performance with benchmarking, since spark management and garbage collection can reduce speedups. section 13.4.3
Listing 13.25 A module for chunked parallel execution of the Vector type
module Data.Vector.Strategies (parVectorChunk) where import Control.Parallel.Strategies #1 import qualified Data.Vector as V #1 parVectorChunk :: Int -> Strategy (V.Vector a) parVectorChunk size = fmap V.fromList . parListChunk size rseq . V.toList #2
A Vector strategy converts the Vector to a list, applies parListChunk with rseq, and converts the result back. section 13.4.3
