Data Environment
10. Data Environment#
The OpenMP data environment contains data attributes of variables and objects. Many constructs (such as parallel, simd, task) accept clauses to control data-sharing attributes of referenced variables in the construct, where data-sharing applies to whether the attribute of the variable is shared , is private storage, or has special operational characteristics (as found in the firstprivate, lastprivate, linear, or reduction clause).
The data environment for a device (distinguished as a device data environment ) is controlled on the host by data-mapping attributes, which determine the relationship of the data on the host, the original data, and the data on the device, the corresponding data.
DATA-SHARING ATTRIBUTES
Data-sharing attributes of variables can be classified as being predetermined , explicitly determined or implicitly determined .
Certain variables and objects have predetermined attributes. A commonly found case is the loop iteration variable in associated loops of a for or do construct. It has a private data-sharing attribute. Variables with predetermined data-sharing attributes cannot be listed in a data-sharing clause; but there are some exceptions (mainly concerning loop iteration variables).
Variables with explicitly determined data-sharing attributes are those that are referenced in a given construct and are listed in a data-sharing attribute clause on the construct. Some of the common data-sharing clauses are: shared, private, firstprivate, lastprivate, linear, and reduction.
Variables with implicitly determined data-sharing attributes are those that are referenced in a given construct, do not have predetermined data-sharing attributes, and are not listed in a data-sharing attribute clause of an enclosing construct. For a complete list of variables and objects with predetermined and implicitly determined attributes, please refer to the Data-sharing Attribute Rules for Variables Referenced in a Construct subsection of the OpenMP Specifications document.
DATA-MAPPING ATTRIBUTES
The map clause on a device construct explicitly specifies how the list items in the clause are mapped from the encountering task’s data environment (on the host) to the corresponding item in the device data environment (on the device). The common list items are arrays, array sections, scalars, pointers, and structure elements (members).
Procedures and global variables have predetermined data mapping if they appear within the list or block of a declare target directive. Also, a C/C++ pointer is mapped as a zero-length array section, as is a C++ variable that is a reference to a pointer.
Without explicit mapping, non-scalar and non-pointer variables within the scope of the target construct are implicitly mapped with a map-type of tofrom. Without explicit mapping, scalar variables within the scope of the target construct are not mapped, but have an implicit firstprivate data-sharing attribute. (That is, the value of the original variable is given to a private variable of the same name on the device.) This behavior can be changed with the defaultmap clause.
The map clause can appear on target, target data and target enter/exit data constructs. The operations of creation and removal of device storage as well as assignment of the original list item values to the corresponding list items may be complicated when the list item appears on multiple constructs or when the host and device storage is shared. In these cases the item’s reference count, the number of times it has been referenced (+1 on entry and -1 on exited) in nested (structured) map regions and/or accumulative (unstructured) mappings, determines the operation. Details of the map clause and reference count operation are specified in the map Clause subsection of the OpenMP Specifications document.