OpenACC Tutorial - Adding directives: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 53: Line 53:
</syntaxhighlight>
</syntaxhighlight>
|}
|}
 
<translate>
Both in the C/C++ and the Fortran cases, the compiler will identify '''two''' kernels. In C/C++, the two kernels will correspond to the inside of each loops. In Fortran, the kernels will be the inside of the first loop, as well as the inside of the implicit loop that Fortran performs when it does an array operation.
Both in the C/C++ and the Fortran cases, the compiler will identify '''two''' kernels. In C/C++, the two kernels will correspond to the inside of each loops. In Fortran, the kernels will be the inside of the first loop, as well as the inside of the implicit loop that Fortran performs when it does an array operation.


Note that in C/C++, the OpenACC block is delimited using curly brackets, while in Fortran, the same comment needs to be repeated, with the <tt>end</tt>  keyword added.
Note that in C/C++, the OpenACC block is delimited using curly brackets, while in Fortran, the same comment needs to be repeated, with the <tt>end</tt>  keyword added.


{{Callout
=== Loops vs Kernels ===
|title=Loops vs Kernels
When the compiler reaches an OpenACC <tt>kernels</tt> directive, it will analyze the code in order to identify sections that can be parallelized. This often corresponds to the body of loops. When such a case is identified, the compiler will wrap the body of the code into a special function called a ''kernel''. This function makes it clear that each call to the function is independent from any other call. The function is then compiled to enable it to run on an accelerator. Since each call is independent, each one of the thousands cores of the accelerator can run the function for one specific index in parallel.
|content=
</translate>
}}
{| class="wikitable" width="100%"
 
|-
 
! <translate>Loop</translate> !! <translate>Kernels</translate>
|-
| <syntaxhighlight lang="cpp" line>
for (int i=0; i<N; i++)
{
  C[i] = A[i] + B[i];
}
</syntaxhighlight> || <syntaxhighlight lang="cpp" line>
void loopBody(A,B,C,i)
{
  C[i] = A[i] + B[i];
}
</syntaxhighlight>
|-
|<translate>Calculate 0 - N in order</translate> || <translate>Each compute core calculates one value of <tt>i</tt>.</translate>
|}
<translate>
<translate>
</translate>
</translate>
Bureaucrats, cc_docs_admin, cc_staff, rsnt_translations
2,837

edits