Bureaucrats, cc_docs_admin, cc_staff, rsnt_translations
2,837
edits
No edit summary |
|||
Line 28: | Line 28: | ||
! C/C++ !! Fortran | ! C/C++ !! Fortran | ||
|- | |- | ||
| <syntaxhighlight lang="cpp" line> | | <syntaxhighlight lang="cpp" line highlight="1,2,13"> | ||
#pragma acc kernels | #pragma acc kernels | ||
{ | { | ||
Line 42: | Line 42: | ||
} | } | ||
} | } | ||
</syntaxhighlight> || <syntaxhighlight lang="fortran" line> | </syntaxhighlight> || <syntaxhighlight lang="fortran" line highlight="1,7"> | ||
!$acc kernels | !$acc kernels | ||
do i=1,N | do i=1,N | ||
Line 91: | Line 91: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="cpp" line> | <syntaxhighlight lang="cpp" line highlight="1,2,7"> | ||
#pragma acc kernels | #pragma acc kernels | ||
{ | { | ||
Line 136: | Line 136: | ||
The first change we make to this code to try to run it on the GPU is to add the <tt>kernels</tt> directive. At this stage, we don't worry about data transfer, or about giving more information to the compiler. | The first change we make to this code to try to run it on the GPU is to add the <tt>kernels</tt> directive. At this stage, we don't worry about data transfer, or about giving more information to the compiler. | ||
</translate> | </translate> | ||
<syntaxhighlight lang="cpp" line> | <syntaxhighlight lang="cpp" line highlight="1,2,15"> | ||
#pragma acc kernels | #pragma acc kernels | ||
{ | { | ||
Line 209: | Line 209: | ||
=== Loop directive with independent clause === | === Loop directive with independent clause === | ||
Another way to tell the compiler that loops iterations are independent is to specify it explicitly by using a different directive: <tt>loop</tt>, with the clause <tt>independent</tt>. This is a ''prescriptive'' directive. Like any prescriptive directive, this tells the compiler what to do, and overrides any compiler analysis. The initial example above would become: | Another way to tell the compiler that loops iterations are independent is to specify it explicitly by using a different directive: <tt>loop</tt>, with the clause <tt>independent</tt>. This is a ''prescriptive'' directive. Like any prescriptive directive, this tells the compiler what to do, and overrides any compiler analysis. The initial example above would become: | ||
<syntaxhighlight lang="cpp" line> | <syntaxhighlight lang="cpp" line highlight="3"> | ||
#pragma acc kernels | #pragma acc kernels | ||
{ | { | ||
Line 301: | Line 301: | ||
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: | 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 highlight="1"> | ||
#pragma acc parallel loop | #pragma acc parallel loop | ||
for (int i=0; i<N; i++) | for (int i=0; i<N; i++) | ||
Line 318: | Line 318: | ||
Going back to the matrix-vector multiplication example, the corresponding code with the <tt>parallel loop</tt> directive would look like this: | Going back to the matrix-vector multiplication example, the corresponding code with the <tt>parallel loop</tt> directive would look like this: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="cpp" line> | <syntaxhighlight lang="cpp" line highlight="6"> | ||
#pragma acc parallel loop | #pragma acc parallel loop | ||
for(int i=0;i<num_rows;i++) { | for(int i=0;i<num_rows;i++) { |