2.2. Data sharing attributes

OmpSs-2 allows to specify the explicit data sharing attributes for the variables referenced in a construct using the following clauses:

  • private(<list>)
  • firstprivate(<list>)
  • shared(<list>)

The private and firstprivate clauses declare one or more variables to be private to the construct (i.e. a new variable will be created). All internal references to the original variable are replaced by references to this new variable. Variables privatized using the private clause are uninitialized when the execution of the construct begins. Variables privatized using the firstprivate clause are initialized with the value of the corresponding original variable when the construct was encountered.

The shared clause declare one or more variables to be shared to the construct (i.e. the construct still will refer the original variable). Programmers must ensure that shared variables do not reach the end of their lifetime before other constructs referencing them have finished.

There are a few exceptions in which the data sharing clauses can not be used on certain variables due the nature of the symbol. In these cases we talk about pre-determined data sharing attributes and they are defined by the following rules:

  • Dynamic storage duration objects are shared (malloc, new,… ).
  • Static data members are shared.
  • Variables declared inside the construct with static storage duration are shared.
  • Variables declared inside the construct with automatic storage duration are private.
  • The loop iteration variable(s) of a loop construct is/are private.

When the variable does not have a pre-determined behaviour and it is not referenced by any of the explicit data sharing clauses it is considered to have an implicit data sharing attribute according with the following rules:

  • If the variable appears in a depend clause, the variable will be shared.
  • If a default clause is present in the construct, the implicit data sharing attribute will be the one defined as a parameter of this clause.
  • If no default clause is present and the variable was private/local in the context encountering the construct, the variable will be firstprivate
  • If no default clause is present and the variable was shared/global in the context encountering the construct, the variable will be shared.