I am working on a custom MonteCarlo simulation and was trying to experiment with multiple threads.
I am aware that Quantlib as such is not thread safe. I have uncommented “define QL_ENABLE_SESSIONS” in userconfig.hpp
and have defined sessionId function at the beginning of my cpp file. I was trying to create QL objects such as YieldTermStructure handles and CalibratedModel inside the function that will called by each thread so that QL objects are not
shared by multiple threads and each has a copy of its own. This worked for my Model object but not for YieldTermStructure objects. I had to lock the critical section using mutex as below even though swapCurve and dividendCurve objects are thread local.
I do not understand why. May be I need to return something other than zero in my sessionId() function ?
std::lock_guard<std::mutex> lg(mapMutex);
{
Dr_t = swapCurve->discount(t);
Dr_T = swapCurve->discount(t + dt);
Dq_t = dividendCurve->discount(t);
Dq_T = dividendCurve->discount(t + dt);
}
Thank you.
............................................................................
For further important information about AllianceBernstein please click here
http://www.abglobal.com/disclaimer/email/disclaimer.html
Free forum by Nabble | Disable Popup Ads | Edit this page |