Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5013
| From | Oliver Ruebenkoenig <ruebenko@wolfram.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Compilation: Avoiding inlining |
| Date | 2011-09-16 11:08 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j4vana$dal$1@smc.vnet.net> (permalink) |
| References | <201109160946.FAA12301@smc.vnet.net> |
On Fri, 16 Sep 2011, DmitryG wrote:
> Here is a program with (* Definition of the equations *) made one-
> step, that performs the same as in my previous post:
>
> **************************************************************************
>
> (* Runge-Kutta-4 routine *)
> makeCompRK[fIn_] :=
> With[{f = fIn},
> Compile[{{x0, _Real,
> 1}, {t0, _Real}, {tMax, _Real}, {n, _Integer}},
> Module[{h, K1, K2, K3, K4, SolList, x = x0, t},
> h = (tMax - t0)/n;
> SolList = Table[x0, {n + 1}];
> Do[t = t0 + k h;
> K1 = h f[t, x];
> K2 = h f[t + (1/2) h, x + (1/2) K1];
> K3 = h f[t + (1/2) h, x + (1/2) K2];
> K4 = h f[t + h, x + K3];
> x = x + (1/6) K1 + (1/3) K2 + (1/3) K3 + (1/6) K4;
> SolList[[k + 1]] = x
>
> , {k, 1, n}];
> SolList](*,CompilationTarget->"C"*)]];
>
> (* Definition of the equations *)
> NN = 100;
> F = Function[{t, x}, Evaluate[ Table[-x[[i]] Sin[ 0.3 t]^2/(1 + 100
> Sum[x[[i + j]], {j, 1, Min[3, NN - i]}]^2), {i, 1, NN}]]];
> Print[]
>
> (* Compilation *)
> tt0 = AbsoluteTime[];
> Timing[RK4Comp = makeCompRK[F];]
> AbsoluteTime[] - tt0
> Print[];
>
> (* Setting parameters and Calculation *)
> x0 = Table[ RandomReal[{0, 1}], {i, 1, NN}]; t0 = 0; tMax =
> 200; n = 500;
> tt0 = AbsoluteTime[];
> Sol = RK4Comp[x0, t0, tMax, n];
> AbsoluteTime[] - tt0
>
> Print["Compilation: ", Developer`PackedArrayQ@Sol]
>
> (* Plotting time dependences *)
>
> x1List = Table[{1. t0 + (tMax - t0) k/n, Sol[[k + 1, 1]]}, {k, 0,
> n}];
> x2List = Table[{1. t0 + (tMax - t0) k/n, Sol[[k + 1, 2]]}, {k, 0, n}];
> x3List = Table[{1. t0 + (tMax - t0) k/n, Sol[[k + 1, 3]]}, {k, 0, n}];
> ListLinePlot[{x1List, x2List, x3List}, PlotMarkers -> Automatic,
> PlotStyle -> {Blue, Green, Red}, PlotRange -> {0, 1}]
>
> **********************************************************
>
> As I understand, it is the command Evaluate that is responsible for
> inlining, making the size of the compiled code grow with NN and
> impossibility to compile in C. However, the program compiled with
> Mathematica runs fast.
>
> Removing Evaluate makes the compiled code small and independent of NN,
> also compiling in C becomes possible. In this case, unfortunately, the
> program runs slowly.
>
> Dmitry
>
>
Most likely due to call backs to Mathematica, you could check that with
CompilePrint.
Oliver
Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Compilation: Avoiding inlining Oliver Ruebenkoenig <ruebenko@wolfram.com> - 2011-09-16 11:08 +0000
Re: Compilation: Avoiding inlining DmitryG <einschlag@gmail.com> - 2011-09-17 10:31 +0000
Re: Compilation: Avoiding inlining DmitryG <einschlag@gmail.com> - 2011-09-19 11:12 +0000
Re: Compilation: Avoiding inlining David Bailey <dave@removedbailey.co.uk> - 2011-09-20 10:08 +0000
Re: Compilation: Avoiding inlining DmitryG <einschlag@gmail.com> - 2011-09-21 09:41 +0000
Re: Compilation: Avoiding inlining DmitryG <einschlag@gmail.com> - 2011-09-22 11:34 +0000
csiph-web