[Numpy-discussion] Fast threading solution thoughts
Thu Feb 12 09:03:49 CST 2009
2009/2/12 David Cournapeau <firstname.lastname@example.org>:
> Matthieu Brucher wrote:
>> Sorry, I was refering to my last mail, but I sent so many in 5 minuts ;)
>> In C, if you have to arrays (two pointers), the compiler can't make
>> aggressive optimizations because they may intersect. With Fortran,
>> this is not possible. In this matter, Numpy behaves like C (everyone
>> heard about the different a[indices] += a[other_intersecting_indices]
>> issues), Matlab is more like Fortran.
> I think it is hard to know exactly, because we don't know how matlab is
> implemented. It is possible to handle special cases for non overlapping
> arrays in numpy, once you are in C; I believe there are many codepath
> which we could optimize aggressively, using openMP, SSE, etc... It is
> just a lot of work to do so manually, so the real problem is how this
> can be handled as generally as possible using a small core.
Indeed, Matlab may not benefit from this. At least, COW makes it
possible to optimize agressively. Then, it's a matter of implementing
the loops in C or Fortran (or to use C99 extensions and rely on the
compiler). In C89, you will have absolutely no benefit (because there
are no way you can tell the compiler that there is no aliasing), in
Fortran, it will be optimized correctly.
The problem with optimizing codepath is that you have to detect them.
On the other hand, if you implement a numpy compliant array that
explicitely forbids aliasing (you could add some additional tests to
ensure that the parents are different, or stuff like that), you can
make the compiler optimize the code better.
Information System Engineer, Ph.D.
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
More information about the Numpy-discussion