Intel® C++ Compiler Classic Developer Guide and Reference

ID 767249
Date 12/16/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

omp simd early_exit

Extends #pragma omp simd, allowing vectorization of multiple exit loops.

Syntax

#pragma omp simd early_exit

Description

Extends #pragma omp simd allowing vectorization of multiple exit loops. When this clause is specified:

  • Each operation before last lexical early exit of the loop may be executed as if early exit were not triggered within the SIMD chunk.
  • After the last lexical early exit of the loop, all operations are executed as if the last iteration of the loop was found.
  • Each list item specified in the linear clause is computed based on the last iteration number upon exiting the loop.
  • The last value for linear clauses and conditional lastprivates clauses are preserved with respect to scalar execution.
  • The last value for reductions clauses are computed as if the last iteration in the last SIMD chunk was executed up on exiting the loop.
  • The shared memory state may not be preserved with regard to scalar execution.
  • Exceptions are not allowed.

Examples

The following example demonstrates how to use this pragma.

In the following example, the pragma specifies that the vector execution of the for loop is safe even though the loop may exit before the loop upper bound condition j < ub becomes false. Suppose j1 is the smallest j, between lb and ub, such that j satisfies b[j] <= 0 . If j1 and j1+1, j1+2, … are within the same (last) SIMD chunk, read of b[j1], b[j1+1], b[j1+2], … and the subsequent evaluation of <= 0 will happen unconditionally, unlike the scalar execution of the same loop. Safety of such vector evaluation is programmer's responsibility. If necessary, simdlen() clause can be used to control the SIMD chunk size.

void foo(int lb, int ub) {
  float a = 0;
  #pragma omp simd early_exit reduction(+:a)
      for(j=lb; j<ub; j++) { 
          if (b[j] <= 0 ) 
              break;
          a += b[j];
     } 
}