Ideally, you wouldn't be using a side effect at all, but something like
reducers to return a single computed result after going over the sequence.
(If the input's too big for main memory, you'd also need to partition the
input seq into reducible-collection chunks small enough to fit in memory.)

If side effects are necessary because you're doing I/O for each element of
the seq, then the overhead of wrapping in pmap is probably minimal as the
task is I/O-bound, but the benefit of pmap may not be significant either.
Threaded I/O is generally only useful for 1. preventing I/O from
bottlenecking a CPU-bound task by splitting them into separate threads and
2. networking with many remote hosts, so you can usefully do something with
host B while waiting for a response from host A, or with one remote host
where latency and task orthogonality make several parallel interactions
preferable to several sequential ones (e.g. a web browser loading images
several at a time from a web server when the throughput is high but so is
the latency).

If side effects are necessary because you're interacting with a legacy Java
API that uses mutable state, you might want to look into pvalues and pcalls.


On Wed, Oct 16, 2013 at 10:34 PM, Pradeep Gollakota <pradeep...@gmail.com>wrote:

> Hi All,
>
> I’m (very) new to clojure (and loving it)… and I’m trying to wrap my head
> around how to correctly choose doseq vs dorun for my particular use case.
> I’ve read this earlier post
> https://groups.google.com/forum/#!msg/clojure/8ebJsllH8UY/mXtixH3CRRsJand I 
> had a clarifying question.
>
> From what I gathered in the above post, it’s more efficient to use doseq
> instead of dorun since map creates another seq. However, if the fn you want
> to apply on the seq can be parallelized, doseq wouldn’t give you the
> ability to parallelize. With dorun you can use pmap instead of map and get
> parallelization.
>
> (doseq [i some-lazy-seq] side-effect-fn)
> (dorun (pmap side-effect-fn some-lazy-seq))
>
> What is the idiomatic way of parallelizing a computation on a lazy seq?
>
> Thanks,
> Pradeep
>
> --
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to