[IPOL discuss] python as an addition to c++
Miguel Colom
colom at cmla.ens-cachan.fr
Wed Jun 5 20:22:11 CEST 2013
Quoting Ofer <ofer.bartal at weizmann.ac.il>:
> Matlab and python are both effective tools for fast prototyping, python
> being the free choice of the two. For this reason, perhaps is would be a
> language worthwhile to learn? :)
I think you mentioned a key word: *prototype*.
A parallelized C/C++ as those we have in the current IPOL publications
are complete programs that once compiled run at their fastest speed
using CPU native instructions.
They're only limited by the power of the machine where the run on.
Therefore, they're really a proof of how well and how much do a given
algorithm with the hardware nowadays. And I think this is really
valuable.
A prototype just shows that a program runs in a very controlled
environment. The best example is a Matlab program, that runs inside a
framework and can't live without it. And sometimes it's not clear what
it's really doing!
A Python program is different, since it doesn't need a framework to
work, but a virtual machine to runs its bytecode. This decoupling of
the CPU instructions and the bytecode adds up a level of indirection
and causes the Python programs to run much slower than a C/C++ program.
Of course, when a function of numpy is called, the speed is similar to
that of a C/C++ program, but only because the function numpy function
is written in C/C++.
But accessing matrix elements (say, to compare patches of an image)
can be extremely slow if it's done directly in Python, because:
- The virtual machine has to check the types of the variables.
- The bounds of the arrays are checked at each access.
There're ways to optimize Python code and it's also possible to use
Cython to translate some code into C/C++ loops and structures. Even
though, I think that this adds even more dependencies to the code, and
that's what we want to avoid.
After all that, I have to say that Python is, after all, my very
favorite language. But maybe not for IPOL...
More information about the discuss
mailing list