A good way to process an array? #12
Unanswered
alexshpilkin
asked this question in
Q&A
Replies: 1 comment 2 replies
-
I agree that "pretending the array is an tree" should be possible, but that will also lead I had envisioned something like this:
This kinda creates that tree "on-demand". However, it's not entire clear to me how the ownership of the data ought to be, nor how we pick a good |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The full binary tree example in the README is good and perhaps representative of some places where one’d want to use automatic parallelization. But there’s also another simple case of a very different flavour: arrays.
Suppose there’s a large linear array of stuff we need to go through in some semblance of an order (a map, a reduce with an associative but not necessarily commutative operation, or something in that vein). Enqueueing every processing job from 0 to N–1 and then gathering up all the results from N–1 to 0 is likely not a good idea for a multitude of reasons (even for a map), one among them being that all the work for enqueueing the items is stuck on the initial thread.
Pretending the array is actually a tree (with the first level dividing the items into [0, N/2) and [N/2, N), and so on down) is probably better, but once the parallelism runs out it has a fairly cache-unfriendly access pattern compared to the linear one we’d have had if we hadn’t went for parallel processing. It sounds like what we’d actually need is to lay out the array non-linearly from the start. I recall a paper (arXiv, ACM DL) considered array layouts for in-RAM binary search and measured things like a BFS layout (like you’d use for implementing a binary heap; their winner) and a Van Emde Boas one (theoretical cache-oblivious winner, but in practice a loser for RAM datasets because of the indexing overhead). Their problem is not quite like ours, though.
Thoughts? Experiences?
(I really hope I’m overcomplicating things and there’s a simple solution I overlooked...)
Beta Was this translation helpful? Give feedback.
All reactions