On Dec 29, 7:02 am, Chouser <chou...@gmail.com> wrote: > > (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?
True, I decided to let it be for the sake of simplicity. > > 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 Thanks for suggestion. In fact, mmap/slurp is *much* faster than built-in slurp. Now, my program starts with: (ns com.wlodarek.examples (:require [clojure.contrib.mmap]) (:require [clojure.contrib.duck-streams])) (defn read-file [filepath] (str (clojure.contrib.mmap/slurp filepath))) (defn write-file [filepath string] (clojure.contrib.duck-streams/spit filepath string)) ; ... I hope Clojure will soon have fast, reasonably named read/write file functions built in the core. Now I'm trying to parallelize also the formatting part, and to move from 2 agents to n agents. Again, thanks for all tips! regards, Piotrek --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---