Dear all,
I have a simple mathematical problem which I want to use a sample for
parallelism.

My first question is if *partition* and *range *are lazy, does access to
lets say second part of partitioned range cause first part to be
materialized or no? Or is this using arithmetic progression in background,
so access to second part can happen without the need to materialize first
part?

My second question is connected to first. If we have 4 cores and *pmap *starts
4 threads to perform our function on 4 parts of partitioned range, is this
happening in parallel, or it is not (because of partitioned ranges
dependence or something else)?

Here is the code:

*; Take 1.2.P (Parallel)
(def range-end 1000)
(def is-dividable-by-3-and-5 #(or (zero? (rem % 3))
                       (zero? (rem % 5))))

(let [no-processors (.. Runtime getRuntime availableProcessors)
      work (partition (/ range-end no-processors) (range 0 range-end))
      result (pmap
               (fn [part]
                 (reduce + (filter is-dividable-by-3-and-5 part)))
               work)]
  (apply + result))*

-- 
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