Thanks a lot, Francis! I've made the changes you suggest - replaced map with mapv and modified apply-cmd to take/return a vector instead of a set (it converts to set internally). My understanding is that reducers preserve the order of operation, so it should give the correct answer. Instead, the simple version now takes ~120 s to run, whereas the r/fold version fails with a "UnsupportedOperationException: nth not supported on this type: Long" somewhere inside reducers/foldvec/fn. Strange.
On Sunday, April 3, 2016 at 2:38:26 AM UTC+5:30, Francis Avila wrote: > > Your input collection to r/fold is provided by cmds-from-input which > returns a lazy-seq (from map) which is not a parallel-foldable type. You > can try mapv instead: vectors are parallel-foldable. (Note only > PersistentVector and PersistentHashMap have useful coll-fold > implementations: all other objects (including sets) fall back on normal > reduction: > https://github.com/clojure/clojure/blob/d5708425995e8c83157ad49007ec2f8f43d8eac8/src/clj/clojure/core/reducers.clj#L347-L367 > ) > > Additionally, I'm not sure how this algorithm could be parallelized > because the order in which you apply the toggle operation matters! I > suspect if you make the mapv change I suggest you will get different final > answers. > > > > > > > On Saturday, April 2, 2016 at 3:24:47 PM UTC-5, Divyansh Prakash wrote: >> >> Hi! >> I'm solving the problem described here <http://adventofcode.com/day/6>. >> I've got the solution >> <https://github.com/divs1210/advent-of-code/blob/master/src/aoc/day6.clj>, >> but it takes ~50 s to compute. >> I tried optimising it by replacing the main reduce operation with r/fold, >> but it doesn't seem to have any effect on the performance for whatever n >> (batch size) I use. >> Any suggestions? >> >> Note: I'm using a MacBook Pro with 8 cores. JDK 7. Clojure 1.8. >> > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
