Parallel creation of random numbers
- Dominant language
- Haskell
- Stars
- 61
- Forks
- 27
- PR merge metrics
- No merged PRs in 30d
Description
Hello, many times I use `mwc-random` to perform a calculation repeatedly, and then I collect the results in form of a list (or vector). Is there a way to parallelize this computation?
For example:
f :: PrimMonad m => Int -> Gen (PrimState m) -> m [Int]
f n g = replicateM n $ uniform g
I can parallelize this computation by splitting the generator, for example like so
splitGen :: PrimMonad m => Int -> Gen (PrimState m) -> m [Gen (PrimState m)]
splitGen n gen
| n <= 0 = return []
| otherwise = do
seeds :: [V.Vector Word32] <- replicateM n $ uniformVector gen 256
mapM initialize seeds
(One needs to activate scoped type variables for this to work). But then, in order to use these generators in parallel, I can only use `mapConcurrently` from the `async` library at the moment which requires the `IO` monad, something I do not really want.
Is there an easier possibility to perform these computations in a given number of parallel threads, each dragging along their private generator? I was, for example, thinking of `parListChunk` from `Control.Parallel.Strategies`, or similar techniques.
Thank you!
PS: I also found https://stackoverflow.com/a/16250010, but I do not really understand what's going on there.
Contributor guide
No contributing guide indexed for this repository
Research direction
No repository file or test is named. Start by reviewing the existing mwc-random generator API alongside Control.Parallel.Strategies, parListChunk, and async/mapConcurrently, then determine whether the project wants a new parallel-generation API and which monads and thread behavior it must support. Done would require an agreed scope and corresponding implementation and tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100