New in Wolfram Mathematica 7: Built-in Parallel Computing  previous | next 
Solve Optimization Problems with Speculative Parallelism
Mathematica 7 lets you run a command with a number of different inputs, stopping when a result is obtained. In the following a minimization command is run using several different methods. The first one to finish is used and the others are canceled. The computation is then repeated using all the methods; a table shows all the results along with the result of the speculative result.
In[1]:=

Click for copyable input
methods = {"Newton", "QuasiNewton", "ConjugateGradient", 

   "InteriorPoint"};

try = ParallelTry[

   {#, FindMinimum[

      E^Sin[5 x] + Sin[5 E^y] + Sin[5 Sin[x]] + Sin[Sin[5 y]] - 

       Sin[5 (x + y)] + 1/4 (x^2 + y^2), {x, y}, Method -> #]} &, 

   methods];
In[2]:=

Click for copyable input
data = ParallelMap[

   {#, FindMinimum[

      E^Sin[5 x] + Sin[5 E^y] + Sin[5 Sin[x]] + Sin[Sin[5 y]] - 

       Sin[5 (x + y)] + 1/4 (x^2 + y^2), {x, y}, Method -> #]} &, 

   methods];
In[3]:=

Click for copyable input
data = Map[ {#[[1]], #[[2, 1]], 

     If[#[[1]] === First[try], "Speculative Result", ""]} &, data];

data = Prepend[data, {"Method", "Minimum"}];

Text[Grid[data, Frame -> All , Spacings -> {1, 1}]]
Out[3]=