My current task is to optimise a Monte Carlo Simulation that calculates Capital Adequacy figures by region for a set of Obligors.
It is running about 10 x too slow for where it will need to be in production and number or daily runs required. Additionally the granularity of the result figures will need to be improved down to desk possibly book level at some stage, the code I've been given is basically a prototype which is used by business units in a semi production capacity.
The app is currently single threaded so I'll need to make it multi-threaded, may look at ThreadPool or the Microsoft Parallels library but I'm constrained to .Net 2 on the server at this bank so may have to consider this guy's port http://www.codeproject.com/KB/cs/aforge_parallel.aspx
am trying my best to get them to upgrade to .net 3.5 SP1 but it's a major exercise in an organisation of this size and might not be possible in my contract time frames.
I've profiled the app using the trial of dottrace (http://www.jetbrains.com/profiler
) any other good profilers people know of? free ones?
A lot of the execution time is spent generating uniform random numbers and then translating this to a normally distributed random number, they are using a c# mersenne twister implementation not sure where they got it or if it's the best way to go about this (or best implementation) to generate the uniform random numbers, then this is translated to a normally distributed version for use in the calculation (haven't delved into the translation code yet).
Also has anyone used:
(c# port of quantlib)
Any alternatives you know of?
I'm a c# developer so would prefer c#, but a wrapper to c++ shouldn't be a problem should it? maybe even faster leveraging the the c++ implementations. Am thinking some of these libraries will have the fastest method to directly generate normally distributed random numbers, without the translation step. Also they may have some other functions that will be helpful in the subsequent calculations.
Also the box this is on is a quad core Opteron 275, 8GB memory but Windows Server 2003 Enterprise 32 bit, should I advise then to upgrade to a 64 bit OS ? any links to articles supporting this decision would really be appreciated.
Anyway any advice, help you may have is really appreciated.
I'm looking for experts to weigh in on the best way to:
- profile this
- take this from single threaded to multithreaded, whether to go for ThreadPool, some Parallel library...
- best way to generate normally distributed random numbers enmass and consume by the monte carlo simulation
- any other architechural considerations I should be thinking about