Re: Version 3.0 Speed
- To: mathgroup at smc.vnet.net
- Subject: [mg7426] Re: [mg7408] Version 3.0 Speed
- From: David Withoff <withoff>
- Date: Sat, 31 May 1997 15:07:53 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
> Hello folks, > > Define > > v[x_, y_, nmax_] := > ((4/Pi) Sum[(1/(2 m - 1)) Sin[(2 m - 1) Pi y] Exp[-(2 m - 1) Pi x], > {m, 1, nmax}]) > > and evaluate > > Plot3D[Evaluate[v[x, y, 400]], {x, 0, 1.3}, {y, 0, 1}, > PlotRange -> {0, 1}, Boxed -> False, > ViewPoint -> {1.741, -2.565, 1.356}, > PlotPoints -> 27, BoxRatios -> {1, 1, 1}, > AxesLabel -> {"x (b)", "y (b)", "V (Vo)"} > ]//Timing > > On a PowerMac 7500/100 with plenty of memory, Version 3.0 takes about 650 > seconds to generate the plot, whereas Version 2.2.2 takes only about 15 > seconds. Why is Version 3.0 so slow comparatively, by a factor of over 40? > > Thanks a lot. > > Patrick Tam This difference is a result of a change in the way that CompiledFunction handles overflow and underflow. For example, in cases of machine underflow, CompiledFunction gives zero in Version 2.2: In[1]:= f = Compile[{x}, Exp[x]] Out[1]= CompiledFunction[{x}, Exp[x], -CompiledCode-] In[2]:= f[-100000.] Out[2]= 0. but in Version 3.0 it switches to uncompiled evaluation: In[1]:= f = Compile[{x}, Exp[x]] Out[1]= CompiledFunction[{x}, Exp[x], -CompiledCode-] In[2]:= f[-100000.] CompiledFunction::cfn: Numerical error encountered at instruction 3; proceeding with uncompiled evaluation. -43430 Out[2]= 3.562949565 10 The compiler is called automatically from Plot3D. Compiled evaluation is faster for this example than uncompiled evaluation. Many of the terms in v[x, y, 400] generate machine underflow within the range of the plot. Version 2.2 just replaces these terms with zero and continues with compiled evaluation, which is often wrong, but which is probably ok in this example. Version 3.0 is more careful, and switches to uncompiled evaluation when it detects underflow, but that extra care has the unfortunate side effect of making this calculation slower. Getting reliable answers is nice, but getting answers quickly is also nice. Maybe in some future version of Mathematica there will be a way to get the best of both designs. Dave Withoff Wolfram Research