Re: Performance of numerical functions decreases with time

• To: mathgroup at yoda.physics.unc.edu
• Subject: Re: Performance of numerical functions decreases with time
• From: withoff
• Date: Fri, 16 Jul 93 11:12:45 CDT

```> Date: Tue, 13 Jul 93 13:57:47 -0700
> From: Magnus Nordborg <magnus at fisher.stanford.edu>
> To: mathgroup <mathgroup at yoda.physics.unc.edu>
> Subject: Performance of numerical functions decreases with time
> Status: RO
>
> Hi,
>
> 	I have a "time-critical" question here.  I want to find the minimum of a simple
> function for many different parameters.  I define something like:
>
> MyFunction[d_,s_,z_,a_,b_,g_,k_] :=
> Module[{fn,res},
> 	fn = - 2*(1 - d)*M^z*(1 - M^g)^k*s -
>
> 		 (1 - M^g)^k*(1 - (1 - M^a)^b)*(1 - M^z*s);
> 	res = FindMinimum[ fn, {M,0.5}][[2]];
> 	If[ MatchQ[res,{Rule_}],
> 		M /. res,
>   	(* else *)
> 		res = FindMinimum[ fn, {M,0.1}][[2]];
>   		If[ MatchQ[res,{Rule_}],
>   			M /. res,
>   		(* else *)
> 			res = FindMinimum[ fn, {M,0.9}][[2]];
>   			If[ MatchQ[res,{Rule_}],
>   				M /. res,
>   			(* else *)
>   				Null
>   			]
>   		]
>   	]
> ]
>
> This particular pattern tries several starting points, but everything I say below applies
> equally well to the simplest possible pattern.  Now, I am trying to use "Table" to find
> the minimum for 10^5 different values, say.  I did some small number (like 10) and
> then extrapolated to find that my job would take on the order of 20 hours (this is using
> Sparc 2 and NeXT).  80 hours later the machines are still crunching.  So I did a little
> test.  I timed 35 cases, then redid the same 35 cases, and so on 10 times.  To my
> chagrin, I find that the performance is decreasing over time!
>
> why = Table[ Timing[ Table[
> 	{0.1,0.1,0.1,1.5,5,1.5,k,
> 		MyFunction [0.1,0.1,0.1,1.5,5,1.5,k]},
> 	{k,1.5,10,0.25}] ], {i,10} ];
>
>
> Transpose[why][[1]]
>
> {23.8333 Second, 26.2833 Second, 28.85 Second,
>
>
>
>   31.6667 Second, 34.5167 Second, 37.0833 Second,
>
>
>
>   39.7 Second, 42.6 Second, 45.5 Second, 48.5833 Second}
>
>
> It doesn't take the proverbial rocket scientist to see that if time to completion more
> than doubles after doing 300 cases, 10^5 will take a bit MORE than 20 h...
>
> What on earth is going on here?  What is causing this, and is there a work-around?
> We really need these numbers fast, unfortunately.  Time for C...?
>
> Grateful for a quick reply,
>
> 			-Magnus
> ---
> Magnus Nordborg
> magnus at fisher.stanford.edu (NeXT mail preferred)
> Department of Biological Sciences
> Stanford University
> Stanford, CA 94305-5020
> +1 (415) 723-4952 (office)
>
> P.S.  I'm using Mathematica 2.1 on NeXT and Sparc.

-------------------------------------------------------------------

This is a consequence of a bug in the Compile function that causes
it to leave unused symbols behind after it finishes.  The Compile
function is called automatically by FindMinimum.  The unused symbols
are all in Compile` context.  For example:

In[14]:= Names["Compile`*"]

Out[14]= {}

In[15]:= Do[MyFunction [0.1,0.1,0.1,1.5,5,1.5,1.5], {5}]

In[16]:= Names["Compile`*"]

Out[16]= {Compile`x1, Compile`x10, Compile`x11, Compile`x12, Compile`x13,

>    Compile`x14, Compile`x15, Compile`x16, Compile`x17, Compile`x18,

>    Compile`x19, Compile`x2, Compile`x20, Compile`x3, Compile`x4,

>    Compile`x5, Compile`x6, Compile`x7, Compile`x8, Compile`x9}

There are three known workarounds:

1)  Remove all of the symbols in Compile` context after each use
of Compile.  For example:

Scan[(Unprotect[#]; Remove[#]) &, Names["Compile`*"]]

2)  Turn off automatic use of Compile using Compiled->False in
the corresponding functions.

3)  Use Mathematica Version 2.2.  The bug has been fixed in Version 2.2.

The same explanation will also apply to repeated use of any function
that uses Compile, which includes most of the numerical application
and plotting functions, or to repeated direct use of Compile.

Dave Withoff
Wolfram Research

```

• Prev by Date: to postscript
• Next by Date: Algorithm used in NDSolve
• Previous by thread: Performance of numerical functions decreases with time