[Openmp-commits] [PATCH] D81054: [OpenMP] Introduce target memory manager

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Nov 3 11:29:12 PST 2020

protze.joachim added a comment.

I tested this with older clang releases (at least back to clang 9.0) and could reproduce the assertion. The error doesn't seem to be related to this patch, but the test just reveals the issue.

I could reduce the issue to:

  #include <omp.h>
  #include <cassert>
  #include <iostream>
  #define N 10
  int main(int argc, char *argv[]) {
  #pragma omp parallel for num_threads(4)
    for (int i = 0; i < 16; ++i) {
      int buffer[N];
      printf("i=%i, n=%i, buffer=%p\n",i,N,buffer);
  #pragma omp critical
  #pragma omp target teams distribute parallel for              \
      map(from                                                  \
          : buffer)
      for (int j = 0; j < N; ++j) {
        buffer[j] = i;
      for (int j = 0; j < N; ++j) {
        if(buffer[j] != i){
          printf("buffer[j=%i]=%i != i=%i, buffer=%p\n",j,buffer[j],i,buffer);
          assert(buffer[j] == i);
    std::cout << "PASS\n";
    return 0;

So I think, that the `map(from)` fails when executed from multiple threads. The issue goes away, if the initial test is executed with OMP_NUM_THREADS=1. Adding the critical does not solve the issue. So, I don't think that a race in libomptarget is causing the issue.

  rG LLVM Github Monorepo



More information about the Openmp-commits mailing list