QuantLib has great facilities for Monte-Carlo pricing engines, classes McSimulation and MonteCarloModel do a lot of work. But they do it in a single thread. What is best way to introduce parallel run in my custom engine (inherited from McSimulation class, as it is done for some instruments in QuantLib)? Now I see 2 options
- Use QuantLib routines as they are present, and handle multiple deals in parallel.
2.1 Make a subclass of MonteCarloModel and overwrite addSamples: insert there OpenMP code
2.2 My engine is already a subclass of McSimulation (I overwrite timeGrid, pathGenerator, pathPricer), I will also overwrite "calculate" - I will copy its current code, but replace instantiation of MonteCarloModel with my implementation.
I don't like neither first, nor second options. The first doesn't allow me to price a single deal quickly, the second makes me in trouble in case of amendments in classes MonteCarloModel and McSimulation in QuantLib distributive.