Re: Redundant numerical input
- To: mathgroup at smc.vnet.net
- Subject: [mg67883] Re: Redundant numerical input
- From: "James Gilmore" <james.gilmore at yale.edu>
- Date: Tue, 11 Jul 2006 05:59:09 -0400 (EDT)
- Organization: Yale University
- References: <e8nsji$k46$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
I think I understand what you are asking.
You may like to pass the values to the argument, so that all possible
numerical operations are performed _before_ the compilation of the function
occurs. This is often advantageous. This could be achieved through pattern
matching, for example,
f=Compile[{{x,_Real},{y,_Real},{z,_Real}},
Evaluate[arg/.{parameters->knownvalues}]
]
Then you could just thread f over the relevant arguments in your list that
change at the given discretization. Here is a simple example demonstrating
the idea. For more complicated arguments, the gains should be larger than
below.
In[43]:=
f = Compile[{{x, _Real}}, Evaluate[x + 2.*a /. {a -> 2}]]
f2 = Compile[{{x, _Real}, {a, _Real}}, x + 2.*a]
Timing[Do[f[0], {10000000}]]
Timing[Do[f2[0, 2], {10000000}]]
Out[43]=
CompiledFunction[{x}, 4.\[InvisibleSpace] + x, -CompiledCode-]
Out[44]=
CompiledFunction[{x, a}, x + 2. a, -CompiledCode-]
Out[45]=
{7.125 Second, Null}
Out[46]=
{8.219 Second, Null}
If you are performing a loop over the parameters, then f will have to be
recompiled each time, so there may be some trade off in speed if this is the
case. Also, if you like, you could send me the numerical function you are
working with and I can take a look and see if there are any bottlenecks?
Hope this was helpful.
Cheers
James Gilmore
"gregorc" <gregor.cernivec at fe.uni-lj.si> wrote in message
news:e8nsji$k46$1 at smc.vnet.net...
> Dear group members,
>
> I am using manually defined (compiled) function which takes for input
> over 50 arguments of length 3. Most of these are just material
> parameters which are constant during numerical simulation and only 3 of
> them are calculation variables. When the function is threaded over many
> discretization points, the calculation becomes rather time consuming. I
> was wondering if it is somehow posible to "tell" the numerical function
> not to parse the redundant parameters every time, since they are already
> in the memory, i.e. use the same form of numerical function, but only 3
> calculation varibles are evaluated each time used. I think this would
> greatly speed up my calculations!?
>
> Thank you and best regards.
>