omp target data

Creates a device data environment by making a mapping of variables from the host to the target device.


#pragma omp target data [clause, clause, ...]




Can be zero or more of the following clauses:

  • device(integer-expression)

  • if(scalar-expression)

  • map([map-type:] list)


The target data construct defines a mapping from data on the host to data on the device. The mapping is defined by one or more map clauses. The map-type may be any of the following:

  • alloc

    A new variable with an undefined value that corresponds to each list item created on the device.

  • to

    A new variable corresponding to each list item is created on the device, initialized from the list item on the host.

  • from

    The value of the device's version of each list item is copied back from the device to the host.

  • tofrom

    A variable initialized from the variable on the host that corresponds to each list item is created on the device. The variable on the device at the end of the target region is then copied back to the variable on the host.

The following example demonstrates how to use this pragma to map to the values of a, b, and c to the device, perform some computation, and then assign values to e and f. At the end of the target data structured block, the values of e and f are copied back to the host.


#pragma omp target data map(to:a,b,c) map(from:e,f) {
  #pragma omp target { e = f(a,b,c); }
  #pragma omp target { f = g(a,b,c); }
For more complete information about compiler optimizations, see our Optimization Notice.