#pragma omp target update

Purpose

The omp target update directive makes the list items in the device data environment consistent with the original list items by copying data between the host and the device.

The direction of data copying is specified by motion-type.

Syntax

Read syntax diagramSkip visual syntax diagram
                                 .-+---+------.   
                                 | '-,-'      |   
                                 V        (1) |   
>>-#--pragma--omp target update----clause-----+----------------><

Notes:
  1. You must specify at least one motion-type clause.

Parameters

clause is any of the following clauses:
motion-type(list)
Synchronizes the values of the list items between the host and device data environment. The motion-type can be from or to. A list item can only appear in a from or to clause, but not both. The copying occurs to each list item that has storage on the device data environment or each original list item on the host data environment according to the value of motion-type:
  • If motion-type is from, the value of each list item is copied from the corresponding item on the device to the original list item on the host.
  • If motion-type is to, the value of each list item is copied from the original list item on the host to the corresponding item on the device.
If the corresponding list item is not present in the device data environment, the original list item does not change.
device(exp)
Creates the data environment on the device of ID exp. The integer expression exp must evaluate to a non-negative integer value less than the value of omp_get_num_devices(). You can specify at most one device clause.
if([target:]exp)
When the if clause is specified and the scalar expression exp evaluates to zero, no copying of data occurs. You can specify at most one if clause.

Examples

int main (){
   int x;
   x = 0;
   #pragma omp target data map(tofrom: x) 
//  A device data environment is created, and x in the device data environment 
//  is initialized. See status 1.
   {  
      x = 10; 
// See status 2.
      #pragma omp target update to(x) 
// See status 3.
   }
}
You can find the variable values for each status in the following table.
Table 1. Variable values on the host and device
Status Value of x on the host Value of x on the device
Status 1 0 0
Status 2 10 0
Status 3 10 10


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us