Use the optimal vector size depending on your target system as the vector size in order to program the most efficient code possible.
For target systems whose computer architecture is generally suitable for vector processing, we do not recommend using vectors of arbitrary size. There is an optimal vector size depending on the type of data processing of the processor. Vectors that are declared with this array size are processed as quickly as possible. Vectors that are declared as a larger array do not have an advantage in speed. Vectors that are declared as smaller arrays do not take full advantage of the processor's capabilities.
You can query the optimal size at runtime. You can find the information in the constants
Constants.vcOptimalREAL
(for vectors with REAL
elements) and Constants.vcOptimalLREAL
(for vectors with LREAL
elements). The constants have the LREAL
data type. If a constant returns the value 1
as the optimal value, then this means that accelerated vector processing is not available
for the target system.
Example
PROGRAM PLC_PRG VAR iOVS_REAL : INT; // Optimal vector size for REAL eleements iOVS_LREAL : INT; // Optimal vector size for LREAL eleements END_VAR iOVS_REAL := Constants.vcOptimalREAL; iOVS_LREAL := Constants.vcOptimalLREAL;
An application that is loaded on the CODESYS Control Win V3 x64 target system returns the following values at runtime:
