On Sun, Dec 28, 2008 at 10:50 PM, Piotr 'Qertoip' Włodarek <qert...@gmail.com> wrote: > > Following my recent adventure with words ranking, here's the parallel > version: > > (use 'clojure.contrib.duck-streams)
Thanks for including your 'use' line -- that's so much better than leaving it implied. Please also consider using 'require' instead, or the :only option to 'use' to make it clear which functions are being brought in from which lib. > (defn split-string-in-two [s] > (let [chunk-size (quot (count s) 2)] > [(subs s 0 chunk-size), (subs s chunk-size)])) Might this cut a word in half and produce (slightly) incorrect results? > 1. Is there a better way to do it? Perhaps agents should share some > data structure? I've got lots to learn in the realm of parallel program design, but the sequential summing step at the end stood out to me. Perhaps another agent that just does incremental summing along the way would reduce the running time. Also, the entire file is read in by a single thread -- perhaps the use of mmap would allow the agents to start counting sooner and reduce total run time that way. You may want to look at clojure.contrib.mmap > 2. Despite producing valid results, the program never ends. Why? When a program uses agents, the top-level of the program is responsible for determining that all the agents have done what they need to, and that the program can terminate. At the REPL this can generally be done with Ctrl-D. In a Script, use (shutdown-agents). I imagine this ought to be done by the same level of code that calls parallel-top-words, since p-t-w itself can't know that no other agent work is being done. --Chouser --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---