Main Content

coder.gpu.iterations

Pragma that provides information to the code generator for making parallelization decisions on variable bound loops

Description

example

coder.gpu.iterations(AVG_NUM_ITER)pragma can be used to specify the average number of iterations (AVG_NUM_ITER) for a variable-boundfor-loop that immediately follows it. This value is used to provide heuristics towards making parallelization decisions for imperfect loops. This pragma does not affect fixed-boundfor-loops.

This is a code generation function. It has no effect in MATLAB®.

Examples

阿胶pse all

This example shows how to use thecoder.gpu.iterationspragma to augment information used by the code generator to make parallelization decisions.

Consider the following MATLAB entry-point functionmyFuncontaining a simple nested loop.

function[a, c] = myFun(b, N1) coder.gpu.kernelfun(); a = coder.nullcopy(zeros(1, N1)); c = coder.nullcopy(b);fori = 1:N1% Loop1a(i) = 1;forj = 1:20% Loop2c(i,j) = 2 * b(i,j);endendend

In this case,Loop 1is an imperfect loop, preventing the code generator from parallelizing the outer loopLoop 1.

修改的入口点函数使用coder.gpu.iterationspragma to inform the code generator the average number of iterations that the loop is expected to execute.

function[a, c] = myFun(b, N1) coder.gpu.kernelfun(); a = coder.nullcopy(zeros(1, N1)); c = coder.nullcopy(b); coder.gpu.iterations(25);% AVG_NUM_ITERfori = 1:N1% Loop1a(i) = 1;forj = 1:20% Loop2c(i,j) = 2 * b(i,j);endendend

Loop 1 is parallelized when theAVG_NUM_ITER > 20(Loop2 bound) regardless of the value ofN1.

Input Arguments

阿胶pse all

Specify the average number of iterations (AVG_NUM_ITER) for a variable-boundfor-loop that immediately follows thecoder.gpu.iterationspragma.

Version History

Introduced in R2019a