Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Compiling in Mathematica 8

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115053] Re: Compiling in Mathematica 8
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Wed, 29 Dec 2010 05:59:49 -0500 (EST)


----- Original Message -----
> From: "DmitryG" <einschlag at gmail.com>
> To: mathgroup at smc.vnet.net
> Sent: Tuesday, December 28, 2010 5:52:14 AM
> Subject: [mg115020] Re: Compiling in Mathematica 8
> On 24 Dez., 04:12, DmitryG <einsch... at gmail.com> wrote:
> > I was pleasantly surprised by new features of Mathematica 8,
> > especially by the possibility to compile pieces of code that solve
> > the
> > speed issue that remained painful in previous versions of
> > Mathematica.
> > Now one can write efficient Monte Carlo or fractal routines in
> > Mathematica. Compilation can be done into Mathematica's native code
> > with speed increase by a factor of 50-100 or into a C code with a
> > much
> > larger speed gain, if a C compiler is installed on your computer.
> >
> > I have two practical questions.
> >
> > 1. What C compiler can be recommended for me as non-C-programmer to
> > install under Windows XP SP2? In the past I was using Microsoft C
> > compiler that, as my friends said, was much faster than the others.
> > Now, the current version of Microsoft C compiler requires SP3 to be
> > installed that I don't want. Also what kind of C compiler would do,
> > C
> > or C++?
> >
> > 2. What about compiling of Mathematica's own routines such as
> > NDSolve?
> > I believe constructions such as Compile[{arguments}, NDSolve[...]]
> > won't work. I have read in the help that NDSolve etc. decide
> > automatically if compilation has to be done. There are also options
> > such as Compile->True, and I have read that one can add //
> > Developer`PackedArrayQ at the end and if the output is True, the
> > command is compiled. I have tried this with NDSolve with both
> > Compile->Tr=
> ue and Compile->False inside and in all cases the output was False.
> >
> > So I suspect NDSolve is never compiled. This is a pity because I am
> > using NDSolve a lot and it works much slower than similar routines
> > written in C or Fortran.
> >
> > I would greatly appreciate advice from Wolfam stuff and members of
> > this group.

Much of NDSolve is implemented in C. As to why it might be slower than similar routines in other languages, you'd need to send specific examples to have any chance of an analysis. I could venture a guess that it is taking significant time in preprocessing e.g. to decide what method to use, or is getting bogged down in small steps or other hard error control tactics for a numerically challenging problem, or ....


> > Happy holidays for all,
> >
> > Dmitry
> 
> I have made speed measurements on NDSolve and found that NDSolve with
> the option Compile->False works by a factor about 3 slower than
> NDSolve with Compile->True or without this option at all. The effect
> of compilation is thus detectable but it is much smaller than the
> effect of compilation of user codes such as Do loops that speeds up
> the calculation by a factor about 50, if the default compilation into
> Mathematica's own code is used.
> 
> Why compilation of NDSolve is so inefficient? Can NDSolve be compiled
> into C?
> 
> Dmitry

As I mentioned, much of it (in particular most time consuming parts) are in C already. Use of Compiled->True means, I think, that function and derivative evaluations can proceed with compiled code. That was apparently the major bottleneck, hence your factor of three.

The Advanced Tutorial documentation for NDSolve might have other approaches for further speed gain. This would be problem specific though. See Documentation Center > tutorial/NDSolveOverview for a start on this.

Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: newbie list question
  • Next by Date: Re: newbie list question
  • Previous by thread: Re: Compiling in Mathematica 8
  • Next by thread: Use of Mathematica