Skip to content

[OpenMP] 'omp unroll partial' loop generates too many iterations #55236

@mikerice1969

Description

@mikerice1969

In the following test the loop executes one more time than expected:

void unroll_partial_remainder(int *A)
{
    #pragma omp parallel for
    #pragma omp unroll partial(4)
    for (int i = 0; i < 12; ++i)
        A[i] = i;
}

#include <stdio.h>
#include <assert.h>

int main() {

  int A[24];
  for(int i = 0; i<24; i++){ A[i]=0; }

  // write 12 elements 0 thru 11.
  unroll_partial_remainder(A);

  // Off by one?
  assert(A[12] == 0);

  return 0;
}
$ clang -fopenmp -fopenmp-version=51 u.c && ./a.out
a.out: u.c:21: int main(): Assertion `A[12] == 0' failed.
Aborted (core dumped)

$ clang --version
clang version 15.0.0 (git@github.com:llvm/llvm-project ef87865b98fa25af1d2c045bab1268b2a1503374)
Target: x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions