Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.
2159 Discussions

OpenMP offload quirk (maybe problem if mapping const array?)

CFR
New Contributor II
1,097 Views

Lenovo T570, Ubuntu 18.04.4, icpc (ICC) 2021.1 Beta 20200602

user@t570:~/OneAPI/OMP$ cat bug2.cpp

#include <omp.h>
#include <cstdio>
void
fn(const unsigned int data[7], int n)
{
#pragma omp target teams distribute parallel for map(to:data[:7])
  for (int i=0; i<n; i++) printf("data[%d] = %d\n", i, data[i]);
}

const unsigned int data[7] = {1,2,3,4,5,6,7};
int
main(int argc, char *argv[])
{
  fn(data, 7);
}
user@t570:~/OneAPI/OMP$ make bug2
icpc -std=c++17 -O3 -o bug2 bug2.cpp -qnextgen -fiopenmp -fopenmp-targets=spir64
user@t570:~/OneAPI/OMP$ ./bug2
Abort was called at 719 line in file:
../neo/level_zero/core/source/device/device_imp.cpp
Aborted (core dumped)

If "data" in not declared "const" then things are fine:

user@t570:~/OneAPI/OMP$ cat bug2.cpp

#include <omp.h>
#include <cstdio>
void
fn(const unsigned int data[7], int n)
{
#pragma omp target teams distribute parallel for map(to:data[:7])
  for (int i=0; i<n; i++) printf("data[%d] = %d\n", i, data[i]);
}

unsigned int data[7] = {1,2,3,4,5,6,7};
int
main(int argc, char *argv[])
{
  fn(data, 7);
}
user@t570:~/OneAPI/OMP$ make bug2
icpc -std=c++17 -O3 -o bug2 bug2.cpp -qnextgen -fiopenmp -fopenmp-targets=spir64
user@t570:~/OneAPI/OMP$ ./bug2
data[0] = 1
data[1] = 2
data[2] = 3
data[3] = 4
data[4] = 5
data[5] = 6
data[6] = 7

 I'm not sure why "data" can't be const in the above, but in any case, the diagnostic provides no insight into the problem.   (It took me quite a while to pare down my application and "fuzz" my code before I was able to attribute the error to the "const" so maybe this will help someone else Googling for this error in the future.)

0 Kudos
1 Solution
AbhishekD_Intel
Moderator
1,076 Views

Hi,

 

From the code sample, you have provided we can see that you want to access a constant array for offload. For handling constant array you can try declaring them inside the main() so that you can use it for offload. Please refer to the below code for more details.

 

 

#include <omp.h>
#include <cstdio>

void fn(const unsigned int data[7], int n){

#pragma omp target teams distribute parallel for map(to:data[:7])
  for (int i=0; i<n; i++) printf("data[%d] = %d\n", i, data[i]);

}

int main(int argc, char *argv[]){

  const unsigned int data[7] = {1,2,3,4,5,6,7};
  fn(data, 7);
  return 0;

}

 

 

This will solve your problem of accessing constants array. Please try the code and let us know if it is working for you.

 

 

Warm Regards,

Abhishek

 

View solution in original post

0 Kudos
5 Replies
AbhishekD_Intel
Moderator
1,077 Views

Hi,

 

From the code sample, you have provided we can see that you want to access a constant array for offload. For handling constant array you can try declaring them inside the main() so that you can use it for offload. Please refer to the below code for more details.

 

 

#include <omp.h>
#include <cstdio>

void fn(const unsigned int data[7], int n){

#pragma omp target teams distribute parallel for map(to:data[:7])
  for (int i=0; i<n; i++) printf("data[%d] = %d\n", i, data[i]);

}

int main(int argc, char *argv[]){

  const unsigned int data[7] = {1,2,3,4,5,6,7};
  fn(data, 7);
  return 0;

}

 

 

This will solve your problem of accessing constants array. Please try the code and let us know if it is working for you.

 

 

Warm Regards,

Abhishek

 

0 Kudos
CFR
New Contributor II
1,072 Views

You're really not defining a global constant anymore, but that does remove the error.

Thanks.

0 Kudos
AbhishekD_Intel
Moderator
1,026 Views

Hi,

 

If you want to access a global constant array then please change the backend to the OpenCL this will resolve your error and you can execute your code with a global constant array.

Please set the following environment variable followed by compiling and running your application.

 

 

export LIBOMPTARGET_PLUGIN=OPENCL

 

 

And let us know if it resolves your issue.

 

 

Warm Regards,

Abhishek

 

0 Kudos
AbhishekD_Intel
Moderator
1,009 Views

Hi,


Please give us an update on your issue. We hope its resolved now.


Warm Regards,

Abhishek


0 Kudos
AbhishekD_Intel
Moderator
985 Views

Hi,


As your issue is resolved we are closing this thread. Please post a new thread if you have any issues.


Thank you


0 Kudos
Reply