|
From:
<fra...@ya...> - 2006-06-22 15:07:50
|
Hi all, =20 I have carried out some code profiling on the new LFM implementation. (ratc= het cap pricing using 3 factors) Results showed that about 38% of the comp= utation time was spend for dynamic memory allocation (the disposable trick = saves some of them but not all of them, because a time step computation req= uires 41 dynamic allocations !). I have removed all these memory operation= s by passing a reference toward the result instead of returning it eg: =20 =20 Existing code: Disposable<Array> LiborForwardModelProcess::drift(Time t, c= onst Array& x) =20 My code: void LiborForwardModelProcess::drift(Time t, const ublas::vect= or<Real>& x, ublas::vector<Real>& result ) =20 This had improved speed by the expected extent with VC++ 2003 but only by 2= 2% with gcc. The remaining time consuming operations being linear alge= bra operations, I have also replaced the existing Matrix/Vector implementat= ion by the boost uBlas library. This gave pretty good results, indeed, all = operations but matrix*scalar operation are greatly accelerated. I removed t= hese operations by embedding them in procedures as follows: =20 Existing code: lfmParam_->covariance(result, t, x); result*=3Dd= t; =20 My code: lfmParam_->covariance(result, t, x, dt); // dt product is do= ne inside =20 Finally the overall gain of speed due to these changes is around 50% with b= oth VC2003 and gcc. I'm considering to implement these changes for the w= hole 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 opinio= n 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 profil= ing shows that it is sufficient for the LFM case (sheer linera algebra oper= ations accounts for a small part of the computation time). More complex ope= rations can be performed using ATLAS through uBlas bindings. Any suggestion/advice are more than welcome. =20 Thanks for your attention,=20 best regards, =20 Fran=E7ois |