I am researching for an architecture for creating an application in C++ to process multiple inputs at the same time in different cores. Each input is processed in a single core simultaneously. Each of the process on a core, the same filters will be processed through. For example: filter1.apply(), filter2.apply() and filter3.apply(). The processes are illustrated for 4 cores for 4 inputs as below:
[core 1] [core 2] [core 3] [core 4] | | | | V V V V input1 input2 input3 input4 | | | | V V V V filter1 filter1 filter1 filter1 | | | | V V V V filter2 filter2 filter2 filter2 | | | | V V V V filter3 filter3 filter3 filter3 | | | | V V V V output1 output2 output3 output4
I dont know which architecture or design pattern is suitable for this. It would be great if you give me some artifacts (documents or sample application) to read further.
Thanks in advance.
Usually thread pools are used to implement such designs. They scale virtually infinitely for independent processes. You can find easy implementations in TBB and PPL. They offer concurrency-related versions of many Standard algorithms and containers. For example, in this sample I’ve used
concurrent_vector, which is avector-like container which can be safely mutated from several threads concurrently, andparallel_for_each, which runs the function on many threads at once.