MathGroup Archive 2011

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

Search the Archive

Re: Parallelize vs Compile

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119380] Re: Parallelize vs Compile
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Wed, 1 Jun 2011 04:33:48 -0400 (EDT)

On 5/31/11 at 7:46 AM, ngoble at iwu.edu (Nicholas Goble) wrote:

>My code seems to run much more quickly when I only use Parallelize[]
>as compared to any combination of Parallelize and Compile.  Even
>when I compile into C using CompilationTarget->"C" and with
>Parallelization->True.

>I thought that compiling would always make a program in Mathematica
>run faster. Why does it slow down?  Is Parallelize always the most
>efficient?

No, compiling will not make any program faster in Mathematica
and Parallelize will not always be the most efficient.

Compile seems to produce the most improvement for proceedural
code, i.e. code using something like a For loop. There are
numerous examples where Compile cannot compile the code and the
code runs uncompliled. My experience with Mathematica has been
whenever Complile does improve performance, most if not all of
that performance gain can be achieve by using functional
programming in an optimal manner.

Parallelize isn't always the most efficient since Mathematica
does not know how to parallelize some built-in functions. And in
these cases, there is overhead when attempting to use
Parallelize. Mathematica tries to parallelize the problem,
determines it cannot then runs the problem on a single core normally.

Both Compile and Parallelize can significantly improve
performance of some code. But neither can be guaranteed to do
so. Neither is a silver bullet. There really is no substitute
for understanding the problem you are trying to solve, how your
code runs and what resources Mathematica already has built-in
that are relevant to the problem you are trying to solve.



  • Prev by Date: Re: Controlling the scale of x-axis in ListPlot
  • Next by Date: Re: FixedPoint[Cos, 1.0]
  • Previous by thread: Re: Parallelize vs Compile
  • Next by thread: Mapping to Create Nested Loops