Hi guys, anyone has an insight into the problem I'm running into?
On Mar 4, 2:27 am, "Dimiter \"malkia\" Stanev" <mal...@gmail.com>
wrote:
> Hi guys,
>
> In the example below, if map is replaced with pmap, it goes twice
> slower on my MBP (2 CPUs).
>
> I believe it's probably the (reduce + ...) causing it, but I can't
> explain it.
>
> Version with map:
> user> (time (pnpolytest))
> "Elapsed time: 3903.533 msecs"
> 6000000
>
> Version with pmap:
> user> (time (pnpolytest))
> "Elapsed time: 7995.565 msecs"
>
> What I'm doing wrong here?
>
> (defn- pnpoly [npol #^floats xp #^floats yp x y]
> (let [npol (int npol)
> x (float x)
> y (float y)]
> (loop [r (int 0)
> i (int 0)
> xi (aget xp (dec npol))
> yi (aget yp (dec npol))]
> (if (< i npol)
> (let [xj xi xi (aget xp i)
> yj yi yi (aget yp i)]
> (if (or (= (> yi y) (> yj y))
> (>= x (+ xi (/ (* (- xj xi)
> (- y yi))
> (- yj yi)))))
> (recur (bit-not r) (inc i) xi yi)
> (recur r (inc i) xi yi)))
> (- r)))))
>
> (defn pnpolytest []
> (let [xp
> (float-array
> [+0.0 +1.0 +1.0 +0.0 +0.0
> +1.0 -0.5 -1.0 -1.0 -2.0
> -2.5 -2.0 -1.5 -0.5 +1.0
> +1.0 +0.0 -0.5 -1.0 -0.5])
> yp
> (float-array
> [+0.0 +0.0 +1.0 +1.0 +2.0
> +3.0 +2.0 +3.0 0.0 -0.5
> -1.0 -1.5 -2.0 -2.0 -1.5
> -1.0 -0.5 -1.0 -1.0 -0.5])
> npol 20]
> (reduce +
> ;; Replace the nex map with pmap,
> ;; and things slow down
> (map (fn [_]
> (+ (pnpoly npol xp yp 0.5 0.5)
> (pnpoly npol xp yp 0.5 1.5)
> (pnpoly npol xp yp -0.5 1.5)
> (pnpoly npol xp yp 0.75 2.25)
> (pnpoly npol xp yp 0.0 2.01)
> (pnpoly npol xp yp -0.5 2.5)
> (pnpoly npol xp yp -1.0 -0.5)
> (pnpoly npol xp yp -1.5 0.5)
> (pnpoly npol xp yp -2.25 -1.0)
> (pnpoly npol xp yp 0.5 -0.25)
> (pnpoly npol xp yp 0.5 -1.25)
> (pnpoly npol xp yp -0.5 -2.5)))
> (range 0 1000000)))))
>
> Thanks,
> Dimiter "malkia" Stanev
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---