Python: Make algebra faster by using pool of vectors
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
DOLFIN |
Invalid
|
Wishlist
|
Unassigned |
Bug Description
In Python, the natural way to write matrix algebra involves a lot of temporary vector creation. By implementing a pool of vectors, I see a 15-20% performance improvement in a matrix-algebra heavy workload. The basic idea is to add a method to the GenericMatrix interface (Python only, probably). Then Matrix.__mul__ (and everywhere else a vector is needed) can use this method whenever they need to create a vector, and they are transparently re-used whenever they go out of scope.
@vec_pool
def create_vec(self, dim=1):
vec = dolfin.Vector()
return vec
The implementation of the vec_pool decorator is found here: http://
(code copyright me, LGPL or whatever you prefer.)
Changed in dolfin: | |
importance: | Undecided → Wishlist |
Changed in dolfin: | |
status: | New → Invalid |
Looks like a nice thing to have but I am not sure it is appropriate to expand DOLFIN with this functionality. It would be more natural to extend libraries using this, such as cbc.block, for this functionality.
Also, using:
D = A.copy()
A += B
instead of:
D = A+B
In this particular case it does not matter but in general it will.
Johan