Mathematica 9 is now available
Previous section-----Next section

Dispatching Evaluations to Remote Kernels

ParallelDispatch[h[e1,e2,...,en],{k1,k2,...,km}]
evaluateseion kernel ki and returns h[ r1, r2, ... rn],whereriis the result of evaluatingei. The default list of kernels is $Slaves
ParallelEvaluate[h[e1,e2,...,en],f,comb]
evaluates f[h[e1,e2,...,en]] in parallel by distributing chunks f[h[ei,ei+1,...,ei+k]] to all kernels and combining the results with comb[].
ParallelEvaluate[h[e1,e2,...,en],f]
the default combiner comb is h, if h has attribute Flat, and Join otherwise
ParallelEvaluate[h[e1,e2,...,en]]
the default function f is Identity

Basic parallel dispatch of evaluations.

In ParallelDispatch[h[e1,e2,...,en],{k1,k2,...,km}], the number m of kernels must be at least as large as the number n of expressions. ParallelDispatch has the attribute HoldFirst so that h[e1,e2,...,en] is not evaluated on the master kernel before the parallelization.
ParallelDispatch[{e1,e2,...,en},{k1,k2,...,kn}] is equivalent to Receive[Inner[Send,{k1,k2,...,kn},{e1,e2,...,en}]].
ParallelEvaluate[h[e1,e2,...,en],f,comb] breaks h[e1,e2,...,en] into as many pieces h[ei,ei+1,...,ei+k] as there are remote kernels, evaluates f[h[ei,ei+1,...,ei+k]] in parallel (using ParallelDispatch[]), then combines the results ri using comb[r1,r2,...,rm]. ParallelEvaluate has the attribute HoldFirst so that h[e1,e2,...,en] is not evaluated on the master kernel before the parallelization.
The size of the pieces of the input expression is chosen to be proportional to the remote processor speed estimates for optimal load balancing.

ParallelEvaluate

ParallelEvaluate is a general and powerful command with default values for its arguments that are suitable for evaluating elements of containers such as lists and associative functions.

Evaluating List-like Containers

If the result of applying the function f to a list is again a list, ParallelEvaluate[{e1,e2,...,en},f] simply applies f to pieces of the input list and joins the partial results together.
In[2]:=
Out[2]=
The result is the same as that of Prime[{1,2,3,4,5,6,7,8,9}], but the computation is done in parallel.
The default function is Identity, therefore, ParallelEvaluate[{e1,e2,...,en}] simply evaluates the elements ei in parallel.
In[3]:=
Out[3]=
If the result of applying the function f to a list is not a list, a custom combiner has to be chosen.
The function Function[li,Count[li,_?OddQ] counts the number of odd elements in a list. To find the total number of odd elements, add the partial results together.
In[4]:=
Out[4]=

Evaluating Associative Operations

If the operation h in h[e1,e2,...,en] is associative (has attribute Flat), the identity
holds; with the default combiner being h itself, the operation is parallelized in a natural way. Here all numbers are added in parallel.
In[5]:=
Out[5]=
In[6]:=
Out[6]=

Automatic Parallelization

ParallelEvaluate[cmd[list,arguments...]] recognizes if cmd is a Mathematica function that operates on a list or other long expression in a way that can be easily parallelized and performs the parallelization automatically. You do not need to figure out suitable f and comb for ParallelEvaluate[list,f,comb]. The list of commands that can be parallelized is kept in the variable $ParallelCommands.
In[5]:=
Out[5]=
In[6]:=
Out[6]=
In[7]:=
Out[7]=
In[8]:=
Out[8]=
Not all uses of these commands can be parallelized. A message is generated and the evaluation is performed sequentially on the master kernel if necessary.
In[9]:=
Out[9]=


Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.