What architectures or design patterns are suitable for this application?

I am studying architecture for creating a C ++ application to handle multiple inputs simultaneously in different cores. Each input is processed simultaneously in one core. Each process on the core is handled by the same filters. For example: filter1.apply (), filter2.apply () and filter3.apply (). The processes are illustrated in 4 cores for 4 inputs, as shown below:

[core 1] [core 2] [core 3] [core 4]
   | | | |     
   Vvvv
  input1 input2 input3 input4
   | | | |    
   Vvvv 
 filter1 filter1 filter1 filter1
   | | | |    
   Vvvv 
 filter2 filter2 filter2 filter2
   | | | |    
   Vvvv 
 filter3 filter3 filter3 filter3
   | | | |    
   Vvvv 
 output1 output2 output3 output4

I do not know which architecture or design template is suitable for this. It would be great if you would give me some artifacts (documents or sample application) to read further.

Thanks in advance.

+5
source share
2 answers

. . TBB PPL. concurrency . , concurrent_vector, vector, , parallel_for_each, .

concurrent_vector<output> outputs;
std::vector<input> inputs;
parallel_for_each(inputs.begin(), inputs.end(), [](input& input) {
    outputs.push_back(filter3(filter2(filter1(input))));
});
+3

, " " . , :

std::vector<filter> filters;

std::for_each(filters.begin(), filters.end(), [input&](f&){f.apply(input);});

====================

, . /del .

:

class YourCore {
public:
    void add_filter(const filter& f) {m_filters.add(f);}
    // void del_filter(int index);
    // void del_filter(by name or UID, so change vector to map or unordered_map);
private:
    std::vector<filter> m_filters;
};
0

All Articles