Re: Efficient CPU usage with recursively parallelizable problem



On Oct 18, 1:57 pm, Tom Anderson <t...@xxxxxxxxxxxxxxx> wrote:
On Sat, 17 Oct 2009, Tomas Mikula wrote:
I have a purely computational (no I/O) problem that can be recursively
split into concurrent tasks. Each task needs to wait for its child tasks
to complete. How would I implement this efficiently, meaning to keep all
the CPU cores busy, while keeping the context-switching overhead low
(i.e. maintain the number of running threads roughly equal to the number
of cores)?

You appear to have rediscovered what is called the "fork-join" parardigm
for parallelism. Sometimes known as "work stealing", although that name
refers to its usual implementation, rather than its surface semantics.

I think this must be a common problem, but can't find a straightforward
solution in the Java SE API. Therefore I'm asking here, maybe I'm
overlooking something.

Just upgrade to Java 7, which will have classes for fork/join via JSR
166y.

Or, if you don't have a time machine, read Doug Lea's paper:

http://gee.cs.oswego.edu/dl/papers/fj.pdf

And then download his library:

http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/...

Or even the prototypes of the JSR-166y classes:

http://gee.cs.oswego.edu/dl/concurrency-interest/

Related reading:

http://www.ibm.com/developerworks/java/library/j-jtp11137.html

tom

--
It's Brains you want!

I quickly looked at it and this really seems to be the API I was
missing in Java 6. Thank you!
.



Relevant Pages

  • Re: simple web programming options
    ... And that I have seen from CGI/FCGI, Java ... PHP seems to provide the best API of ready-to-use ... doing CGIs specifically and scripted access to databases. ... I recommend PHP highest for language. ...
    (comp.programming)
  • Re: to RG - Lisp lunacy and Perl psychosis
    ... about ABCL and was hoping to stick with a familiar ANSI implementation ... The Java access API is derived from ACL's jlinker (http:// ... ACL's API assumes the JVM is a different process, ... It is mostly ANSI compliant; it lacks the long form of define-method- ...
    (comp.lang.lisp)
  • Re: what is encapsulation in an interface ?
    ... you're promoting ignorance of the collections API. ... be aware of it in order to collect pay as a Java programmer. ... How fortunate it is for us Java programmers that you aren't the world ... very short "for" loop was terrible and no ...
    (comp.lang.java.programmer)
  • Re: Shortage of qualified Java programmers
    ... library of Java is what you have computers for -- not people. ... every detail of the API. ... to figure out how a Comparator works given the Javadocs. ... programmers written by Bill Venners. ...
    (comp.lang.java.programmer)
  • Re: Shortage of qualified Java programmers
    ... candidates are very hard to come by in the Atlanta area. ... that a candidate will list every Java technology in the world on his ... API test.) ... questions might be too easy for programmers with 3+ years Java experience. ...
    (comp.lang.java.programmer)