some programs can be made to run faster by dividing them up into smaller pieces and running these pieces on multiple processors. this is known as parallel computing, and a large number of hardware and software systems exist to facilitate it. the most famous example of a (distributed) parallel program is seti@home, but there are many other applications, including ray tracing, database searching, code breaking, neural network training, genetic algorithms, and a whole host of np-complete problems where a brute force approach is needed.
the replicated-worker pattern 【程序编程相关:Principles, Patterns】computefarm is an open source java framework for developing and running parallel programs. under the covers, computefarm runs on jini, which brings code mobility and fault tolerance to network applications. from version 2.1 onwards, jini is being java.sun.com/cgi-bin/wa?a2=ind0503&l=jini-users&o=d&p=36217">released under the apache license, version 2.0, so this is an exciting time for jini. this article introduces computefarm and illustrates how to run parallel programs with it. 【推荐阅读:Using the Strategy D】
in computefarm, a computespace holds task objects and result objects of the type object. each workers lifecycle is as follows: 【扩展信息:Timing is Everything】
computefarm grew out of an implementation in javaspaces (itself a part of jini) of the replicated-worker pattern from the definitive book on javaspaces, java.sun.com/developer/books/javaspaces/introduction.html">javaspaces principles, patterns, and practice, by eric freeman, susanne hupfer, and ken arnold. in this pattern, also know as the master-worker pattern, a master process creates a collection of tasks that need to be run. workers take tasks from the collection and run them, then hand the computed result to the master. a space is a natural conduit for passing messages between master and workers, due to the decoupled programming style it encourages.
wait for an available task from the computespace. execute the task. put the task result back into the computespace. go to step 1.there are typically many workers, and they are identical; hence the term replicated. this pattern neatly provides load balancing, whereby each worker contributes whatever resources it can afford. the worker on a faster machine will execute more tasks than the worker on a slower or otherwise heavily loaded machine; and as long as the granularity of the tasks is sufficiently fine, no one worker will hold up the computation.
a client of computefarm (the master process) will not usually think in terms of the workers doing their work, but in terms of the overall problem they have to solve, called a job. from the clients point of view, this is what happens:
... 下一页