Thanks! Realized that a bit too late (Looked into the pmap source
code, but that's about it).

I've split my job decision roughly 1000 x 1000 - now I'm getting 8
times speedup, on 8 core machine:

 (reduce +
            (pmap
             (fn [_]
               (reduce +
                       (map (fn [_]
                              (+ (pnpoly np xp yp  0.5   0.5)
                                 (pnpoly np xp yp  0.5   1.5)
                                 (pnpoly np xp yp -0.5   1.5)
                                 (pnpoly np xp yp  0.75  2.25)
                                 (pnpoly np xp yp  0.0   2.01)
                                 (pnpoly np xp yp -0.5   2.5)
                                 (pnpoly np xp yp -1.0  -0.5)
                                 (pnpoly np xp yp -1.5   0.5)
                                 (pnpoly np xp yp -2.25 -1.0)
                                 (pnpoly np xp yp  0.5  -0.25)
                                 (pnpoly np xp yp  0.5  -1.25)
                                 (pnpoly np xp yp -0.5  -2.5)))
                            (range 0 1000))))
             (range 0 1000)))

Clojure is reasonable :)

Jeffrey Straszheim wrote:
> It is pretty common to get a slowdown when moving from map to pmap.  It just
> means that the thread scheduling overhead is greater than the gain from
> parallelizing the code.  The behavior might be very different w/ larger data
> sets, or w/ more CPU's.  It is often best to leave parallelism as an option
> to the client of your library.
> Are you using the latest build?  pmap now uses Java futures and they run in
> a cached thread pool.  If so, try running the algorithm a few times and see
> if it speeds up as the thread pool winds up.
>
> On Fri, Mar 6, 2009 at 1:31 PM, Dimiter malkia Stanev <mal...@gmail.com>wrote:
>
> >
> > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to