# Multithreading Monte-Carlo pricing in QuantLib for a single product

I've been actively using QuantLib for structured product pricing using Monte Carlo. Due to the fact that at a great deal of paths are often needed and one needs to speed up the calculation and all that, I find myself having to think about ways to multithread the pricing. By profiling the code I obviously noted that the biggest bottleneck is not the product construction but running the Monte Carlo simulation.

Therefore let's suppose that if I needed 300k paths to somewhat accurately price the product, can I just spawn 10 threads, build the product in each one of them and make each thread calculate the NPV of the product with 30k paths all whilst using different seeds and then average the 10 different NPVs together?

• even if you use different seeds, there's no guarantee that the generated sequences won't overlap. If you're willing to change the engine code so that you can pass the relevant parameters, a safer option would be to use a low-discrepancy generator such as Sobol, which has the ability to skip ahead in the sequence. This way, you could tell each generator to start at the correct place in the sequence of $2^N-1$ samples you'll use.