c++cparallel-processingopenmpoffloading

How to correctly use the update() clause in OpenMP


I have a program that was originally being executed sequentially and now I'm trying to parallelize it via OpenMP Offloading. The thing is that when I use the update clause, depending on the case, if I include the size of the array I want to move it returns an incorrect result, but other times it works. For example, this pragma:

#pragma omp target update from(image[:bands])

Is not the same as:

#pragma omp target update from(image)

What I want to do is move the whole thing. Suppose the variable was originally declared in the host as follows:

double* image = (double*)malloc(bands*sizeof(double));

And that these update pragmas are being called inside a target data region where the variable image has been mapped like this:

#pragma omp target data map(to: image[:bands]) {
 // the code
}

I want to move it to the host to do some work that cannot be done in the device. Note: The same thing may happen with the "to" update pragmas, not only the "from".


Solution

  • Well I don't know why anyone from OpenMP answered this question, as the answer was pretty simple (I say this because they don't have a forum anymore and this is supposed to be the best place to ask questions about OpenMP...). If you want to copy data dynamically allocated using pointers you have to use the omp_target_memcpy() function.