Hi all,
I have carried out some code profiling on the new LFM implementation. (ratchet cap pricing using 3 factors) Results showed that about 38% of the computation time was spend for dynamic memory allocation (the disposable trick saves some of them but not all of them, because a time step computation requires 41 dynamic allocations !). I have removed all these memory operations by passing a reference toward the result instead of returning it eg:
Existing code: Disposable<Array> LiborForwardModelProcess::drift(Time t, const Array& x)
My code: void LiborForwardModelProcess::drift(Time t, const ublas::vector<Real>& x, ublas::vector<Real>& result )
This had improved speed by the expected extent with VC++ 2003 but only by 22% with gcc. The remaining time consuming operations being linear algebra operations, I have also replaced the existing Matrix/Vector implementation by the boost uBlas library. This gave pretty good results, indeed, all operations but matrix*scalar operation are greatly accelerated. I removed these operations by embedding them in procedures as follows:
Existing code: lfmParam_->covariance(result, t, x); result*=dt;
My code: lfmParam_->covariance(result, t, x, dt); // dt product is done inside
Finally the overall gain of speed due to these changes is around 50% with both VC2003 and gcc. I'm considering to implement these changes for the whole QuantLib, but before doing so I would like to know your opinion on the subject. I do not see any other way to improve memory management, but I'm hesitating between two solutions for the uBlas migration :
Embedding all uBlas code in the existing Array and Matrix classes. The main advantage is that no other file would be altered. However it seems really tedious to expose all the nice features of uBlas using this architecture.
Replacing completely all Array and Matrix in the QuantLib code.
I tend to prefer the second solution because it is much neater in my opinion even if it is not the simplest one in the short run. I'm aware that uBlas is not the most efficient linear algebra library available, however profiling shows that it is sufficient for the LFM case (sheer linera algebra operations accounts for a small part of the computation time). More complex operations can be performed using ATLAS through uBlas bindings.
Any suggestion/advice are more than welcome.
Thanks for your attention,
best regards,
François
| Free forum by Nabble | Edit this page |