When you generate code from a model that contains an N-Ratio
Buffer block, you can configure the block to optimize memory usage or enable
concurrent execution.
Optimize Memory UsageIn the Simulink model, in the Solver pane under model settings, clear
the Allow tasks to execute concurrently on target parameter. To
enable this parameter, you must set the solver type to
Fixed-step. (since R2026a)
Generate
code from the model. The N-Ratio Buffer block optimizes the memory
used in the generated code and has the lowest possible latency for the
P- to NP-frame conversion. (since R2026a)
The following image illustrates how the input and output signals of the N-Ratio
Buffer block look when you clear the Allow tasks to execute
concurrently on target parameter.
Consider a ramp signal that produces one sample every 1 second starting at an initial
value of 1. The goal is to buffer this signal to a frame of 5 samples using the
N-Ratio Buffer block.
Plot the output signal in a time scope. In this mode, the memory occupied by the
generated code is optimized and the latency is very low.
Support for Concurrent ExecutionSelect the Allow tasks to execute
concurrently on target parameter. The N-Ratio Buffer block
supports multicore concurrent execution for code generated from a model containing this
block. In this mode, the block uses twice the memory for the internal buffer and
introduces additional latency to ensure thread safety. (since R2026b)
The following is an illustration of how the input and output signals of the
N-Ratio Buffer block look when you select the Allow tasks to
execute concurrently on target parameter.
Consider a ramp signal that produces one sample every 1 second starting at an initial
value of 1. Again, the goal is to buffer this signal to a frame of 5 samples using the
N-Ratio Buffer block.
In this mode, the block initializes the buffer with a frame of 2N
zeros, and the block begins buffering this frame at the start of the simulation. The
internal buffer uses twice the memory to ensure thready safety. Inputs to the block are
delayed by one buffer length or 5 samples. The block outputs the first frame of data at
t = 0, the next at t = 5, and so on. The output
rate matches the rate at which the block operates.
Plot the output signal in a time scope. In this mode, the latency equals the input
frame size.
Compare both the signals in the time scope. The signal generated with concurrency
disabled has lower latency and the signal generated with concurrency enabled has higher
latency.