aphyr / tesser

Clojure reducers, but for parallel execution: locally and on distributed systems.
871 stars 39 forks source link

Transient data structures with > 1 chunk #15

Closed neverfox closed 8 years ago

neverfox commented 8 years ago

In the README, it suggests that you could use the post-reducer to turn transient data structures into persistent data structures, so I tried this with a toy example. It works great if there's just one chuck, but if there's more than one, you get the dreaded Transient used after persistent! call error.

(t/tesser (reducible-chunk 512 (range 512))
(t/fold {:reducer-identity (constantly (transient []))
         :reducer conj!
         :post-reducer persistent!
         :combiner-identity (constantly (transient []))
         :combiner conj!
         :post-combiner persistent!}))
;; works

(t/tesser (reducible-chunk 512 (range 513))
(t/fold {:reducer-identity (constantly (transient []))
         :reducer conj!
         :post-reducer persistent!
         :combiner-identity (constantly (transient []))
         :combiner conj!
         :post-combiner persistent!}))
;; fails

Based on my understanding from your diagrams, the second chunk should be starting with a new reducer-identity value, i.e. a new transient data-structure, so where am I going wrong?

aphyr commented 8 years ago

In your example, you compute a single transient, then make a constant function that returns it. It's trying to use the same transient for every reducer at once.

neverfox commented 8 years ago

Oh course! So obvious now. Thank you!

(partial transient [])