Serving the Quantitative Finance Community

 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

sitmo C++ parallel random engine

December 12th, 2013, 2:08 pm

Have you used PRNG in applications, e.g. MC on a multicore machine? And what's the best s/w architecture, e.g. usual loop (Clewlow-Strickland), producer-consumer, prefetching etc.? In the short-term I would like to call the PRNG from C#. All I need is 1 or two function to return a rng or a tuple of rng. I have an easier version of my lost in action MC101 in C#.
Last edited by Cuchulainn on December 11th, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

sitmo C++ parallel random engine

December 12th, 2013, 2:34 pm

Looks good. What I need to do is 1. Download your native C++ code (easy as Boost yes?)2. Create a Managed C++ wrapper class with a minimal interface to 13. Call 2 from MC in C#Note! I am more interested in accuracy of PRNG rather than possible latency overhead. MC is slow anyway, so it is not an issue at the moment.I suppose PRNG beats my simple-minded Box-Muller
Last edited by Cuchulainn on December 11th, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

sitmo C++ parallel random engine

December 12th, 2013, 2:59 pm

Quotethe minimal interface is probably seed() and operator()()?Excellent! that's fine.All your comments are crystal clear.
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

sitmo C++ parallel random engine

December 12th, 2013, 4:10 pm

I am writing up a chapter as we speak in preparation in het buitenland op korte termijn.I will post the summary soon.What is possible is a .NET assembly dll and C# developers can call your PRNG! Cool, yes?
Last edited by Cuchulainn on December 11th, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

sitmo C++ parallel random engine

December 12th, 2013, 4:39 pm

QuoteOriginally posted by: outrunYes cool! You could make a generic C++.wrapper temptatie van wrap *any* C++ random engine! C++11 has quite a few engines and all provide the same interface. Eg I'm currently checking if there are LDS random engines (Sobol, Fauré, Niedereitter), and if they can be cast into parallel independent stream concept.Yes, _but_ .NET generics<T> don't work with native C++ templates. But double is fine? QuoteSomeone found a bug in the discard() of my parallel rng. Here is new fixed version (prng_engine.hpp). I've also finalized the last bits to make it a fully compliant C++11 engine.1. how can I get this HTML code to be C? zip is better?2. does it work with 'old' C++ compilers? I have several machines but here I have VS2010. There are still folk VC++ 6,0, 2005 ....
Last edited by Cuchulainn on December 11th, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20253
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

sitmo C++ parallel random engine

December 12th, 2013, 6:10 pm

QuoteOriginally posted by: outrunHere is the hpp source fileGot it! Right mouse click and SAVE option
Last edited by Cuchulainn on December 11th, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
MiloRambaldi
Posts: 1
Joined: July 26th, 2010, 12:27 am

sitmo C++ parallel random engine

February 4th, 2014, 2:11 am

QuoteOriginally posted by: outrunYes, here is a very simple C++11 version that has 128 threads. 1. Each thread initializes a local rng engine with a unique seed (based on incrementing a global counter)2. then each thread does it main job: it accumulated the results of 1.000.000 draws from the engine3. then -as each thread finishes- it updates a global result aggregationStep 1 and 3 use a mutex to prevent lockingoutput:128 threads generated 128000000 random numbers, the sum of them is 274892645070220693 code:Very nice! But one minor point: I don't think this is a "legitimate" way to do parallel random number generation, unless your PRNG has some special property that makes it safe. I have read papers about simulations giving completely false results by parallelizing MT with consecutive seeds. (This has been discussed in this forum. Apparently it was some sort of famous "catastrophe".) Also: Do you know if there is any open source parallel MC that takes advantage of GPU computing?