Login  Register

Re: Quantlib - multithreading

Posted by Luigi Ballabio on Dec 21, 2016; 7:37am
URL: http://quantlib.414.s1.nabble.com/Quantlib-multithreading-tp17934p17935.html

Yes, you do need to return something other than 0.  It should be a unique number for each thread.

Luigi


On Wed, Dec 21, 2016 at 10:06 AM Ghorpadkar, Suhas <[hidden email]> wrote:

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

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users