When trying to perform matrix multiplication (let us say with fixed point), there are ways to minimize model area and complexity, specially when the model is huge. To explain the usage of "For-Each" subsystems, let us take a look at a 50x50 * 50x1 multiplication.
The above model represents matrix multiplication where the subsystem 'matrix_multiply' usually contains multiple "Product" blocks and "Accumulator" blocks to eventually form the desired output. Also, since the input is a matrix, we need to have some kind of selector logic to go through the matrix values one by one.
To enable some code/block reuse, we can use a "For-Each" subsystem. Consider the figure below:
For now, we transpose the first input to the matrix multiplication and vectorize it. The "For-Each" subsystem uses a partition width of 50, which effectively separates all the rows of the first input. This system also has a sharing factor of 50, set on it to share all instances of the "For-Each" subsystem. Below is the screenshot of how a For-Each subsystem will look like from inside.
Inside the "For-Each" subsystem, we perform a multiply and an accumulate. This system specifies a streaming factor of 50, so that each "For-Each" subsystem only has one "Multiplier" block. See the screenshot below on how to specify the streaming factor:
This method promotes reusability, reducing model complexity and very fast code generation as compared to using many "Multiplier" blocks. However, this approach is not suitable for use in a feedback loop.