Reason for use to declare target pragma in OpenMP

I wonder what is the reason for using the directive declare target

. I can just use target {, data} map (to/from/tofrom ...)

to indicate which variables should be used by the device. As far as functions are concerned, is it mandatory for a function called from scope target

declared as target? Suppose I have the following code:

int data[N];

#pragma omp target
{
    #pragma omp parallel for
    for (int i=0; i<N; i++)
        data[i] = my_function(i);
}

      

Is it required to wrap the my_function()

declaration / definition with declare target

?

+3


source to share


1 answer


In your example, the array data[N]

will map to the device at the start of each target region and not display at the end. In programs with multiple target scopes, it can be useful to display data[N]

only once when run using a directive declare target

.

As far as features are concerned, the OpenMP 4.0 specification is not entirely clear. He only says:

The declare target directive indicates that variables, functions (C, C ++, and Fortran), and subroutines (Fortran) are mapped to the device.



Thus, it does not explicitly prohibit calls to non-target functions from target areas and other target functions.

But I personally think it my_function

should be declared as a target. Otherwise, why was this pragma (for functions) introduced at all?

+1


source







All Articles