OpenACC Tutorial - Adding directives: Difference between revisions

Jump to navigation Jump to search
m
Line 299: Line 299:


== The <tt>parallel loop</tt> directive ==
== The <tt>parallel loop</tt> directive ==
With the <tt>kernels</tt> directive, we let the compiler do all of the analysis. This is the ''descriptive'' approach to porting a code. OpenACC support a ''prescriptive'' approach through a different directive, called the <tt>parallel</tt> directive. This can be combined with the <tt>loop</tt> directive, to form the <tt>parallel loop</tt> directive. An example would be the following code:
With the <tt>kernels</tt> directive, we let the compiler do all of the analysis. This is the ''descriptive'' approach to porting a code. OpenACC supports a ''prescriptive'' approach through a different directive, called the <tt>parallel</tt> directive. This can be combined with the <tt>loop</tt> directive, to form the <tt>parallel loop</tt> directive. An example would be the following code:
</translate>
</translate>
<syntaxhighlight lang="cpp" line>
<syntaxhighlight lang="cpp" line>
Line 313: Line 313:
For reasons that we explain below, in order to use this directive in the matrix-vector product example, we need to introduce additional clauses used to manage the scope of data. The <tt>private</tt> and <tt>reduction</tt> clauses control how the data flows through a parallel region.  
For reasons that we explain below, in order to use this directive in the matrix-vector product example, we need to introduce additional clauses used to manage the scope of data. The <tt>private</tt> and <tt>reduction</tt> clauses control how the data flows through a parallel region.  
* With the <tt>private</tt> clause, a copy of the variable is made for each loop iteration, making the value of the variable independent from other iterations.  
* With the <tt>private</tt> clause, a copy of the variable is made for each loop iteration, making the value of the variable independent from other iterations.  
* With the <tt>reduction</tt> clause, the values of a variable in each iterations will be ''reduced'' to a single value. It supports addition (+), multiplication (*), maximum (max), minimum (min) among other operations.  
* With the <tt>reduction</tt> clause, the values of a variable in each iteration will be ''reduced'' to a single value. It supports addition (+), multiplication (*), maximum (max), minimum (min), among other operations.  
These clauses were not required with the <tt>kernels</tt> directive, because the <tt>kernels</tt> directive handles this for you.  
These clauses were not required with the <tt>kernels</tt> directive, because the <tt>kernels</tt> directive handles this for you.  


Bureaucrats, cc_docs_admin, cc_staff
2,879

edits

Navigation menu