On Tue, May 18, 2010 at 10:18 AM, braver <delivera...@gmail.com> wrote:

> I have a huge graph of the form
>
> {"john" {1 {"alice" 1, "bob" 3}, 4 {"alice" 2, "stan" 1}, "alice" {1
> {"john" 1, "mandy" 2}, 2 {"john" 3, "stan" 2}}}
>
> It shows for each user days on which he communicated, and for each
> day, with whom and how many times he addressed that person.
> Essentially this is an adjacency list -- here it's a map --
> representation of a graph.
>
> I need to verify that for any top-level user, the days in his
> adjacency list, as returned by seq'ing the adjacency map.  I've
> written these functions to do it, with the help of the #clojure folks:
>
> (defn reps-sorted1? [dreps & [progress]]
>  (loop [[[user ureps :as userdays] :as users] (seq dreps) i 0]
>    (if ureps
>      (if (loop [prev 0 [[day _] :as days] (seq ureps)]
>        (when (and progress (= 0 (mod i progress))) (print ".")
> (.flush System/out))
>        (if day (if (<= prev day)
>          (recur day (next days))
>            (do (println userdays) false)) true))
>            (recur (next users) (inc i)) false) true)))
>
> (defn reps-sorted2? [dreps]
>  (->> dreps (pmap (fn [[_ days]]
>    (let [s (map first days)]
>      (every? true? (map >= s (cons (first s) s))))))
>    (every? true?)))
>
> user=> (time (reps-sorted2?
> dreps))
> "Elapsed time: 127606.905 msecs"
> true
> user=> (time (reps-sorted1? dreps))
> "Elapsed time: 8368.616 msecs"
> true
>
> As you can see, the imperative solution vastly outperforms the
> functional one, even though the functional allows for pmap!  Without
> the pmap, it actually did faster, in 40 seconds.  Why is FP slower
> here?
>
> -- Alexy
>

The documentation is pretty clear about how pmap works. Your work needs to
be greater than the coordination overhead. You probably need to batch your
work before trying to call pmap.

David

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

Reply via email to