Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

To my knowledge, DiscretePlot cannot be parallelized, although one can simulate the default behavior of DiscretePlot and get the benefits of parallelization with a combination of ListPlot and ParallelTable. For example.

f[x_]:=(Pause[0.5];x^2);
DiscretePlot[f[x], {x, 0, 2, 0.2}] // AbsoluteTiming

Mathematica graphics

ListPlot[ParallelTable[{x, f[x]}, {x, 0, 2, 0.2}], 
  Filling -> Axis] // AbsoluteTiming

Mathematica graphics

The problem with this alternative is that we lose access to several useful DiscretePlot options: ExtentMarkers, ExtentSize and ExtentElementFunction. How can we simulate the behavior of these options in ListPlot so that we may preserve the benefits of parallelization?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Try this:

ClearAll[discretePlot];
SetAttributes[discretePlot,HoldAll];
discretePlot[args___]:=
    Block[{System`DiscretePlotDump`flatTable},            
        SetAttributes[System`DiscretePlotDump`flatTable,HoldFirst];
        System`DiscretePlotDump`flatTable[expr_,eval_,{var_},{vals_}]:=
            ParallelTable[expr,{var,vals}];
        DiscretePlot[args]
    ];
share|improve this answer
1  
How could I have missed System`DiscretePlotDump`flatTable? Brilliant. –  bobthechemist Apr 8 at 17:13
2  
@bobthechemist Yep, that's the first thing that comes to mind - you probably just forgot :) –  Leonid Shifrin Apr 8 at 17:14
    
I don't actually get an improvement in AbsoluteTiming using this function on bob's example. Should I? v7 issue? –  Mr.Wizard Apr 11 at 2:39
    
@Mr.Wizard Very likely, V7 issue. Can't check, don't have V7 handy. –  Leonid Shifrin Apr 11 at 13:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.