Tag Archives: design pattern

Monoid design pattern to Fastflow multihreading C++ library for high speed trading like HFT

Monoid design pattern to Fastflow multihreading C++ library for high speed trading like HFT

As I started digging further into Monoid pattern thing, it was promising with these articles:

https://www.fpcomplete.com/blog/2012/09/functional-patterns-in-c

https://isocpp.org/blog/2013/05/functional-patterns-in-c-bartosz-milewski

https://www.quora.com/Why-is-monad-more-famous-than-functor-and-applicative-functor

One of these links does have source code demo. To be honest, the code was not commented or documented at all which means I cannot go beyond than looking at. It did not compile with my GCC 4.9 but I have no patience to figure it out from there.

Check out the history here:

C++ event driven meta programming libraries

Or watch the video here:

Event driven C++ Metaprograming

As these links base the methodology off Haskell, there are a number of reasons which this functional programming language could be as fast as C or C++. Here are some other comparisons:
http://lambda.jstolarek.com/2013/04/haskell-as-fast-as-c-a-case-study/

https://www.quora.com/Why-is-monad-more-famous-than-functor-and-applicative-functor

As I am no expert here, but it was recommended another multithreading library could handle the same performance using these Monoid design patterns. It does look promising but after some further digging, Intel TBB or Boost Futures came up. I think that is a yucky proposition when I knew about a faster (and easier) multi-threading library called Fastflow.
I took a look to see if it was abandoned. To my surprise, 2.1 just came out 2 days ago. Talk about perfect timing!

http://sourceforge.net/projects/mc-fastflow/files/?source=navbar

There was a performance graph to show how Fastflow performs against other libraries. It seems to keep up with OpenMP which is the fastest one compared to CILK or TBB. Again, I am no expert here but I think it is worthy to revisit this multithreading library.

fastflow 236876

It is also comforting to know the FIX8 project chose FastFlow as well for concurrency which they claim their library is quite fast. Knowing all this with my revisit to both C++ on Linux, it might important to showcase my earlier on this library:

https://quantlabs.net/blog/?s=fastflow

Videos: https://www.youtube.com/user/quantlabs/search?query=fastflow

Keep your eyes peeled on more up to date topics on Fastflow

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Java design pattern for LMAX

Java design pattern for LMAX

Oldie but goldie (I think)

Thanks to NYC Contact for sending

http://martinfowler.com/articles/lmax.html

Join my FREE newsletter to learn more about how LMAX is technically run 

 

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Know your data structures, algorithms, design patterns and test case uses for any technical job interview!!

Know your data structures, algorithms, design patterns and test case uses for any technical job interview!!
This might not be quant related but if you are applying for any development type roles (name me a quant based position that is not), ensure you know the notes below.
Let me stress this (once again right), know these topics really well. I have done at least seven interviews which involve one hundred percent rate of design patterns. I was kind of dumbfounded on the level of detail interviewers go into on this. There are some great resources out there but it might be wise to pick up a copy of Gang of Four in Design Patterns. This seems to be to the bible in this arena. They also started the concept of this.
We were all taught data structures in our early years of computer science courses. You need to know these areas well too. Understood the logic and reasoning of why these data structures are used. Focus on the basic ones including stack, heap, singly and double linked list, binary search tree, and even graphs. Also understand the concept of the Big O algorithms which involved time and space complexity. A great site to learn this from is algolist.net. It has some great tutorials to have you understand this data structures with code snippets in both Java and C++.
Let’s get into the less talked about algorithms. Depending on the type of company you are applying to, I would recommend to learn the basics including Fibonacci, prime, factorial, and all the basic sorting algorithms. These include your typical sorting like bubble, selection, insertion, merge, and quick sort. Again know the time complexity of each sorting algorithm. A good explanation of this is found at Wikipedia.
Regardless of what level of position you are applying, be expected to answer questions on these above concepts. You should consider emphasizing your knowledge in design patterns if you are going for a senior role or even architect level.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

C# or Java Job Interview Question: Singleton design pattern source code sample which is thread safe

C# or Java Job Interview Question: Singleton design pattern source code sample which is thread safe

Below is a sample but we assume the Mutex locks are already defined. See my previous posts on multithreading for an example how to do to this.

#include
using namespace std;

template
class Lock
{
public:
Lock( T& t )
: t_(t)
, locked_(true)
{
t_.Lock();
}

~Lock()
{
Unlock();
}

void Unlock()
{
if( locked_ )
{
t_.Unlock();
locked_ = false;
}
}

private:
T& t_;
bool locked_;
};

template
class Singleton
{
public:
T* Instance()
{
if(!instance)
{

//use pthread_mutex_lock?
Lock l(m);
//Lock mutex; //-+

if(!instance) // Double check
{
instance = new T;
}
}

return instance;
}
private:
Singleton(){}
~Singleton(){}
static T *instance;
};

int main() {
return 0;
}

For C# with no multi threading:
Implement singleton
In C#:
public sealed class Singleton //sealed prevents class from derived so like final in Java
{
private static Singleton s_instance = new Singleton();
// Make the constructor private so that no new instance can be generated from outside
private Singleton() {}
public Singleton GetInstance()
{
return s_instance();
}

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

C++ Job Interview Question: Singleton design pattern source code sample which is thread safe

C++ Job Interview Question: Singleton design pattern source code sample which is thread safe
Below is a sample but we assume the Mutex locks are already defined. See my previous posts on multithreading for an example how to do to this.

#include
using namespace std;

template
class Lock
{
public:
Lock( T& t )
: t_(t)
, locked_(true)
{
t_.Lock();
}

~Lock()
{
Unlock();
}

void Unlock()
{
if( locked_ )
{
t_.Unlock();
locked_ = false;
}
}

private:
T& t_;
bool locked_;
};

template
class Singleton
{
public:
T* Instance()
{
if(!instance)
{

//use pthread_mutex_lock?
Lock l(m);
//Lock mutex; //-+

if(!instance) // Double check
{
instance = new T;
}
}

return instance;
}
private:
Singleton(){}
~Singleton(){}
static T *instance;
};

int main() {
return 0;
}

C++ Job Interview Question: Singleton design pattern source code sample which is thread safe
Below is a sample but we assume the Mutex locks are already defined. See my previous posts on multithreading for an example how to do to this.

#include
using namespace std;

template
class Lock
{
public:
Lock( T& t )
: t_(t)
, locked_(true)
{
t_.Lock();
}

~Lock()
{
Unlock();
}

void Unlock()
{
if( locked_ )
{
t_.Unlock();
locked_ = false;
}
}

private:
T& t_;
bool locked_;
};

template
class Singleton
{
public:
T* Instance()
{
if(!instance)
{

//use pthread_mutex_lock?
Lock l(m);
//Lock mutex; //-+

if(!instance) // Double check
{
instance = new T;
}
}

return instance;
}
private:
Singleton(){}
~Singleton(){}
static T *instance;
};

int main() {
return 0;
}

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!